On 8/25/25 7:57 AM, Yongting Lin wrote:
This case is quit simple by using madvise(MADV_HUGEPAGE), but for verifying the size of THP memory, we need to setup the memcg and attach test process to this memcg before perform the test.
Because mshare doesn't support THP feature, the size of THP memory should be 0 even though we use madivse.
There can be THPs in an mshare region if THP settings are set to "always", but otherwise madvise() won't work directly on the msharefs VMA. It will be necessary to implement an ioctl to apply madvise operations to memory in an mshare region.
Anthony
Signed-off-by: Yongting Lin linyongting@bytedance.com
tools/testing/selftests/mshare/memory.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/mshare/memory.c b/tools/testing/selftests/mshare/memory.c index 7754c0e33506..2a415ce7bc01 100644 --- a/tools/testing/selftests/mshare/memory.c +++ b/tools/testing/selftests/mshare/memory.c @@ -68,4 +68,15 @@ TEST_F(memory, swap) ASSERT_GT(swap_size, GB(1) * 9 / 10); } +TEST_F(memory, thp) +{
- ASSERT_NE(madvise(self->addr, self->allocate_size, MADV_HUGEPAGE), -1);
- /* touch 1G */
- memset(self->addr, 0x01, GB(1));
- size_t huge = read_huge_from_cgroup(self->cgroup);
- /* mshare don't support THP now */
- ASSERT_EQ(huge, 0);
+}
- TEST_HARNESS_MAIN