]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: memcontrol: split out __obj_cgroup_charge()
authorJohannes Weiner <hannes@cmpxchg.org>
Mon, 2 Mar 2026 19:50:16 +0000 (14:50 -0500)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 5 Apr 2026 20:53:16 +0000 (13:53 -0700)
Move the page charge and remainder calculation into its own function.  It
will make the slab stat refactor easier to follow.

Link: https://lkml.kernel.org/r/20260302195305.620713-4-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: Johannes Weiner <jweiner@meta.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memcontrol.c

index 5dd61e35f50d1ef2d35f011b35a12348ca18712a..c01da86e6a2e52ab9378ebb4640b0646498f71bd 100644 (file)
@@ -3156,10 +3156,24 @@ out:
                obj_cgroup_uncharge_pages(objcg, nr_pages);
 }
 
+static int __obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp,
+                              size_t size, size_t *remainder)
+{
+       size_t charge_size;
+       int ret;
+
+       charge_size = PAGE_ALIGN(size);
+       ret = obj_cgroup_charge_pages(objcg, gfp, charge_size >> PAGE_SHIFT);
+       if (!ret)
+               *remainder = charge_size - size;
+
+       return ret;
+}
+
 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)
 {
-       size_t charge_size, remainder;
+       size_t remainder;
        int ret;
 
        if (likely(consume_obj_stock(objcg, size, pgdat, idx)))
@@ -3188,10 +3202,7 @@ 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.
         */
-       charge_size = PAGE_ALIGN(size);
-       remainder = charge_size - size;
-
-       ret = obj_cgroup_charge_pages(objcg, gfp, charge_size >> PAGE_SHIFT);
+       ret = __obj_cgroup_charge(objcg, gfp, size, &remainder);
        if (!ret && (remainder || pgdat))
                refill_obj_stock(objcg, remainder, false, size, pgdat, idx);