From patchwork Fri Aug 19 11:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 12948753 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC39CC32771 for ; Fri, 19 Aug 2022 11:33:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 04DB78D0003; Fri, 19 Aug 2022 07:33:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3F778D0001; Fri, 19 Aug 2022 07:33:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E06F98D0003; Fri, 19 Aug 2022 07:33:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D0BD08D0001 for ; Fri, 19 Aug 2022 07:33:55 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9317AC0B94 for ; Fri, 19 Aug 2022 11:33:55 +0000 (UTC) X-FDA: 79816132830.21.2C5DF34 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf24.hostedemail.com (Postfix) with ESMTP id C11DD180027 for ; Fri, 19 Aug 2022 11:33:53 +0000 (UTC) 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660908834; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=EuX1meLOg0oHjjxDbVEpDgR2oMqWCNr4J1FW+oczNkw=; b=fgK/uO4ZkIeHzNRiixHlUyWCPH1RurrmX/MrH4A63M4rRXEXVTFe2XjLnkFjyNfbwRte+k +9oudPocOhSVyZ9QsxMD2sp5dp856P6CLQ5UkI0BxlzJ4hPjA2KPgOWXzpbpW+wQ9/FKhy Vo0wejj84wtpRQNpjfZIg6gv8ztDS3g= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660908834; a=rsa-sha256; cv=none; b=KwpYte5KxO7A5keAPTk/iRgaQG/9l3ms4vf0fbrndFkAwYZpRp2z/hghZAe0enopNRn241 gG9N8JYu5+RbHuUmW3JfP4EfzIDAMkZj8qqaVzURq8lwYvrz+ZoJ/UvXlOCd7xYfw7J8gB vGPMEPGZf6HvmQXjrmtLGGS0RanwFoQ= X-Stat-Signature: 6dty676dtds5hqhh7keyr8raq65e173g X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C11DD180027 X-HE-Tag: 1660908833-552726 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 simplized as bellowing where memory charged on group B abserved while we only want have group E's memory be controlled and B's descendants compete freely for memory. This should be the consequences of unified hierarchy. Under this scenario, less efficient memory reclaim is observed when comparing with no memory control. It is believed that multi LRU scanning introduces some 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 = memory) - B(subtree_control = NULL) - C() \ D() - E(subtree_control = memory) - F() \ G() Signed-off-by: Zhaoyang Huang Nacked-by: Tejun Heo Nacked-by: Johannes Weiner --- 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, int cgroup_parse_float(const char *input, unsigned dec_shift, s64 *v); +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_struct *task, return cset_cgroup_from_root(task_css_set(task), root); } +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 = 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; if (mem_cgroup_disabled()) return NULL; @@ -956,9 +957,11 @@ struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm) } rcu_read_lock(); + cgrp = get_task_cgroup(rcu_dereference(mm->owner)); do { memcg = mem_cgroup_from_task(rcu_dereference(mm->owner)); - if (unlikely(!memcg)) + if (unlikely(!memcg) + || !(cgroup_ss_mask(cgrp) & (1 << memory_cgrp_id))) memcg = root_mem_cgroup; } while (!css_tryget(&memcg->css)); rcu_read_unlock();