mirror of
https://github.com/torvalds/linux.git
synced 2026-06-03 03:53:37 +02:00
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>
This commit is contained in:
parent
9f2541d9b2
commit
9d181e4709
|
|
@ -3159,7 +3159,7 @@ static void refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes,
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user