Commit c63b835d authored by Roman Gushchin's avatar Roman Gushchin Committed by Andrew Morton

percpu: scoped objcg protection

Similar to slab and kmem, switch to a scope-based protection of the objcg
pointer to avoid.

Link: https://lkml.kernel.org/r/20231019225346.1822282-6-roman.gushchin@linux.devSigned-off-by: default avatarRoman Gushchin (Cruise) <roman.gushchin@linux.dev>
Tested-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
Acked-by: default avatarShakeel Butt <shakeelb@google.com>
Reviewed-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent e86828e5
...@@ -1628,14 +1628,12 @@ static bool pcpu_memcg_pre_alloc_hook(size_t size, gfp_t gfp, ...@@ -1628,14 +1628,12 @@ static bool pcpu_memcg_pre_alloc_hook(size_t size, gfp_t gfp,
if (!memcg_kmem_online() || !(gfp & __GFP_ACCOUNT)) if (!memcg_kmem_online() || !(gfp & __GFP_ACCOUNT))
return true; return true;
objcg = get_obj_cgroup_from_current(); objcg = current_obj_cgroup();
if (!objcg) if (!objcg)
return true; return true;
if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size))) { if (obj_cgroup_charge(objcg, gfp, pcpu_obj_full_size(size)))
obj_cgroup_put(objcg);
return false; return false;
}
*objcgp = objcg; *objcgp = objcg;
return true; return true;
...@@ -1649,6 +1647,7 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, ...@@ -1649,6 +1647,7 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg,
return; return;
if (likely(chunk && chunk->obj_cgroups)) { if (likely(chunk && chunk->obj_cgroups)) {
obj_cgroup_get(objcg);
chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg; chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] = objcg;
rcu_read_lock(); rcu_read_lock();
...@@ -1657,7 +1656,6 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg, ...@@ -1657,7 +1656,6 @@ static void pcpu_memcg_post_alloc_hook(struct obj_cgroup *objcg,
rcu_read_unlock(); rcu_read_unlock();
} else { } else {
obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size)); obj_cgroup_uncharge(objcg, pcpu_obj_full_size(size));
obj_cgroup_put(objcg);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment