Skip to content

Commit c8b9073

Browse files
leitaoakpm00
authored andcommitted
selftests/mm: export get_free_hugepages()
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/[email protected]/#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/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Breno Leitao <[email protected]> Reviewed-by: Rik van Riel <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent afb2d66 commit c8b9073

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

tools/testing/selftests/mm/hugetlb-madvise.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,6 @@
3636
unsigned long huge_page_size;
3737
unsigned long base_page_size;
3838

39-
unsigned long get_free_hugepages(void)
40-
{
41-
unsigned long fhp = 0;
42-
char *line = NULL;
43-
size_t linelen = 0;
44-
FILE *f = fopen("/proc/meminfo", "r");
45-
46-
if (!f)
47-
return fhp;
48-
while (getline(&line, &linelen, f) > 0) {
49-
if (sscanf(line, "HugePages_Free: %lu", &fhp) == 1)
50-
break;
51-
}
52-
53-
free(line);
54-
fclose(f);
55-
return fhp;
56-
}
57-
5839
void write_fault_pages(void *addr, unsigned long nr_pages)
5940
{
6041
unsigned long i;

tools/testing/selftests/mm/vm_util.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,22 @@ int uffd_unregister(int uffd, void *addr, uint64_t len)
269269

270270
return ret;
271271
}
272+
273+
unsigned long get_free_hugepages(void)
274+
{
275+
unsigned long fhp = 0;
276+
char *line = NULL;
277+
size_t linelen = 0;
278+
FILE *f = fopen("/proc/meminfo", "r");
279+
280+
if (!f)
281+
return fhp;
282+
while (getline(&line, &linelen, f) > 0) {
283+
if (sscanf(line, "HugePages_Free: %lu", &fhp) == 1)
284+
break;
285+
}
286+
287+
free(line);
288+
fclose(f);
289+
return fhp;
290+
}

tools/testing/selftests/mm/vm_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int uffd_register(int uffd, void *addr, uint64_t len,
5151
int uffd_unregister(int uffd, void *addr, uint64_t len);
5252
int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len,
5353
bool miss, bool wp, bool minor, uint64_t *ioctls);
54+
unsigned long get_free_hugepages(void);
5455

5556
/*
5657
* On ppc64 this will only work with radix 2M hugepage size

0 commit comments

Comments
 (0)