* [RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings
@ 2024-08-16 17:21 Aryabhatta Dey
2024-08-16 17:54 ` Aryabhatta Dey
0 siblings, 1 reply; 3+ messages in thread
From: Aryabhatta Dey @ 2024-08-16 17:21 UTC (permalink / raw)
To: akpm, shuah, linux-mm, linux-kselftest, linux-kernel
Add defines for file path names to avoid duplicate strings
in print messages and make it easier to maintain.
Signed-off-by: Aryabhatta Dey <aryabhattadey35@gmail.com>
---
tools/testing/selftests/mm/compaction_test.c | 46 ++++++++++----------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
index e140558e6f53..541ac0373258 100644
--- a/tools/testing/selftests/mm/compaction_test.c
+++ b/tools/testing/selftests/mm/compaction_test.c
@@ -21,6 +21,9 @@
#define MAP_SIZE_MB 100
#define MAP_SIZE (MAP_SIZE_MB * 1024 * 1024)
+#define COMPACT_UNEVICTABLE_ALLOWED "/proc/sys/vm/compact_unevictable_allowed"
+#define NR_HUGEPAGES "/proc/sys/vm/nr_hugepages"
+
struct map_list {
void *map;
struct map_list *next;
@@ -59,17 +62,16 @@ int prereq(void)
char allowed;
int fd;
- fd = open("/proc/sys/vm/compact_unevictable_allowed",
- O_RDONLY | O_NONBLOCK);
+ fd = open(COMPACT_UNEVICTABLE_ALLOWED, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- ksft_print_msg("Failed to open /proc/sys/vm/compact_unevictable_allowed: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to open %s: %s\n",
+ COMPACT_UNEVICTABLE_ALLOWED, strerror(errno));
return -1;
}
if (read(fd, &allowed, sizeof(char)) != sizeof(char)) {
- ksft_print_msg("Failed to read from /proc/sys/vm/compact_unevictable_allowed: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to read from %s: %s\n",
+ COMPACT_UNEVICTABLE_ALLOWED, strerror(errno));
close(fd);
return -1;
}
@@ -97,10 +99,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
in to play */
mem_free = mem_free * 0.8;
- fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
+ fd = open(NR_HUGEPAGES, O_RDWR | O_NONBLOCK);
if (fd < 0) {
- ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to open %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
ret = -1;
goto out;
}
@@ -108,16 +110,16 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
/* Request a large number of huge pages. The Kernel will allocate
as much as it can */
if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) {
- ksft_print_msg("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to write 100000 to %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
goto close_fd;
}
lseek(fd, 0, SEEK_SET);
if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
- ksft_print_msg("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to re-read from %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
goto close_fd;
}
@@ -134,8 +136,8 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
if (write(fd, init_nr_hugepages, strlen(init_nr_hugepages))
!= strlen(init_nr_hugepages)) {
- ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to write value to %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
goto close_fd;
}
@@ -162,15 +164,15 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
int fd, ret = -1;
char nr_hugepages[20] = {0};
- fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
+ fd = open(NR_HUGEPAGES, O_RDWR | O_NONBLOCK);
if (fd < 0) {
- ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to open %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
goto out;
}
if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
- ksft_print_msg("Failed to read from /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to read from %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
goto close_fd;
}
@@ -178,8 +180,8 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
/* Start with the initial condition of 0 huge pages */
if (write(fd, "0", sizeof(char)) != sizeof(char)) {
- ksft_print_msg("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to write 0 to %s: %s\n",
+ NR_HUGEPAGES, strerror(errno));
goto close_fd;
}
--
2.46.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings
2024-08-16 17:21 [RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings Aryabhatta Dey
@ 2024-08-16 17:54 ` Aryabhatta Dey
0 siblings, 0 replies; 3+ messages in thread
From: Aryabhatta Dey @ 2024-08-16 17:54 UTC (permalink / raw)
To: akpm, shuah, linux-mm, linux-kselftest, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 84 bytes --]
Made a mistake. Please ignore the above patch.
Will send the corrected one shortly.
[-- Attachment #2: Type: text/html, Size: 139 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* [RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings
@ 2024-08-16 18:08 Aryabhatta Dey
0 siblings, 0 replies; 3+ messages in thread
From: Aryabhatta Dey @ 2024-08-16 18:08 UTC (permalink / raw)
To: akpm, shuah, linux-mm, linux-kselftest, linux-kernel
Add defines for the file path names to avoid duplicate strings
in print messages and make it easier to maintain.
Signed-off-by: Aryabhatta Dey <aryabhattadey35@gmail.com>
---
tools/testing/selftests/mm/compaction_test.c | 46 ++++++++++----------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
index e140558e6f53..8f46431a9182 100644
--- a/tools/testing/selftests/mm/compaction_test.c
+++ b/tools/testing/selftests/mm/compaction_test.c
@@ -21,6 +21,9 @@
#define MAP_SIZE_MB 100
#define MAP_SIZE (MAP_SIZE_MB * 1024 * 1024)
+#define COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH "/proc/sys/vm/compact_unevictable_allowed"
+#define NR_HUGEPAGES_FILE_NAME_PATH "/proc/sys/vm/nr_hugepages"
+
struct map_list {
void *map;
struct map_list *next;
@@ -59,17 +62,16 @@ int prereq(void)
char allowed;
int fd;
- fd = open("/proc/sys/vm/compact_unevictable_allowed",
- O_RDONLY | O_NONBLOCK);
+ fd = open(COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- ksft_print_msg("Failed to open /proc/sys/vm/compact_unevictable_allowed: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to open %s: %s\n",
+ COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, strerror(errno));
return -1;
}
if (read(fd, &allowed, sizeof(char)) != sizeof(char)) {
- ksft_print_msg("Failed to read from /proc/sys/vm/compact_unevictable_allowed: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to read from %s: %s\n",
+ COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, strerror(errno));
close(fd);
return -1;
}
@@ -97,10 +99,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
in to play */
mem_free = mem_free * 0.8;
- fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
+ fd = open(NR_HUGEPAGES_FILE_NAME_PATH, O_RDWR | O_NONBLOCK);
if (fd < 0) {
- ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to open %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
ret = -1;
goto out;
}
@@ -108,16 +110,16 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
/* Request a large number of huge pages. The Kernel will allocate
as much as it can */
if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) {
- ksft_print_msg("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to write 100000 to %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
goto close_fd;
}
lseek(fd, 0, SEEK_SET);
if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
- ksft_print_msg("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to re-read from %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
goto close_fd;
}
@@ -134,8 +136,8 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
if (write(fd, init_nr_hugepages, strlen(init_nr_hugepages))
!= strlen(init_nr_hugepages)) {
- ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to write value to %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
goto close_fd;
}
@@ -162,15 +164,15 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
int fd, ret = -1;
char nr_hugepages[20] = {0};
- fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK);
+ fd = open(NR_HUGEPAGES_FILE_NAME_PATH, O_RDWR | O_NONBLOCK);
if (fd < 0) {
- ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to open %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
goto out;
}
if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) {
- ksft_print_msg("Failed to read from /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to read from %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
goto close_fd;
}
@@ -178,8 +180,8 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages)
/* Start with the initial condition of 0 huge pages */
if (write(fd, "0", sizeof(char)) != sizeof(char)) {
- ksft_print_msg("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n",
- strerror(errno));
+ ksft_print_msg("Failed to write 0 to %s: %s\n",
+ NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno));
goto close_fd;
}
--
2.46.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-16 18:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-16 17:21 [RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings Aryabhatta Dey
2024-08-16 17:54 ` Aryabhatta Dey
2024-08-16 18:08 Aryabhatta Dey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox