Commit bcfe6bd5 authored by Roman Gushchin's avatar Roman Gushchin Committed by Liu Shixin
Browse files

mm: kmem: reimplement get_obj_cgroup_from_current()

mainline inclusion
from mainline-v6.7-rc1
commit e56808fef8f71a192b2740c0b6ea8be7ab865d54
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8YU7J

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e56808fef8f71a192b2740c0b6ea8be7ab865d54

--------------------------------

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: default avatarRoman Gushchin (Cruise) <roman.gushchin@linux.dev>
Reviewed-by: default avatarVlastimil Babka <vbabka@suse.cz>
Acked-by: default avatarShakeel 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent f027f151
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -1870,9 +1870,18 @@ void __memcg_kmem_uncharge_page(struct page *page, int order);
 * needs to be used outside of the local scope.
 */
struct obj_cgroup *current_obj_cgroup(void);
struct obj_cgroup *get_obj_cgroup_from_current(void);
struct obj_cgroup *get_obj_cgroup_from_folio(struct folio *folio);

static inline struct obj_cgroup *get_obj_cgroup_from_current(void)
{
	struct obj_cgroup *objcg = current_obj_cgroup();

	if (objcg)
		obj_cgroup_get(objcg);

	return objcg;
}

int obj_cgroup_charge(struct obj_cgroup *objcg, gfp_t gfp, size_t size);
void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size);

+0 −32
Original line number Diff line number Diff line
@@ -3161,38 +3161,6 @@ static struct obj_cgroup *current_objcg_update(void)
	return objcg;
}

__always_inline struct obj_cgroup *get_obj_cgroup_from_current(void)
{
	struct mem_cgroup *memcg;
	struct obj_cgroup *objcg;

	if (in_task()) {
		memcg = current->active_memcg;
		if (unlikely(memcg))
			goto from_memcg;

		objcg = READ_ONCE(current->objcg);
		if (unlikely((unsigned long)objcg & CURRENT_OBJCG_UPDATE_FLAG))
			objcg = current_objcg_update();

		if (objcg) {
			obj_cgroup_get(objcg);
			return objcg;
		}
	} else {
		memcg = this_cpu_read(int_active_memcg);
		if (unlikely(memcg))
			goto from_memcg;
	}
	return NULL;

from_memcg:
	rcu_read_lock();
	objcg = __get_obj_cgroup_from_memcg(memcg);
	rcu_read_unlock();
	return objcg;
}

__always_inline struct obj_cgroup *current_obj_cgroup(void)
{
	struct mem_cgroup *memcg;