Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1504840rwb; Fri, 19 Aug 2022 05:02:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Ynt8iiRpVO8nbAWOjaPvg0iYbkgDRRQw4rtSpUKsbXOtOHTqPo0NX0Ljn5KWs66kYKz3O X-Received: by 2002:a05:6402:3585:b0:445:e56b:faf7 with SMTP id y5-20020a056402358500b00445e56bfaf7mr5817958edc.356.1660910570023; Fri, 19 Aug 2022 05:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660910570; cv=none; d=google.com; s=arc-20160816; b=SQhI2IRfS89vgUs4/Vi8cYaaK+98osHiDieNMiYen4ShUFZUfINZEFBKy5+m5APUb4 MK85WVwNe5bywvQW+lBhrfF61hqJi+qqPq0bjT58u2gLsOApFFB6tokzCc8uIubN7Clr dmuJ/iAqgdtbZN3j+l9uLORVSmqOFy1GSUHfyV6qE8RdVN4nO+G0gk3obuLqZ+CYylww jo7mmxhnluce+sL1m1v983lFkpXAjYrTxLIKH0P3WAa8N0+ZnRHqTWc6JbaZovUzhrf3 12gB24skPRKkrS9HOxhBvepPCRijIfQiOXYZ9Q6CkbWcoEzHGqCdv8wqbjme3tKJlqKn lKiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=EuX1meLOg0oHjjxDbVEpDgR2oMqWCNr4J1FW+oczNkw=; b=xMmRHQnscdVLBRMpVpTgIp/Nt6d8Kruj5ZC67YWLzOBsR2C5PCxgy5/cJ3pdOwwJYE fUICVJfLTuz9xWLhOUAvTzpsetj3r1hn64UjF7BiNelaBt7mSpuY5tX6Vd2zAutK1GjM prp6oiu/5fwPzlboMhZlCKuk5AOgWombXT++1DFxQjStvrHUFuja5qFUKeK46Xo0sCZr 71wygfDQTlOrD2j/NNrBfq3u8JPjGwWffvEE3zQ2btyRjsS7CqB8deGsS4Bv4ErpRnqc wbdHvCsF91UnDhD+IXNHxctHAXz4QbDMafQn11zrvRMjNq0pIOa1Fu9c88AWb73Fde9k nxLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw8-20020a056402228800b00446305c6606si1526185edb.206.2022.08.19.05.02.23; Fri, 19 Aug 2022 05:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348210AbiHSLeg (ORCPT + 99 others); Fri, 19 Aug 2022 07:34:36 -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 Content-Type: text/plain 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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(); -- 1.9.1