Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kselftests: cgroup: update kmem test for new vmstat implementation

With memcg having switched to rstat, memory.stat output is precise.
Update the cgroup selftest to reflect the expectations and error
tolerances of the new implementation.

Also add newly tracked types of memory to the memory.stat side of the
equation, since they're included in memory.current and could throw false
positives.

Link: https://lkml.kernel.org/r/20210209163304.77088-9-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Johannes Weiner and committed by
Linus Torvalds
4bbcc5a4 2cd21c89

+14 -8
+14 -8
tools/testing/selftests/cgroup/test_kmem.c
··· 19 19 20 20 21 21 /* 22 - * Memory cgroup charging and vmstat data aggregation is performed using 23 - * percpu batches 32 pages big (look at MEMCG_CHARGE_BATCH). So the maximum 24 - * discrepancy between charge and vmstat entries is number of cpus multiplied 25 - * by 32 pages multiplied by 2. 22 + * Memory cgroup charging is performed using percpu batches 32 pages 23 + * big (look at MEMCG_CHARGE_BATCH), whereas memory.stat is exact. So 24 + * the maximum discrepancy between charge and vmstat entries is number 25 + * of cpus multiplied by 32 pages. 26 26 */ 27 - #define MAX_VMSTAT_ERROR (4096 * 32 * 2 * get_nprocs()) 27 + #define MAX_VMSTAT_ERROR (4096 * 32 * get_nprocs()) 28 28 29 29 30 30 static int alloc_dcache(const char *cgroup, void *arg) ··· 162 162 */ 163 163 static int test_kmem_memcg_deletion(const char *root) 164 164 { 165 - long current, slab, anon, file, kernel_stack, sum; 165 + long current, slab, anon, file, kernel_stack, pagetables, percpu, sock, sum; 166 166 int ret = KSFT_FAIL; 167 167 char *parent; 168 168 ··· 184 184 anon = cg_read_key_long(parent, "memory.stat", "anon "); 185 185 file = cg_read_key_long(parent, "memory.stat", "file "); 186 186 kernel_stack = cg_read_key_long(parent, "memory.stat", "kernel_stack "); 187 + pagetables = cg_read_key_long(parent, "memory.stat", "pagetables "); 188 + percpu = cg_read_key_long(parent, "memory.stat", "percpu "); 189 + sock = cg_read_key_long(parent, "memory.stat", "sock "); 187 190 if (current < 0 || slab < 0 || anon < 0 || file < 0 || 188 - kernel_stack < 0) 191 + kernel_stack < 0 || pagetables < 0 || percpu < 0 || sock < 0) 189 192 goto cleanup; 190 193 191 - sum = slab + anon + file + kernel_stack; 194 + sum = slab + anon + file + kernel_stack + pagetables + percpu + sock; 192 195 if (abs(sum - current) < MAX_VMSTAT_ERROR) { 193 196 ret = KSFT_PASS; 194 197 } else { ··· 201 198 printf("anon = %ld\n", anon); 202 199 printf("file = %ld\n", file); 203 200 printf("kernel_stack = %ld\n", kernel_stack); 201 + printf("pagetables = %ld\n", pagetables); 202 + printf("percpu = %ld\n", percpu); 203 + printf("sock = %ld\n", sock); 204 204 } 205 205 206 206 cleanup: