From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3787EC56202 for ; Thu, 26 Nov 2020 12:10:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5E87B20DD4 for ; Thu, 26 Nov 2020 12:10:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E87B20DD4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6C0AC6B0071; Thu, 26 Nov 2020 07:10:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 648256B0072; Thu, 26 Nov 2020 07:10:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2B66B0074; Thu, 26 Nov 2020 07:10:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 2EACE6B0071 for ; Thu, 26 Nov 2020 07:10:21 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E83CC8249980 for ; Thu, 26 Nov 2020 12:10:20 +0000 (UTC) X-FDA: 77526451800.17.kiss30_06035982737f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id CE540180D0181 for ; Thu, 26 Nov 2020 12:10:20 +0000 (UTC) X-HE-Tag: kiss30_06035982737f X-Filterd-Recvd-Size: 3982 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Nov 2020 12:10:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EBEB0AC22; Thu, 26 Nov 2020 12:10:18 +0000 (UTC) Subject: Re: [PATCH] mm/list_lru: dont make them memcg aware if kmem is disabled To: Balbir Singh , linux-mm@kvack.org, mhocko@kernel.org Cc: hannes@cmpxchg.org, vdavydov.dev@gmail.com References: <20201126043023.377343-1-bsingharora@gmail.com> From: Vlastimil Babka Message-ID: Date: Thu, 26 Nov 2020 13:10:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201126043023.377343-1-bsingharora@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 11/26/20 5:30 AM, Balbir Singh wrote: > When alloc_super() allocates list_lrus for dentries and inodes > they are made memcg aware if KMEM is compiled in, we should > also check if kmem was disabled at runtime. > > This overhead is about 32 bytes extra per possible nodes per caller > of list_lru_init() > > Signed-off-by: Balbir Singh I'd rather export cgroup_memory_nokmem and make cgroup_kmem_disabled() inline, put it next to memcg_kmem_enabled() and explain in comments what each means. And ideally, the current memcg_kmem_enabled() should be named e.g. memcg_kmem_active(), and then the new cgroup_kmem_disabled() could be named memcg_kmem_enabled(). But that's churn and potential future backport hazard, so dunno. > --- > include/linux/memcontrol.h | 6 ++++++ > mm/list_lru.c | 9 +++++++++ > mm/memcontrol.c | 9 +++++++++ > 3 files changed, 24 insertions(+) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 4a4df9a23a8b..4285741a855d 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -1636,6 +1636,7 @@ static inline bool memcg_kmem_enabled(void) > return static_branch_likely(&memcg_kmem_enabled_key); > } > > +extern bool cgroup_kmem_disabled(void); > static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp, > int order) > { > @@ -1691,6 +1692,11 @@ static inline bool memcg_kmem_enabled(void) > return false; > } > > +static inline bool cgroup_kmem_disabled(void) > +{ > + return false; > +} > + > static inline int memcg_cache_id(struct mem_cgroup *memcg) > { > return -1; > diff --git a/mm/list_lru.c b/mm/list_lru.c > index 5aa6e44bc2ae..478386aa9852 100644 > --- a/mm/list_lru.c > +++ b/mm/list_lru.c > @@ -439,6 +439,15 @@ static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware) > { > int i; > > + /* > + * Override memcg_aware here, otherwise callers > + * will allocate memcg aware lru's and that wastes > + * memory and the amount can scale with the number of > + * nodes and caller contexts. > + */ > + if (cgroup_kmem_disabled()) > + memcg_aware = false; > + > lru->memcg_aware = memcg_aware; > > if (!memcg_aware) > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 15f2396f1605..8edf3ada8f4e 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -99,6 +99,15 @@ static bool do_memsw_account(void) > return !cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_noswap; > } > > +/* > + * NOTE: This is not the logical opposite of what > + * memcg_kmem_enabled() does > + */ > +bool cgroup_kmem_disabled(void) > +{ > + return cgroup_memory_nokmem; > +} > + > #define THRESHOLDS_EVENTS_TARGET 128 > #define SOFTLIMIT_EVENTS_TARGET 1024 > >