Skip to contentSkip to conversation

selftests/mm: hugetlb_madv_vs_map: add underflow test

PATCH Superseded Guillaume Morin 2 participants 2 messages Aug 27 – Aug 28

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/mm: hugetlb_madv_vs_map: add underflow test

Add a test that checks for underflows when a parent unmaps the page first. Also check that when the child exits the reserve count is correct.

---
 .../testing/selftests/mm/hugepage_settings.c  |  9 ++
 .../testing/selftests/mm/hugepage_settings.h  |  1 +
 .../selftests/mm/hugetlb_madv_vs_map.c        | 84 ++++++++++++++++++-
 3 files changed, 93 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/hugepage_settings.c +9 -0
index d7917dce3aba..584054736ce9 100644
@@ -449,6 +449,15 @@ unsigned long hugetlb_free_pages(unsigned long size)
 	return read_num(path);
 }
 
+unsigned long hugetlb_nr_resv_pages(unsigned long size)
+{
+	char path[PATH_MAX];
+
+	hugetlb_sysfs_path(path, sizeof(path), size, "resv_hugepages");
+
+	return read_num(path);
+}
+
 static bool __hugetlb_setup(unsigned long size, unsigned long nr)
 {
 	unsigned long free = hugetlb_free_pages(size);
tools/testing/selftests/mm/hugepage_settings.h +1 -0
index 726c73c43c05..548e9d288d1d 100644
@@ -98,6 +98,7 @@ unsigned long default_huge_page_size(void);
 unsigned long hugetlb_nr_pages(unsigned long size);
 void hugetlb_set_nr_pages(unsigned long size, unsigned long nr);
 unsigned long hugetlb_free_pages(unsigned long size);
+unsigned long hugetlb_nr_resv_pages(unsigned long size);
 
 static inline void hugetlb_save_settings(void)
 {
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +83 -1

108 lines not on this page · raw message

Signature · 4 lines
2.39.1

-- 
Guillaume Morin <[email protected]>
#1 lore raw
Quoted 4 lines · Guillaume Morin
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +0 -0
@@ -120,5 +127,80 @@ int main(void)
 	}
 
 	ksft_test_result_pass("No unexpected huge page allocations\n");

tools/testing/selftests/mm/hugetlb_madv_vs_map.c int main(void) · line 139

Quoted 10 lines
tools/testing/selftests/mm/hugetlb_madv_vs_map.c +10 -0
+	huge_ptr = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
+			MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
+
+	if ((unsigned long)huge_ptr == -1)
+		ksft_exit_fail_msg("Failed to allocate huge page\n");
+
+	{
+		pid_t pid;
+		int pipe_fds[2];
+		unsigned long nr_reserved = 0;

Why do you want to start a C block "{" here? That looks like a bit weird.

Also, please factor our this new code.

Thanks for the new test,
--breno