Skip to content

Commit e5d8506

Browse files
rgushchinAvenger-285714
authored andcommitted
mm: kmem: reimplement get_obj_cgroup_from_current()
mainline inclusion from mainline-v6.7-rc1 category: performance commit e56808f upstream. Reimplement get_obj_cgroup_from_current() using current_obj_cgroup(). get_obj_cgroup_from_current() and current_obj_cgroup() share 80% of the code, so the new implementation is almost trivial. get_obj_cgroup_from_current() is a convenient function used by the bpf subsystem, so there is no reason to get rid of it completely. Link: https://lkml.kernel.org/r/20231019225346.1822282-7-roman.gushchin@linux.dev Signed-off-by: Roman Gushchin (Cruise) <roman.gushchin@linux.dev> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Shakeel Butt <shakeelb@google.com> 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> Cc: Naresh Kamboju <naresh.kamboju@linaro.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> (cherry picked from commit e56808f) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 864359d commit e5d8506

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

include/linux/memcontrol.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,9 +1779,18 @@ void __memcg_kmem_uncharge_page(struct page *page, int order);
17791779
* needs to be used outside of the local scope.
17801780
*/
17811781
struct obj_cgroup *current_obj_cgroup(void);
1782-
struct obj_cgroup *get_obj_cgroup_from_current(void);
17831782
struct obj_cgroup *get_obj_cgroup_from_folio(struct folio *folio);
17841783

1784+
static inline struct obj_cgroup *get_obj_cgroup_from_current(void)
1785+
{
1786+
struct obj_cgroup *objcg = current_obj_cgroup();
1787+
1788+
if (objcg)
1789+
obj_cgroup_get(objcg);
1790+
1791+
return objcg;
1792+
}
1793+
17851794
int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size);
17861795
void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size);
17871796

mm/memcontrol.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,38 +3060,6 @@ static struct obj_cgroup *current_objcg_update(void)
30603060
return objcg;
30613061
}
30623062

3063-
__always_inline struct obj_cgroup *get_obj_cgroup_from_current(void)
3064-
{
3065-
struct mem_cgroup *memcg;
3066-
struct obj_cgroup *objcg;
3067-
3068-
if (in_task()) {
3069-
memcg = current->active_memcg;
3070-
if (unlikely(memcg))
3071-
goto from_memcg;
3072-
3073-
objcg = READ_ONCE(current->objcg);
3074-
if (unlikely((unsigned long)objcg & CURRENT_OBJCG_UPDATE_FLAG))
3075-
objcg = current_objcg_update();
3076-
3077-
if (objcg) {
3078-
obj_cgroup_get(objcg);
3079-
return objcg;
3080-
}
3081-
} else {
3082-
memcg = this_cpu_read(int_active_memcg);
3083-
if (unlikely(memcg))
3084-
goto from_memcg;
3085-
}
3086-
return NULL;
3087-
3088-
from_memcg:
3089-
rcu_read_lock();
3090-
objcg = __get_obj_cgroup_from_memcg(memcg);
3091-
rcu_read_unlock();
3092-
return objcg;
3093-
}
3094-
30953063
__always_inline struct obj_cgroup *current_obj_cgroup(void)
30963064
{
30973065
struct mem_cgroup *memcg;

0 commit comments

Comments
 (0)