summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <jweiner@meta.com>2026-03-02 22:50:15 +0300
committerAndrew Morton <akpm@linux-foundation.org>2026-04-05 23:53:16 +0300
commit9d181e47098d6911f4a5b3d9feff60c2bf6786a2 (patch)
tree2606a223af4216e8f70f438a4a1b4d0e3c25e3ea
parent9f2541d9b2fc1ee86415b8d41f6a19cb2a582aac (diff)
downloadlinux-9d181e47098d6911f4a5b3d9feff60c2bf6786a2.tar.xz
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>
-rw-r--r--mm/memcontrol.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5262533d0828..5dd61e35f50d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3159,7 +3159,7 @@ out:
static int obj_cgroup_charge_account(struct obj_cgroup *objcg, gfp_t gfp, size_t size,
struct pglist_data *pgdat, enum node_stat_item idx)
{
- unsigned int nr_pages, nr_bytes;
+ size_t charge_size, remainder;
int ret;
if (likely(consume_obj_stock(objcg, size, pgdat, idx)))
@@ -3188,16 +3188,12 @@ static int obj_cgroup_charge_account(struct obj_cgroup *objcg, gfp_t gfp, size_t
* bytes is (sizeof(object) + PAGE_SIZE - 2) if there is no data
* race.
*/
- nr_pages = size >> PAGE_SHIFT;
- nr_bytes = size & (PAGE_SIZE - 1);
+ charge_size = PAGE_ALIGN(size);
+ remainder = charge_size - size;
- if (nr_bytes)
- nr_pages += 1;
-
- ret = obj_cgroup_charge_pages(objcg, gfp, nr_pages);
- if (!ret && (nr_bytes || pgdat))
- refill_obj_stock(objcg, nr_bytes ? PAGE_SIZE - nr_bytes : 0,
- false, size, pgdat, idx);
+ ret = obj_cgroup_charge_pages(objcg, gfp, charge_size >> PAGE_SHIFT);
+ if (!ret && (remainder || pgdat))
+ refill_obj_stock(objcg, remainder, false, size, pgdat, idx);
return ret;
}