From nobody Fri Apr 10 20:21:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74D07C32771 for ; Fri, 19 Aug 2022 11:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbiHSLeh (ORCPT ); Fri, 19 Aug 2022 07:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347966AbiHSLeb (ORCPT ); Fri, 19 Aug 2022 07:34:31 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A27F380B66 for ; Fri, 19 Aug 2022 04:34:28 -0700 (PDT) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 27JBTQbI043766 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Fri, 19 Aug 2022 19:29:26 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 19 Aug 2022 19:29:27 +0800 From: "zhaoyang.huang" To: Johannes Weiner , Michal Hocko , Zhaoyang Huang , , , , , Tejun Heo , Zefan Li , Roman Gushchin , Shakeel Butt , Muchun Song Subject: [RFC PATCH] memcg: use root_mem_cgroup when css is inherited Date: Fri, 19 Aug 2022 19:29:22 +0800 Message-ID: <1660908562-17409-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 27JBTQbI043766 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zhaoyang Huang It is observed in android system where per-app cgroup is demanded by freezer subsys and part of groups require memory control. The hierarchy could be si= mplized as bellowing where memory charged on group B abserved while we only want ha= ve group E's memory be controlled and B's descendants compete freely for memor= y. This should be the consequences of unified hierarchy. Under this scenario, less efficient memory reclaim is observed when compari= ng with no memory control. It is believed that multi LRU scanning introduces s= ome of the overhead. Furthermore, page thrashing is also heavier than global LRU which could be the consequences of partial failure of WORKINGSET mechanism = as LRU is too short to protect the active pages. A(subtree_control =3D memory) - B(subtree_control =3D NULL) - C() \ D() - E(subtree_control =3D memory) - F() \ G() Signed-off-by: Zhaoyang Huang --- include/linux/cgroup.h | 1 + kernel/cgroup/cgroup.c | 11 +++++++++++ mm/memcontrol.c | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 0d1ada8..747f0f4 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -136,6 +136,7 @@ extern void cgroup_post_fork(struct task_struct *p, =20 int cgroup_parse_float(const char *input, unsigned dec_shift, s64 *v); =20 +struct cgroup *get_task_cgroup(struct task_struct *task); /* * Iteration helpers and macros. */ diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 1779ccd..3f34c58 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -1457,6 +1457,17 @@ struct cgroup *task_cgroup_from_root(struct task_str= uct *task, return cset_cgroup_from_root(task_css_set(task), root); } =20 +struct cgroup *get_task_cgroup(struct task_struct *task) +{ + struct cgroup *src_cgrp; + /* find the source cgroup */ + spin_lock_irq(&css_set_lock); + src_cgrp =3D task_cgroup_from_root(task, &cgrp_dfl_root); + spin_unlock_irq(&css_set_lock); + + return src_cgrp; +} + /* * A task must hold cgroup_mutex to modify cgroups. * diff --git a/mm/memcontrol.c b/mm/memcontrol.c index abec50f..c81012b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -930,6 +930,7 @@ static __always_inline struct mem_cgroup *active_memcg(= void) struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) { struct mem_cgroup *memcg; + struct cgroup *cgrp; =20 if (mem_cgroup_disabled()) return NULL; @@ -956,9 +957,11 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_st= ruct *mm) } =20 rcu_read_lock(); + cgrp =3D get_task_cgroup(rcu_dereference(mm->owner)); do { memcg =3D mem_cgroup_from_task(rcu_dereference(mm->owner)); - if (unlikely(!memcg)) + if (unlikely(!memcg) + || !(cgroup_ss_mask(cgrp) & (1 << memory_cgrp_id))) memcg =3D root_mem_cgroup; } while (!css_tryget(&memcg->css)); rcu_read_unlock(); --=20 1.9.1