selftests/mm: export get_free_hugepages()
authorBreno Leitao <leitao@debian.org>
Thu, 5 Oct 2023 16:39:21 +0000 (09:39 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 18 Oct 2023 21:34:16 +0000 (14:34 -0700)
Patch series "New selftest for mm", v2.

This is a simple test case that reproduces an mm problem[1], where a page
fault races with madvise(), and it is not trivial to reproduce and debug.

This test-case aims to avoid such race problems from happening again,
impacting workloads that leverages external allocators, such as tcmalloc,
jemalloc, etc.

[1] https://lore.kernel.org/all/20231001005659.2185316-1-riel@surriel.com/#r

This patch (of 2):

get_free_hugepages() is helpful for other hugepage tests.  Export it to
the common file (vm_util.c) to be reused.

Link: https://lkml.kernel.org/r/20231005163922.87568-1-leitao@debian.org
Link: https://lkml.kernel.org/r/20231005163922.87568-2-leitao@debian.org
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Rik van Riel <riel@surriel.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/hugetlb-madvise.c
tools/testing/selftests/mm/vm_util.c
tools/testing/selftests/mm/vm_util.h

index d55322df4b7366c0cb3ad47a6de1092479230444..f32d99565c5eaa96f6a16aafc45a10f118652026 100644 (file)
 unsigned long huge_page_size;
 unsigned long base_page_size;
 
-unsigned long get_free_hugepages(void)
-{
-       unsigned long fhp = 0;
-       char *line = NULL;
-       size_t linelen = 0;
-       FILE *f = fopen("/proc/meminfo", "r");
-
-       if (!f)
-               return fhp;
-       while (getline(&line, &linelen, f) > 0) {
-               if (sscanf(line, "HugePages_Free:      %lu", &fhp) == 1)
-                       break;
-       }
-
-       free(line);
-       fclose(f);
-       return fhp;
-}
-
 void write_fault_pages(void *addr, unsigned long nr_pages)
 {
        unsigned long i;
index 558c9cd8901c5a17de934f98455c84583314ac41..3082b40492dd8181b75d182c87bde20779f526db 100644 (file)
@@ -269,3 +269,22 @@ int uffd_unregister(int uffd, void *addr, uint64_t len)
 
        return ret;
 }
+
+unsigned long get_free_hugepages(void)
+{
+       unsigned long fhp = 0;
+       char *line = NULL;
+       size_t linelen = 0;
+       FILE *f = fopen("/proc/meminfo", "r");
+
+       if (!f)
+               return fhp;
+       while (getline(&line, &linelen, f) > 0) {
+               if (sscanf(line, "HugePages_Free:      %lu", &fhp) == 1)
+                       break;
+       }
+
+       free(line);
+       fclose(f);
+       return fhp;
+}
index c7fa61f0dff8d963b2ad5f92554b94691f6a17c5..c02990bbd56f4cf1cb5ea878f8fa76c4b6057c8d 100644 (file)
@@ -51,6 +51,7 @@ int uffd_register(int uffd, void *addr, uint64_t len,
 int uffd_unregister(int uffd, void *addr, uint64_t len);
 int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
                              bool miss, bool wp, bool minor, uint64_t *ioctls);
+unsigned long get_free_hugepages(void);
 
 /*
  * On ppc64 this will only work with radix 2M hugepage size