Re: [PATCH v3 30/54] selftests/mm: compaction_test: use HugeTLB helpers ...

Sarthak Sharma
2026-05-04T10:08:53Z

Hi Mike!

On 4/29/26 2:12 AM, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> ... instead of open coded access of HugeTLB parameters via /proc.
>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> tools/testing/selftests/mm/compaction_test.c | 113 +++----------------
> 1 file changed, 17 insertions(+), 96 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c
> index 30209c40b697..962a50c3d66f 100644
> --- a/tools/testing/selftests/mm/compaction_test.c
> +++ b/tools/testing/selftests/mm/compaction_test.c
> @@ -17,6 +17,7 @@
> #include <string.h>
>
> @@ -161,48 +120,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size,
> ret = 0;
>
> close_fd:

A small nit, should we rename close_fd: to out: now? After this change
the label no longer closes an fd and is the common exit path, so
close_fd feels a bit misleading.

> - close(fd);
> - out:
> ksft_test_result(ret == 0, "check_compaction\n");
> return ret;
> }
>
> -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);
> - if (fd < 0) {
> - ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n",
> - 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));
> - goto close_fd;
> - }
> -
> - lseek(fd, 0, SEEK_SET);
> -
> - /* 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));
> - goto close_fd;
> - }
> -
> - *initial_nr_hugepages = strtoul(nr_hugepages, NULL, 10);
> - ret = 0;
> -
> - close_fd:
> - close(fd);
> -
> - out:
> - return ret;
> -}
> -