| From: Shakeel Butt <shakeel.butt@linux.dev> |
| Subject: memcg: simplify MEMCG_VMALLOC updates - fix |
| Date: Fri, 4 Apr 2025 10:41:52 -0700 |
| |
| add comment |
| |
| Link: https://lkml.kernel.org/r/bmlkdbqgwboyqrnxyom7n52fjmo76ux77jhqw5odc6c6dfon3h@zdylwtmlywbt |
| Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev> |
| Cc: Johannes Weiner <hannes@cmpxchg.org> |
| Cc: Michal Hocko <mhocko@suse.com> |
| Cc: Muchun Song <muchun.song@linux.dev> |
| Cc: Roman Gushchin <roman.gushchin@linux.dev> |
| Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| mm/vmalloc.c | 2 ++ |
| 1 file changed, 2 insertions(+) |
| |
| --- a/mm/vmalloc.c~memcg-vmalloc-simplify-memcg_vmalloc-updates-fix |
| +++ a/mm/vmalloc.c |
| @@ -3371,6 +3371,7 @@ void vfree(const void *addr) |
| |
| if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS)) |
| vm_reset_perms(vm); |
| + /* All pages of vm should be charged to same memcg, so use first one. */ |
| if (vm->nr_pages && !(vm->flags & VM_MAP_PUT_PAGES)) |
| mod_memcg_page_state(vm->pages[0], MEMCG_VMALLOC, -vm->nr_pages); |
| for (i = 0; i < vm->nr_pages; i++) { |
| @@ -3672,6 +3673,7 @@ static void *__vmalloc_area_node(struct |
| node, page_order, nr_small_pages, area->pages); |
| |
| atomic_long_add(area->nr_pages, &nr_vmalloc_pages); |
| + /* All pages of vm should be charged to same memcg, so use first one. */ |
| if (gfp_mask & __GFP_ACCOUNT && area->nr_pages) |
| mod_memcg_page_state(area->pages[0], MEMCG_VMALLOC, |
| area->nr_pages); |
| _ |