Re: [PATCH] selftests: KVM: use dirty logging to check if page stats work correctly

From: Paolo Bonzini
Date: Fri Oct 15 2021 - 12:20:16 EST


On 23/08/21 23:36, Ben Gardon wrote:
+#ifdef __x86_64__
+ TEST_ASSERT(get_page_stats(X86_PAGE_SIZE_4K) != 0,
+ "4K page is zero");
+ if (p->backing_src == VM_MEM_SRC_ANONYMOUS_THP)
+ TEST_ASSERT(get_page_stats(X86_PAGE_SIZE_2M) != 0,
+ "2M page is zero");
+ if (p->backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB_1GB)
+ TEST_ASSERT(get_page_stats(X86_PAGE_SIZE_1G) != 0,
+ "1G page is zero");
+#endif
This check is correct, but it misses some cases. It'd be worth going
back to ensure that all relevant backing src types are handled here.
For example, this misses VM_MEM_SRC_ANONYMOUS_HUGETLB_2MB.

We could also be more precise by asserting that the counts are at
least some value or total to some value. THP introduces some flakiness
but one way or another the mapping counts at this point should total
up to account for the expected size of guest memory.


I am worried about flakiness here. I would prefer to have just a check that _some_ pagesize is nonzero.

Also even for 1GB hugetlbfs not all processors support gigabyte pages, so for those the stat would be 0.

Finally, please use the binary statistics interface, so that the test does not require root.

Paolo