KVM: selftests: access_tracking_perf_test fixes for NUMA balancing and MGLRU
v4 cover KVM: selftests: access_tracking_perf_test fixes for NUMA balancing and MGLRU
This series fixes some issues with access_tracking_perf_test when MGLRU or NUMA balancing are in use.
With MGLRU, touching a page doesn't necessarily clear the Idle flag. This has come up in the past, and the recommendation was to use MGLRU generation numbers[1], which this series does.
With NUMA balancing, pages are temporarily mapped as PROT_NONE, so the SPTEs will be zapped, losing the Accessed bits. The fix here is, in the event we have lost access information to print a warning and continue with the test, just like what we do if the test is running a nested VM.
A flag is added for the user to specify if they wish for the test to always enforce or always skip this check.
Based on kvm/next.
Changelog:
v3[4] -> v4:
- Multiple fixes to access_tracking_perf_test:
1. Fix for software-managed A/D-bit configs.
2. Fix for expected number of pages when guest page size is > PAGE_SIZE.
3. Properly check youngest generation when looking for pages.
- Do an initial aging pass for MGLRU. This allows us to check that pages move back to the youngest generation after the first access pass.
- Add controller-root location logic in the cgroup utils, and use this to make the test work for cgroup-v1 (thanks Sean!).
- Some cleanup for access_tracking_perf_test code, comments, warning messages, and the commit message (thanks Sean!).
v2[3] -> v3:
- Applied David's directory fix on patch 3.
- Added SoB-by, R-by (patch 2, missed in v2), and A-by.
v1[2] -> v2:
- Re-add clone3_selftests.h for cgroup selftests (thanks Michal!)
- Some comment fixes, patches 2 and 5 (thanks Maxim!).
[1]: https://lore.kernel.org/all/CAOUHufZeADNp_y=Ng+acmMMgnTR=ZGFZ7z-m6O47O=CmJauWjw@mail.gmail.com/
[2]: https://lore.kernel.org/kvm/[email protected]/
[3]: https://lore.kernel.org/kvm/[email protected]/
[4]: https://lore.kernel.org/kvm/[email protected]/
James Houghton (3):
cgroup: selftests: Move cgroup_util into its own library
KVM: selftests: Build and link selftests/cgroup/lib into KVM selftests
KVM: selftests: access_tracking_perf_test: Use MGLRU for access
tracking
Maxim Levitsky (1):
KVM: selftests: access_tracking_perf_test: Add option to skip the
sanity check
Sean Christopherson (3):
KVM: selftests: Extract guts of THP accessor to standalone sysfs
helpers
cgroup: selftests: Move memcontrol specific helpers out of common
cgroup_util.c
cgroup: selftests: Add API to find root of specific controller
tools/testing/selftests/cgroup/Makefile | 21 +-
.../selftests/cgroup/{ => lib}/cgroup_util.c | 118 ++----
.../cgroup/{ => lib/include}/cgroup_util.h | 13 +-
.../testing/selftests/cgroup/lib/libcgroup.mk | 19 +
.../selftests/cgroup/test_memcontrol.c | 78 ++++
tools/testing/selftests/kvm/Makefile.kvm | 4 +-
.../selftests/kvm/access_tracking_perf_test.c | 281 +++++++++++--
.../selftests/kvm/include/lru_gen_util.h | 51 +++
.../testing/selftests/kvm/include/test_util.h | 1 +
.../testing/selftests/kvm/lib/lru_gen_util.c | 386 ++++++++++++++++++
tools/testing/selftests/kvm/lib/test_util.c | 42 +-
11 files changed, 865 insertions(+), 149 deletions(-)
rename tools/testing/selftests/cgroup/{ => lib}/cgroup_util.c (88%)
rename tools/testing/selftests/cgroup/{ => lib/include}/cgroup_util.h (91%)
create mode 100644 tools/testing/selftests/cgroup/lib/libcgroup.mk
create mode 100644 tools/testing/selftests/kvm/include/lru_gen_util.h
create mode 100644 tools/testing/selftests/kvm/lib/lru_gen_util.cbase-commit: 45eb29140e68ffe8e93a5471006858a018480a45
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 1/7 KVM: selftests: Extract guts of THP accessor to standalone sysfs helpers
From: Sean Christopherson <[email protected]>
Extract the guts of thp_configured() and get_trans_hugepagesz() to standalone helpers so that the core logic can be reused for other sysfs files, e.g. to query numa_balancing.
Opportunistically assert that the initial fscanf() read at least one byte, and add a comment explaining the second call to fscanf().
--- tools/testing/selftests/kvm/lib/test_util.c | 35 ++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-)
tools/testing/selftests/kvm/lib/test_util.c +24 -11
@@ -132,37 +132,50 @@ void print_skip(const char *fmt, ...)puts (", skipping test" ); } -bool thp_configured (void ) +static bool test_sysfs_path (const char *path) { -int ret;struct stat statbuf; +int ret; - ret =stat ("/sys/kernel/mm/transparent_hugepage" , &statbuf); + ret =stat (path, &statbuf);TEST_ASSERT (ret ==0 || (ret ==-1 && errno ==ENOENT ), -"Error in stating /sys/kernel/mm/transparent_hugepage" ); +"Error in stat()ing '%s'" , path);return ret ==0 ; } -size_t get_trans_hugepagesz (void ) +bool thp_configured (void ) +{ +return test_sysfs_path ("/sys/kernel/mm/transparent_hugepage" ); +} + +static size_t get_sysfs_val (const char *path) {size_t size;FILE *f;int ret; -TEST_ASSERT (thp_configured (),"THP is not configured in host kernel" ); - - f =fopen ("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" ,"r" ); -TEST_ASSERT (f !=NULL ,"Error in opening transparent_hugepage/hpage_pmd_size" ); + f =fopen (path,"r" ); +TEST_ASSERT (f,"Error opening '%s'" , path); ret =fscanf (f,"%ld" , &size); +TEST_ASSERT (ret >0 ,"Error reading '%s'" , path); + +/* Re-scan the input stream to verify the entire file was read. */ ret =fscanf (f,"%ld" , &size); -TEST_ASSERT (ret <1 ,"Error reading transparent_hugepage/hpage_pmd_size" ); -fclose (f); +TEST_ASSERT (ret <1 ,"Error reading '%s'" , path); +fclose (f);return size; } +size_t get_trans_hugepagesz (void ) +{ +TEST_ASSERT (thp_configured (),"THP is not configured in host kernel" ); + +return get_sysfs_val ("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" ); +} +size_t get_def_hugetlb_pagesz (void ) {char buf[64 ];
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 2/7 KVM: selftests: access_tracking_perf_test: Add option to skip the sanity check
In reply to James HoughtonFrom: Maxim Levitsky <[email protected]>
Add an option to skip sanity check of number of still idle pages, and set it by default to skip, in case hypervisor or NUMA balancing is detected.
--- .../selftests/kvm/access_tracking_perf_test.c | 62 ++++++++++++++++--- .../testing/selftests/kvm/include/test_util.h | 1 + tools/testing/selftests/kvm/lib/test_util.c | 7 +++ 3 files changed, 61 insertions(+), 9 deletions(-)
tools/testing/selftests/kvm/access_tracking_perf_test.c +53 -9
@@ -65,6 +65,16 @@ static int vcpu_last_completed_iteration[KVM_MAX_VCPUS];/* Whether to overlap the regions of memory vCPUs access. */ static bool overlap_memory_access; +/* +* If the test should only warn if there are too many idle pages (i.e., it is +* expected). +* -1: Not yet set. +* 0: We do not expect too many idle pages, so FAIL if too many idle pages. +* 1: Having too many idle pages is expected, so merely print a warning if +* too many idle pages are found. +*/ +static int idle_pages_warn_only =-1 ; +struct test_params {/* The backing source for the region of memory. */ enum vm_mem_backing_src_type backing_src;
@@ -177,18 +187,12 @@ static void mark_vcpu_memory_idle(struct kvm_vm *vm,* arbitrary; high enough that we ensure most memory access went through * access tracking but low enough as to not make the test too brittle * over time and across architectures. -* -* When running the guest as a nested VM, "warn" instead of asserting -* as the TLB size is effectively unlimited and the KVM doesn't -* explicitly flush the TLB when aging SPTEs. As a result, more pages -* are cached and the guest won't see the "idle" bit cleared. */ if (still_idle >= pages /10 ) { -#ifdef __x86_64__ -TEST_ASSERT (this_cpu_has (X86_FEATURE_HYPERVISOR ), +TEST_ASSERT (idle_pages_warn_only,"vCPU%d: Too many pages still idle (%lu out of %lu)" , vcpu_idx, still_idle, pages); -#endif +printf ("WARNING: vCPU%d: Too many pages still idle (%lu out of %lu), " "this will affect performance results.\n" , vcpu_idx, still_idle, pages);
@@ -328,6 +332,32 @@ static void run_test(enum vm_guest_mode mode, void *arg)memstress_destroy_vm (vm); } +static int access_tracking_unreliable (void ) +{ +#ifdef __x86_64__ +/* +* When running nested, the TLB size may be effectively unlimited (for +* example, this is the case when running on KVM L0), and KVM doesn't +* explicitly flush the TLB when aging SPTEs. As a result, more pages +* are cached and the guest won't see the "idle" bit cleared. +*/ +if (this_cpu_has (X86_FEATURE_HYPERVISOR )) { +puts ("Skipping idle page count sanity check, because the test is run nested" ); +return 1 ; + } +#endif +/* +* When NUMA balancing is enabled, guest memory will be unmapped to get +* NUMA faults, dropping the Accessed bits. +*/ +if (is_numa_balancing_enabled ()) { +puts ("Skipping idle page count sanity check, because NUMA balancing is enabled" ); +return 1 ; + } + +return 0 ; +} +static void help (char *name) {puts ("" );
@@ -342,6 +372,12 @@ static void help(char *name)printf (" -v: specify the number of vCPUs to run.\n" );printf (" -o: Overlap guest memory accesses instead of partitioning\n" " them into a separate region of memory for each vCPU.\n" ); +printf (" -w: Control whether the test warns or fails if more than 10%\n" +" of pages are still seen as idle/old after accessing guest\n" +" memory. >0 == warn only, 0 == fail, <0 == auto. For auto\n" +" mode, the test fails by default, but switches to warn only\n" +" if NUMA balancing is enabled or the test detects it's running\n" +" in a VM.\n" );backing_src_help ("-s" );puts ("" );exit (0 );
@@ -359,7 +395,7 @@ int main(int argc, char *argv[])guest_modes_append_default (); -while ((opt =getopt (argc, argv,"hm:b:v:os:" )) !=-1 ) { +while ((opt =getopt (argc, argv,"hm:b:v:os:w:" )) !=-1 ) {switch (opt) {case 'm' :guest_modes_cmdline (optarg);
@@ -376,6 +412,11 @@ int main(int argc, char *argv[])case 's' : params.backing_src =parse_backing_src_type (optarg);break ; +case 'w' : + idle_pages_warn_only = +atoi_non_negative ("Idle pages warning" , + optarg); +break ;case 'h' :default :help (argv[0 ]);
@@ -388,6 +429,9 @@ int main(int argc, char *argv[]) "CONFIG_IDLE_PAGE_TRACKING is not enabled");close (page_idle_fd); +if (idle_pages_warn_only ==-1 ) + idle_pages_warn_only =access_tracking_unreliable (); +for_each_guest_mode (run_test, ¶ms);return 0 ;
tools/testing/selftests/kvm/include/test_util.h +1 -0
@@ -153,6 +153,7 @@ bool is_backing_src_hugetlb(uint32_t i);void backing_src_help (const char *flag);enum vm_mem_backing_src_type parse_backing_src_type (const char *type_name);long get_run_delay (void ); +bool is_numa_balancing_enabled (void );/* * Whether or not the given source type is shared memory (as opposed to
tools/testing/selftests/kvm/lib/test_util.c +7 -0
@@ -176,6 +176,13 @@ size_t get_trans_hugepagesz(void)return get_sysfs_val ("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" ); } +bool is_numa_balancing_enabled (void ) +{ +if (!test_sysfs_path ("/proc/sys/kernel/numa_balancing" )) +return false; +return get_sysfs_val ("/proc/sys/kernel/numa_balancing" ) ==1 ; +} +size_t get_def_hugetlb_pagesz (void ) {char buf[64 ];
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 3/7 cgroup: selftests: Move memcontrol specific helpers out of common cgroup_util.c
In reply to James HoughtonFrom: Sean Christopherson <[email protected]>
Move a handful of helpers out of cgroup_util.c and into test_memcontrol.c that have nothing to with cgroups in general, in anticipation of making cgroup_util.c a generic library that can be used by other selftests.
Make read_text() and write_text() non-static so test_memcontrol.c can use them.
---
Sean's original patch[1] didn't build for me, hence the read_text() and write_text() change.
[1]: https://lore.kernel.org/kvm/[email protected]/
---
tools/testing/selftests/cgroup/cgroup_util.c | 82 +------------------ tools/testing/selftests/cgroup/cgroup_util.h | 8 +- .../selftests/cgroup/test_memcontrol.c | 78 ++++++++++++++++++ 3 files changed, 83 insertions(+), 85 deletions(-)
tools/testing/selftests/cgroup/cgroup_util.c +2 -80
@@ -20,7 +20,7 @@#include "../clone3/clone3_selftests.h" /* Returns read len on success, or -errno on failure. */ -static ssize_t read_text (const char *path,char *buf,size_t max_len) +ssize_t read_text (const char *path,char *buf,size_t max_len) {ssize_t len;int fd;
@@ -39,7 +39,7 @@ static ssize_t read_text(const char *path, char *buf, size_t max_len) }/* Returns written len on success, or -errno on failure. */ -static ssize_t write_text (const char *path,char *buf,ssize_t len) +ssize_t write_text (const char *path,char *buf,ssize_t len) {int fd;
@@ -488,84 +488,6 @@ int cg_run_nowait(const char *cgroup,return pid; } -int get_temp_fd (void ) -{ -return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ); -} - -int alloc_pagecache (int fd,size_t size) -{ -char buf[PAGE_SIZE ]; -struct stat st; -int i; - -if (fstat (fd, &st)) - goto cleanup; - - size += st.st_size; - -if (ftruncate (fd, size)) - goto cleanup; - -for (i =0 ; i < size; i +=sizeof (buf)) -read (fd, buf,sizeof (buf)); - -return 0 ; - -cleanup: -return -1 ; -} - -int alloc_anon (const char *cgroup,void *arg) -{ -size_t size = (unsigned long )arg; -char *buf, *ptr; - - buf =malloc (size); -for (ptr = buf; ptr < buf + size; ptr +=PAGE_SIZE ) - *ptr =0 ; - -free (buf); -return 0 ; -} - -int is_swap_enabled (void ) -{ -char buf[PAGE_SIZE ]; -const char delim[] ="\n" ; -int cnt =0 ; -char *line; - -if (read_text ("/proc/swaps" , buf,sizeof (buf)) <=0 ) -return -1 ; - -for (line =strtok (buf, delim); line; line =strtok (NULL , delim)) - cnt++; - -return cnt >1 ; -} - -int set_oom_adj_score (int pid,int score) -{ -char path[PATH_MAX ]; -int fd, len; - -sprintf (path,"/proc/%d/oom_score_adj" , pid); - - fd =open (path,O_WRONLY |O_APPEND ); -if (fd <0 ) -return fd; - - len =dprintf (fd,"%d" , score); -if (len <0 ) { -close (fd); -return len; - } - -close (fd); -return 0 ; -} -int proc_mount_contains (const char *option) {char buf[4 *PAGE_SIZE ];
tools/testing/selftests/cgroup/cgroup_util.h +3 -5
@@ -21,6 +21,9 @@ static inline int values_close(long a, long b, int err)return labs (a - b) <= (a + b) /100 * err; } +extern ssize_t read_text (const char *path,char *buf,size_t max_len); +extern ssize_t write_text (const char *path,char *buf,ssize_t len); +extern int cg_find_unified_root (char *root,size_t len,bool *nsdelegate);extern char *cg_name (const char *root,const char *name);extern char *cg_name_indexed (const char *root,const char *name,int index);
@@ -49,11 +52,6 @@ extern int cg_enter_current_thread(const char *cgroup);extern int cg_run_nowait (const char *cgroup,int (*fn)(const char *cgroup,void *arg),void *arg); -extern int get_temp_fd (void ); -extern int alloc_pagecache (int fd,size_t size); -extern int alloc_anon (const char *cgroup,void *arg); -extern int is_swap_enabled (void ); -extern int set_oom_adj_score (int pid,int score);extern int cg_wait_for_proc_count (const char *cgroup,int count);extern int cg_killall (const char *cgroup);int proc_mount_contains (const char *option);
tools/testing/selftests/cgroup/test_memcontrol.c +78 -0
84 lines not on this page · raw message
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 4/7 cgroup: selftests: Move cgroup_util into its own library
In reply to James HoughtonKVM selftests will soon need to use some of the cgroup creation and deletion functionality from cgroup_util.
---
tools/testing/selftests/cgroup/Makefile | 21 ++++++++++---------
.../selftests/cgroup/{ => lib}/cgroup_util.c | 2 +-
.../cgroup/{ => lib/include}/cgroup_util.h | 4 ++--
.../testing/selftests/cgroup/lib/libcgroup.mk | 19 +++++++++++++++++
4 files changed, 33 insertions(+), 13 deletions(-)
rename tools/testing/selftests/cgroup/{ => lib}/cgroup_util.c (99%)
rename tools/testing/selftests/cgroup/{ => lib/include}/cgroup_util.h (99%)
create mode 100644 tools/testing/selftests/cgroup/lib/libcgroup.mktools/testing/selftests/cgroup/Makefile +11 -10
@@ -21,14 +21,15 @@ TEST_GEN_PROGS += test_zswap LOCAL_HDRS += $(selfdir)/clone3/clone3_selftests.h $(selfdir)/pidfd/pidfd.h include ../lib.mk +include lib/libcgroup.mk -$(OUTPUT)/test_core: cgroup_util.c -$(OUTPUT)/test_cpu: cgroup_util.c -$(OUTPUT)/test_cpuset: cgroup_util.c -$(OUTPUT)/test_freezer: cgroup_util.c -$(OUTPUT)/test_hugetlb_memcg: cgroup_util.c -$(OUTPUT)/test_kill: cgroup_util.c -$(OUTPUT)/test_kmem: cgroup_util.c -$(OUTPUT)/test_memcontrol: cgroup_util.c -$(OUTPUT)/test_pids: cgroup_util.c -$(OUTPUT)/test_zswap: cgroup_util.c +$(OUTPUT)/test_core: $(LIBCGROUP_O) +$(OUTPUT)/test_cpu: $(LIBCGROUP_O) +$(OUTPUT)/test_cpuset: $(LIBCGROUP_O) +$(OUTPUT)/test_freezer: $(LIBCGROUP_O) +$(OUTPUT)/test_hugetlb_memcg: $(LIBCGROUP_O) +$(OUTPUT)/test_kill: $(LIBCGROUP_O) +$(OUTPUT)/test_kmem: $(LIBCGROUP_O) +$(OUTPUT)/test_memcontrol: $(LIBCGROUP_O) +$(OUTPUT)/test_pids: $(LIBCGROUP_O) +$(OUTPUT)/test_zswap: $(LIBCGROUP_O)
tools/testing/selftests/cgroup/lib/cgroup_util.c renamed from tools/testing/selftests/cgroup/cgroup_util.c +1 -1
@@ -17,7 +17,7 @@#include <unistd.h> #include "cgroup_util.h" -#include "../clone3/clone3_selftests.h" +#include "../../clone3/clone3_selftests.h" /* Returns read len on success, or -errno on failure. */ ssize_t read_text (const char *path,char *buf,size_t max_len)
tools/testing/selftests/cgroup/lib/include/cgroup_util.h renamed from tools/testing/selftests/cgroup/cgroup_util.h +2 -2
@@ -2,9 +2,9 @@#include <stdbool.h> #include <stdlib.h> -#include "../kselftest.h" - +#ifndef PAGE_SIZE #define PAGE_SIZE 4096 +#endif #define MB (x) (x << 20)
tools/testing/selftests/cgroup/lib/libcgroup.mk new file +19 -0
@@ -0,0 +1,19 @@ +CGROUP_DIR := $(selfdir)/cgroup + +LIBCGROUP_C := lib/cgroup_util.c + +LIBCGROUP_O := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBCGROUP_C)) + +LIBCGROUP_O_DIRS := $(shell dirname $(LIBCGROUP_O) | uniq) + +CFLAGS += -I$(CGROUP_DIR)/lib/include + +EXTRA_HDRS := $(selfdir)/clone3/clone3_selftests.h + +$(LIBCGROUP_O_DIRS): + mkdir -p $@ + +$(LIBCGROUP_O): $(OUTPUT)/%.o : $(CGROUP_DIR)/%.c $(EXTRA_HDRS) $(LIBCGROUP_O_DIRS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ + +EXTRA_CLEAN += $(LIBCGROUP_O)
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 5/7 cgroup: selftests: Add API to find root of specific controller
In reply to James HoughtonFrom: Sean Christopherson <[email protected]>
Add an API in the cgroups library to find the root of a specific controller. KVM selftests will use the API to find the memory controller.
Search for the controller on both v1 and v2 mounts, as KVM selftests' usage will be completely oblivious of v1 versus v2.
--- .../selftests/cgroup/lib/cgroup_util.c | 34 +++++++++++++++---- .../cgroup/lib/include/cgroup_util.h | 1 + 2 files changed, 28 insertions(+), 7 deletions(-)
tools/testing/selftests/cgroup/lib/cgroup_util.c +27 -7
@@ -217,7 +217,8 @@ int cg_write_numeric(const char *cgroup, const char *control, long value)return cg_write (cgroup, control, buf); } -int cg_find_unified_root (char *root,size_t len,bool *nsdelegate) +static int cg_find_root (char *root,size_t len,const char *controller, +bool *nsdelegate) {char buf[10 *PAGE_SIZE ];char *fs, *mount, *type, *options;
@@ -236,18 +237,37 @@ int cg_find_unified_root(char *root, size_t len, bool *nsdelegate) options =strtok (NULL , delim);strtok (NULL , delim);strtok (NULL , delim); - -if (strcmp (type,"cgroup2" ) ==0 ) { -strncpy (root, mount, len); -if (nsdelegate) - *nsdelegate = !!strstr (options,"nsdelegate" ); -return 0 ; +if (strcmp (type,"cgroup" ) ==0 ) { +if (!controller || !strstr (options, controller)) +continue ; + }else if (strcmp (type,"cgroup2" ) ==0 ) { +if (controller && +cg_read_strstr (mount,"cgroup.controllers" , controller)) +continue ; + }else { +continue ; } +strncpy (root, mount, len); + +if (nsdelegate) + *nsdelegate = !!strstr (options,"nsdelegate" ); +return 0 ; + }return -1 ; } +int cg_find_controller_root (char *root,size_t len,const char *controller) +{ +return cg_find_root (root, len, controller,NULL ); +} + +int cg_find_unified_root (char *root,size_t len,bool *nsdelegate) +{ +return cg_find_root (root, len,NULL , nsdelegate); +} +int cg_create (const char *cgroup) {return mkdir (cgroup,0755 );
tools/testing/selftests/cgroup/lib/include/cgroup_util.h +1 -0
@@ -24,6 +24,7 @@ static inline int values_close(long a, long b, int err)extern ssize_t read_text (const char *path,char *buf,size_t max_len);extern ssize_t write_text (const char *path,char *buf,ssize_t len); +extern int cg_find_controller_root (char *root,size_t len,const char *controller);extern int cg_find_unified_root (char *root,size_t len,bool *nsdelegate);extern char *cg_name (const char *root,const char *name);extern char *cg_name_indexed (const char *root,const char *name,int index);
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 6/7 KVM: selftests: Build and link selftests/cgroup/lib into KVM selftests
In reply to James Houghtonlibcgroup.o is built separately from KVM selftests and cgroup selftests, so different compiler flags used by the different selftests will not conflict with each other.
--- tools/testing/selftests/kvm/Makefile.kvm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/Makefile.kvm +2 -1
@@ -204,6 +204,7 @@ OVERRIDE_TARGETS = 1 # importantly defines, i.e. overwrites, $(CC) (unless `make -e` or `make CC=`, # which causes the environment variable to override the makefile). include ../lib.mk +include ../cgroup/lib/libcgroup.mk INSTALL_HDR_PATH = $(top_srcdir)/usr LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
@@ -257,7 +258,7 @@ LIBKVM_S := $(filter %.S,$(LIBKVM)) LIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C)) LIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S)) LIBKVM_STRING_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_STRING)) -LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(LIBKVM_STRING_OBJ) +LIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(LIBKVM_STRING_OBJ) $(LIBCGROUP_O) SPLIT_TEST_GEN_PROGS := $(patsubst %, $(OUTPUT)/%, $(SPLIT_TESTS)) SPLIT_TEST_GEN_OBJ := $(patsubst %, $(OUTPUT)/$(ARCH)/%.o, $(SPLIT_TESTS))
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v4 7/7 KVM: selftests: access_tracking_perf_test: Use MGLRU for access tracking
In reply to James HoughtonUse MGLRU's debugfs interface to do access tracking instead of page_idle. The logic to use the page_idle bitmap is left in, as it is useful for kernels that do not have MGLRU built in.
When MGLRU is enabled, page_idle will report pages as still idle even after being accessed, as MGLRU doesn't necessarily clear the Idle folio flag when accessing an idle page, so the test will not attempt to use page_idle if MGLRU is enabled but otherwise not usable.
Aging pages with MGLRU is much faster than marking pages as idle with page_idle.
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/access_tracking_perf_test.c | 227 ++++++++-- .../selftests/kvm/include/lru_gen_util.h | 51 +++ .../testing/selftests/kvm/lib/lru_gen_util.c | 386 ++++++++++++++++++ 4 files changed, 638 insertions(+), 27 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/lru_gen_util.h create mode 100644 tools/testing/selftests/kvm/lib/lru_gen_util.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -8,6 +8,7 @@ LIBKVM += lib/elf.c LIBKVM += lib/guest_modes.c LIBKVM += lib/io.c LIBKVM += lib/kvm_util.c +LIBKVM += lib/lru_gen_util.c LIBKVM += lib/memstress.c LIBKVM += lib/guest_sprintf.c LIBKVM += lib/rbtree.c
tools/testing/selftests/kvm/access_tracking_perf_test.c +200 -27
336 lines not on this page · raw message
tools/testing/selftests/kvm/include/lru_gen_util.h new file +51 -0
51 lines not on this page · raw message
tools/testing/selftests/kvm/lib/lru_gen_util.c new file +386 -0
386 lines not on this page · raw message
Signature · 1 line
2.49.0.1015.ga840276032-goog
Sean Christopherson
reviewerRe: [PATCH v4 7/7] KVM: selftests: access_tracking_perf_test: Use MGLRU for access tracking
tools/testing/selftests/kvm/access_tracking_perf_test.c static void help(char *name) · line 504
Quoted 6 lines · James Houghton
tools/testing/selftests/kvm/access_tracking_perf_test.c +1
-1@@ -372,7 +501,7 @@ static void help(char *name)printf (" -v: specify the number of vCPUs to run.\n" );printf (" -o: Overlap guest memory accesses instead of partitioning\n" " them into a separate region of memory for each vCPU.\n" ); - printf(" -w: Control whether the test warns or fails if more than 10%\n" + printf(" -w: Control whether the test warns or fails if more than 10%%\n"
This belongs in patch 2. I'll fixup when applying.
Sean Christopherson
reviewerQuoted 8 lines · James Houghton
This series fixes some issues with
access_tracking_perf_testwhen MGLRU or NUMA balancing are in use.With MGLRU, touching a page doesn't necessarily clear the Idle flag. This has come up in the past, and the recommendation was to use MGLRU generation numbers[1], which this series does.
[...]
Applied to kvm-x86 selftests, thanks!
[1/7] KVM: selftests: Extract guts of THP accessor to standalone sysfs helpers
https://github.com/kvm-x86/linux/commit/d761c14d902e [2/7] KVM: selftests: access_tracking_perf_test: Add option to skip the sanity check https://github.com/kvm-x86/linux/commit/26dcdfa01c33 [3/7] cgroup: selftests: Move memcontrol specific helpers out of common cgroup_util.c https://github.com/kvm-x86/linux/commit/3a7f9e518c6a [4/7] cgroup: selftests: Move cgroup_util into its own library https://github.com/kvm-x86/linux/commit/2c754a84ff16 [5/7] cgroup: selftests: Add API to find root of specific controller https://github.com/kvm-x86/linux/commit/38e1dd578142 [6/7] KVM: selftests: Build and link selftests/cgroup/lib into KVM selftests https://github.com/kvm-x86/linux/commit/b11fcb51e2b2 [7/7] KVM: selftests: access_tracking_perf_test: Use MGLRU for access tracking https://github.com/kvm-x86/linux/commit/d166453ebd29