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

Configure Feed

Select the types of activity you want to include in your feed.

memcg: vmalloc: simplify MEMCG_VMALLOC updates

The vmalloc region can either be charged to a single memcg or none. At
the moment kernel traverses all the pages backing the vmalloc region to
update the MEMCG_VMALLOC stat. However there is no need to look at all
the pages as all those pages will be charged to a single memcg or none.
Simplify the MEMCG_VMALLOC update by just looking at the first page of the
vmalloc region.

[shakeel.butt@linux.dev: add comment]
Link: https://lkml.kernel.org/r/bmlkdbqgwboyqrnxyom7n52fjmo76ux77jhqw5odc6c6dfon3h@zdylwtmlywbt
Link: https://lkml.kernel.org/r/20250403053326.26860-1-shakeel.butt@linux.dev
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Shakeel Butt and committed by
Andrew Morton
aa8d89d1 98c93890

+7 -8
+7 -8
mm/vmalloc.c
··· 3371 3371 3372 3372 if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS)) 3373 3373 vm_reset_perms(vm); 3374 + /* All pages of vm should be charged to same memcg, so use first one. */ 3375 + if (vm->nr_pages && !(vm->flags & VM_MAP_PUT_PAGES)) 3376 + mod_memcg_page_state(vm->pages[0], MEMCG_VMALLOC, -vm->nr_pages); 3374 3377 for (i = 0; i < vm->nr_pages; i++) { 3375 3378 struct page *page = vm->pages[i]; 3376 3379 3377 3380 BUG_ON(!page); 3378 - if (!(vm->flags & VM_MAP_PUT_PAGES)) 3379 - mod_memcg_page_state(page, MEMCG_VMALLOC, -1); 3380 3381 /* 3381 3382 * High-order allocs for huge vmallocs are split, so 3382 3383 * can be freed as an array of order-0 allocations ··· 3673 3672 node, page_order, nr_small_pages, area->pages); 3674 3673 3675 3674 atomic_long_add(area->nr_pages, &nr_vmalloc_pages); 3676 - if (gfp_mask & __GFP_ACCOUNT) { 3677 - int i; 3678 - 3679 - for (i = 0; i < area->nr_pages; i++) 3680 - mod_memcg_page_state(area->pages[i], MEMCG_VMALLOC, 1); 3681 - } 3675 + /* All pages of vm should be charged to same memcg, so use first one. */ 3676 + if (gfp_mask & __GFP_ACCOUNT && area->nr_pages) 3677 + mod_memcg_page_state(area->pages[0], MEMCG_VMALLOC, 3678 + area->nr_pages); 3682 3679 3683 3680 /* 3684 3681 * If not enough pages were obtained to accomplish an