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.

mm: memcg: simplify objcg charge size and stock remainder math

Use PAGE_ALIGN() and a more natural cache remainder calculation.

Link: https://lkml.kernel.org/r/20260302195305.620713-3-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Reviewed-by: Hao Li <hao.li@linux.dev>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Johannes Weiner and committed by
Andrew Morton
9d181e47 9f2541d9

+6 -10
+6 -10
mm/memcontrol.c
··· 3159 3159 static int obj_cgroup_charge_account(struct obj_cgroup *objcg, gfp_t gfp, size_t size, 3160 3160 struct pglist_data *pgdat, enum node_stat_item idx) 3161 3161 { 3162 - unsigned int nr_pages, nr_bytes; 3162 + size_t charge_size, remainder; 3163 3163 int ret; 3164 3164 3165 3165 if (likely(consume_obj_stock(objcg, size, pgdat, idx))) ··· 3188 3188 * bytes is (sizeof(object) + PAGE_SIZE - 2) if there is no data 3189 3189 * race. 3190 3190 */ 3191 - nr_pages = size >> PAGE_SHIFT; 3192 - nr_bytes = size & (PAGE_SIZE - 1); 3191 + charge_size = PAGE_ALIGN(size); 3192 + remainder = charge_size - size; 3193 3193 3194 - if (nr_bytes) 3195 - nr_pages += 1; 3196 - 3197 - ret = obj_cgroup_charge_pages(objcg, gfp, nr_pages); 3198 - if (!ret && (nr_bytes || pgdat)) 3199 - refill_obj_stock(objcg, nr_bytes ? PAGE_SIZE - nr_bytes : 0, 3200 - false, size, pgdat, idx); 3194 + ret = obj_cgroup_charge_pages(objcg, gfp, charge_size >> PAGE_SHIFT); 3195 + if (!ret && (remainder || pgdat)) 3196 + refill_obj_stock(objcg, remainder, false, size, pgdat, idx); 3201 3197 3202 3198 return ret; 3203 3199 }