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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9678CC433F5 for ; Sun, 22 May 2022 21:14:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 236C68D0006; Sun, 22 May 2022 17:14:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E6D68D0005; Sun, 22 May 2022 17:14:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D6C78D0006; Sun, 22 May 2022 17:14:47 -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 F28FE8D0005 for ; Sun, 22 May 2022 17:14:46 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id DA26B608CC for ; Sun, 22 May 2022 07:05:40 +0000 (UTC) X-FDA: 79492493640.07.856877F Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf21.hostedemail.com (Postfix) with ESMTP id BFA071C0026 for ; Sun, 22 May 2022 07:05:26 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id a9so9100653pgv.12 for ; Sun, 22 May 2022 00:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tjn5cOhPCJTjLCzK5W9G1YBEVUEJ+0rPrDGESwiPuzc=; b=6ErhHO7dbpgMH9Zx1cY/WLrWxTcKKKUhBSAT93UR5AofH7RZKOvRzTXakMcnc2c3dv aXUDK/yYpi8AmTnCO3FonlmbFvIu1zOwNVQl+h4ZQJxvAV/rtJW5HzM8FMCpXHfIzZVX WWdhwSOi8CcGHFD4pvZgcqQH6MaQx4gVhsNsVunDicjqZHhEHiz0ZLYEH7l7cK2MJlnH zR6ehqjLoecSj/Kqxbuqv36LJW8RmENI3lcHeIpu13z0t4bYtOOHnElmYnW2AWCw0ud5 NzPchRJnnw0c9EbC7vo6XwrEdMb1Vs61l0PZ9h5Z0ReOFO28/hjFsqXBtMr99F/WT0/6 RyoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tjn5cOhPCJTjLCzK5W9G1YBEVUEJ+0rPrDGESwiPuzc=; b=voKZKcOINtsSoY79sa1s6420bfjel1S+v4jy1n2UHVPoKxa0FqxmXj/AJJKiC9PirR StCq3boR9ST9Op/yvjGBfFVWfa/9ZyC//RI7Umhq89DyhekfgIvgG+lpXnAzARune+z/ kc8inpG4COYVInBIp41MR9ZOQw5+AjTDQRCBa5ulJkr3mOgYaBqnaGgC1vm4TwMp51mF /z1RwfJQgmtYQWex9WccA3gK6x8p4tpNoGrPzAbhf4Kc3JUFZFYISdBhfR/zqznvE8g/ pni/lLlw+9T8GzYn+5PpFPZxulJSqnTxoRDYTm2qMuyY4CA64x9CZxUBgJyCPqS5nOzG 91yg== X-Gm-Message-State: AOAM532M2i0sobSPF81d1HK2AjUPIuPE2ykL5as9oating+Y4pOsrIm/ JDXh3laamuMbkXfz2G45SqikhquBpoZk/g== X-Google-Smtp-Source: ABdhPJw5cRdHzRZx9lTBuuKwc2V4JIXzSWocp2ibl1WRe0b2e2nweOStW9WpfmJBpS3lWWsSkfZ55w== X-Received: by 2002:a63:63c7:0:b0:3f5:faf8:c45e with SMTP id x190-20020a6363c7000000b003f5faf8c45emr15856429pgb.234.1653203136578; Sun, 22 May 2022 00:05:36 -0700 (PDT) Received: from localhost ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id l20-20020a170903005400b0015e8d4eb2b4sm2575828pla.254.2022.05.22.00.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 00:05:36 -0700 (PDT) Date: Sun, 22 May 2022 15:05:33 +0800 From: Muchun Song To: Roman Gushchin Cc: Andrew Morton , linux-mm@kvack.org, Dave Chinner , linux-kernel@vger.kernel.org, Kent Overstreet , Hillf Danton , Christophe JAILLET Subject: Re: [PATCH v3 1/6] mm: memcontrol: introduce mem_cgroup_ino() and mem_cgroup_get_from_ino() Message-ID: References: <20220509183820.573666-1-roman.gushchin@linux.dev> <20220509183820.573666-2-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220509183820.573666-2-roman.gushchin@linux.dev> Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=6ErhHO7d; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BFA071C0026 X-Stat-Signature: r7etwwdnhpf4haiqd1zh5met6yzceg6u X-HE-Tag: 1653203126-995520 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 Mon, May 09, 2022 at 11:38:15AM -0700, Roman Gushchin wrote: > Shrinker debugfs requires a way to represent memory cgroups without > using full paths, both for displaying information and getting input > from a user. > > Cgroup inode number is a perfect way, already used by bpf. > > This commit adds a couple of helper functions which will be used > to handle memcg-aware shrinkers. > > Signed-off-by: Roman Gushchin > --- > include/linux/memcontrol.h | 21 +++++++++++++++++++++ > mm/memcontrol.c | 23 +++++++++++++++++++++++ > 2 files changed, 44 insertions(+) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index fe580cb96683..a6de9e5c1549 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -831,6 +831,15 @@ static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) > } > struct mem_cgroup *mem_cgroup_from_id(unsigned short id); > > +#ifdef CONFIG_SHRINKER_DEBUG > +static inline unsigned long mem_cgroup_ino(struct mem_cgroup *memcg) > +{ > + return memcg ? cgroup_ino(memcg->css.cgroup) : 0; > +} > + > +struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino); > +#endif > + > static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) > { > return mem_cgroup_from_css(seq_css(m)); > @@ -1324,6 +1333,18 @@ static inline struct mem_cgroup *mem_cgroup_from_id(unsigned short id) > return NULL; > } > > +#ifdef CONFIG_SHRINKER_DEBUG > +static inline unsigned long mem_cgroup_ino(struct mem_cgroup *memcg) > +{ > + return 0; > +} > + > +static inline struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) > +{ > + return NULL; > +} > +#endif > + > static inline struct mem_cgroup *mem_cgroup_from_seq(struct seq_file *m) > { > return NULL; > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 04cea4fa362a..e6472728fa66 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5018,6 +5018,29 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id) > return idr_find(&mem_cgroup_idr, id); > } > > +#ifdef CONFIG_SHRINKER_DEBUG > +struct mem_cgroup *mem_cgroup_get_from_ino(unsigned long ino) > +{ > + struct cgroup *cgrp; > + struct cgroup_subsys_state *css; > + struct mem_cgroup *memcg; > + > + cgrp = cgroup_get_from_id(ino); > + if (!cgrp) > + return ERR_PTR(-ENOENT); > + > + css = cgroup_get_e_css(cgrp, &memory_cgrp_subsys); > + if (css) > + memcg = container_of(css, struct mem_cgroup, css); > + else > + memcg = ERR_PTR(-ENOENT); > + > + cgroup_put(cgrp); I think it's better to use css_put() here since the refcount is get via cgroup_get_e_css() which returns a css struct. Thanks. > + > + return memcg; > +} > +#endif > + > static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) > { > struct mem_cgroup_per_node *pn; > -- > 2.35.3 > >