Currently, mshare doesn't support madvise(MADV_HUGEPAGE) to make pages
become THP page.

Thus we need to set /sys/kernel/mm/transparent_hugepage/shmem_enabled
to 'always', enabling mshare to acquire THP pages in a best effort way.

This case is quit simple that set up a mshare memory with 2MB size,
than use memset to fill the physical memory and verify whether THP
was allocated by reading memory.stat.

Signed-off-by: Yongting Lin <[email protected]>
---
 tools/testing/selftests/mshare/memory.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/testing/selftests/mshare/memory.c 
b/tools/testing/selftests/mshare/memory.c
index 4bb0d22b9c03..5132210b1465 100644
--- a/tools/testing/selftests/mshare/memory.c
+++ b/tools/testing/selftests/mshare/memory.c
@@ -68,4 +68,22 @@ TEST_F(memory, swap)
        ASSERT_GT(swap_size, MB(2) * 9 / 10);
 }
 
+TEST_F(memory, thp)
+{
+       /* fill physical memory */
+       memset(self->addr, 0x01, MB(2));
+
+       size_t huge = read_huge_from_cgroup(self->cgroup);
+
+       /*
+        * mshare only allocate in the best effort way, and
+        * don't support madvise(MADV_HUGEPAGE) to change pages
+        * into THP or khuged to replace pages with THP.
+        */
+       ksft_print_msg("Tip: Please enable transparent hugepages for shmem 
before running this test.\n"
+                       "For example: echo always > 
/sys/kernel/mm/transparent_hugepage/shmem_enabled\n");
+
+       ASSERT_GE(huge, MB(2));
+}
+
 TEST_HARNESS_MAIN
-- 
2.20.1


Reply via email to