Skip to contentSkip to conversation

KVM: selftests: access_tracking_perf_test fixes and cleanups

PATCH New Zenghui Yu 1 participant 4 messages Sep 17

Subsystems (3)
lore
Share & tools
lore

Zenghui Yu

author
#0 lore raw

cover KVM: selftests: access_tracking_perf_test fixes and cleanups

From: "Zenghui Yu (Huawei)" <[email protected]>

Patch 1 fixes a deterministic failure of access_tracking_perf_test when the host page size is bigger than the guest's, e.g. the 4K guest modes on a 64K arm64 host: page_idle tracks idleness per host page, so walk the test region at that granularity. Patches 2 and 3 are two small cleanups found along the way.

Tested on an arm64 host with 64K pages.

Zenghui Yu (Huawei) (3):
KVM: selftests: Fix access_tracking_perf_test for larger host page
size
KVM: selftests: Add missing newline to access_tracking_perf_test help
KVM: selftests: Remove destroy_cgroup() from access_tracking_perf_test

 .../selftests/kvm/access_tracking_perf_test.c | 23 +++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
Signature · 1 line
2.53.0
author
#1 lore raw

PATCH 1/3 KVM: selftests: Fix access_tracking_perf_test for larger host page size

From: "Zenghui Yu (Huawei)" <[email protected]>

access_tracking_perf_test marks guest memory idle through page_idle by walking its test region one guest page at a time and checking/marking the host PFN backing each guest page. The walk assumes that every guest page maps to a distinct host page, which only holds when the guest page size is

Quoted 1 line

= the host page size.

On an arm64 host with 64K pages, the test also runs guest modes that use 4K pages, where 16 consecutive guest pages are backed by one host page. The first of them marks the shared host page idle and the other 15 then see the page as already idle and count it as "still idle", inflating still_idle to ~94% and failing the test:

  $ ./access_tracking_perf_test
  Random seed: 0x1c04f013
  lru_gen: Could not open /sys/kernel/mm/lru_gen/enabled
  Using page_idle for aging
  Testing guest mode: PA-bits:48,  VA-bits:48,  4K pages
  __vm_create: mode='PA-bits:48,  VA-bits:48,  4K pages' type='0', pages='1696'
  guest physical test memory: [0xffffbfff0000, 0xffffffff0000)

Populating memory : 0.299047690s
Writing to populated memory : 0.008723980s
Reading from populated memory : 0.010692350s

==== Test Assertion Failure ====

    access_tracking_perf_test.c:164: idle_pages_warn_only
    pid=3503998 tid=3504006 errno=4 - Interrupted system call
       1	0x000000000040308f: too_many_idle_pages at access_tracking_perf_test.c:164
       2	 (inlined by) pageidle_mark_vcpu_memory_idle at access_tracking_perf_test.c:229
       3	 (inlined by) vcpu_thread_main at access_tracking_perf_test.c:339
       4	0x000000000040a267: vcpu_thread_main at memstress.c:277
       5	0x00007fff958ef09b: ?? ??:0
       6	0x00007fff959548db: ?? ??:0
    vCPU0: Too many pages still idle (245647 out of 262144)

Idle tracking is fundamentally per host page though. Walk the region in units of the larger of the guest and host page size instead. This changes nothing when the guest page size is >= the host's - if the guest page is bigger, the guest only ever faults the first host page of each guest page anyway.

Assisted-by GLM-5.3 OpenCode
---
 .../selftests/kvm/access_tracking_perf_test.c    | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/access_tracking_perf_test.c +13 -3
index 4415c94b2866..bcdfeb9c22d8 100644
@@ -175,8 +175,8 @@ static void pageidle_mark_vcpu_memory_idle(struct kvm_vm *vm,
 {
 	int vcpu_idx = vcpu_args->vcpu_idx;
 	gva_t base_gva = vcpu_args->gva;
-	u64 pages = vcpu_args->pages;
-	u64 page;
+	u64 idle_page_size;
+	u64 pages, page;
 	u64 still_idle = 0;
 	u64 no_pfn = 0;
 	int page_idle_fd;
@@ -192,8 +192,18 @@ static void pageidle_mark_vcpu_memory_idle(struct kvm_vm *vm,
 	pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
 	TEST_ASSERT(pagemap_fd > 0, "Failed to open pagemap.");
 
+	/*
+	 * Idle tracking operates on host pages, so walk the region in units of
+	 * the larger of the guest and host page size.  If the host page is the
+	 * bigger one, several guest pages are backed by one host page and
+	 * checking/marking the same PFN once per guest page would make the
+	 * sanity check below count the shared page as still idle.
+	 */
+	idle_page_size = max_t(u64, memstress_args.guest_page_size, getpagesize());
+	pages = vcpu_args->pages * memstress_args.guest_page_size / idle_page_size;
+
 	for (page = 0; page < pages; page++) {
-		gva_t gva = base_gva + page * memstress_args.guest_page_size;
+		gva_t gva = base_gva + page * idle_page_size;
 		u64 pfn = lookup_pfn(pagemap_fd, vm, gva);
 
 		if (!pfn) {
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH 2/3 KVM: selftests: Add missing newline to access_tracking_perf_test help

In reply to Zenghui Yu

From: "Zenghui Yu (Huawei)" <[email protected]>

The help text for the -h option is printed without a trailing newline, so it runs together with the first line of the guest mode help that follows it. Add the missing newline.

---
 tools/testing/selftests/kvm/access_tracking_perf_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/access_tracking_perf_test.c +1 -1
index bcdfeb9c22d8..98ace8b8b4ac 100644
@@ -504,7 +504,7 @@ static void help(char *name)
 	printf("usage: %s [-h] [-m mode] [-b vcpu_bytes] [-v vcpus] [-o]  [-s mem_type]\n",
 	       name);
 	puts("");
-	printf(" -h: Display this help message.");
+	printf(" -h: Display this help message.\n");
 	guest_modes_help();
 	printf(" -b: specify the size of the memory region which should be\n"
 	       "     dirtied by each vCPU. e.g. 10M or 3G.\n"
Signature · 1 line
2.53.0
author
#3 lore raw

PATCH 3/3 KVM: selftests: Remove destroy_cgroup() from access_tracking_perf_test

In reply to Zenghui Yu

From: "Zenghui Yu (Huawei)" <[email protected]>

destroy_cgroup() is not called anywhere. Remove the dead helper.

---
 tools/testing/selftests/kvm/access_tracking_perf_test.c | 5 -----
 1 file changed, 5 deletions(-)
tools/testing/selftests/kvm/access_tracking_perf_test.c +0 -5
index 98ace8b8b4ac..9b83e4efcaf9 100644
@@ -523,11 +523,6 @@ static void help(char *name)
 	exit(0);
 }
 
-void destroy_cgroup(char *cg)
-{
-	printf("Destroying cgroup: %s\n", cg);
-}
-
 int main(int argc, char *argv[])
 {
 	struct test_params params = {
Signature · 1 line
2.53.0