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 0E6EAC433EF for ; Tue, 24 May 2022 02:00:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63AA16B0072; Mon, 23 May 2022 22:00:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E9716B0073; Mon, 23 May 2022 22:00:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AB416B0074; Mon, 23 May 2022 22:00:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 388326B0072 for ; Mon, 23 May 2022 22:00:40 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0731334602 for ; Tue, 24 May 2022 02:00:40 +0000 (UTC) X-FDA: 79498982640.31.0495288 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf09.hostedemail.com (Postfix) with ESMTP id A3469140023 for ; Tue, 24 May 2022 02:00:25 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id b135so3463001pfb.12 for ; Mon, 23 May 2022 19:00: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=ks5fHZGz5K1moEIff4MSVWwvyiI+uYKrM7vKXg28rC0=; b=RuIliZvWTgzJRnlripHHDX+9nt0tRt6Z47armgptC9p5cIznXN3wsoEbwY4Hkm8DZx CpUbOaTMMt3sCq3O0k7/6ATXu7gn5Pvh8jSw4dehpmbHMojeJxmSUIu+L5CFVDowf4xx fYAGOlEM3P7pY8D//c3l8fuqIbK7TuZ7mXMIqnU5fA27Ak0p7r0YmGOzkq6IaF2L0SF4 3QU5OfF3vMUXMMdToNC5hJKuvY4M0j+exO01qpxAWWeRFeKK/KN4oltqFU1Rl60HNDmZ qOfgx+XkvEn6Huu65Yl0YUKdm8RhI4PHz9CoC4tSaKhr/u5ihuBavphenfGMiBgEBgQG nQFw== 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=ks5fHZGz5K1moEIff4MSVWwvyiI+uYKrM7vKXg28rC0=; b=Ei/eKsBuIFoodE8jUyqpSjXx8MX8bg0JoFEY7zTtpzs4mO5EBMyXDo9N/gxmcG6I5m HXCBBvlx8c/ejj0t2tQx223g1SPMdzPVCBbEucXH6ND/oSpEuXtenUmxoi4mBrPdilAe R4WMtEkNZsP5l62uedtlkrCLcWrbvznTY7SijiuP2R4j+/l3Q3/gHpGb4Bm4FhKfoivZ 7DTqv+RMo1yNIFBfyAeovhmge6J822i/EYkw/FB0MtXh9zEI3wvkwdvcyEfUMgRKCHgO rhuyS9lUz7KtuPLDKjAB6FI1GQdkGp/m2o7VsAhZJd48KdizR3Qf4l5378ekFoIrKmUr VcUg== X-Gm-Message-State: AOAM533x5ccUBMTBKc10yCBW/4uk07WtrKP3TyzkuEax2G+NrvMNQOBh Ak8dUnSTrmzHhYNd3YBvkEF7VQ== X-Google-Smtp-Source: ABdhPJytnwSaStOgTzWHURP9QGPnEoymAUGruoeUxElkd7F90wuj4W/hyTnpA0OJdKiPBtAw0J0jWA== X-Received: by 2002:a05:6a00:1a03:b0:510:a1d9:7de0 with SMTP id g3-20020a056a001a0300b00510a1d97de0mr25807224pfv.53.1653357632063; Mon, 23 May 2022 19:00:32 -0700 (PDT) Received: from localhost ([2408:8207:18da:2310:f940:af17:c2f5:8656]) by smtp.gmail.com with ESMTPSA id p18-20020a170902f09200b0015e8d4eb23bsm5767658pla.133.2022.05.23.19.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 19:00:31 -0700 (PDT) Date: Tue, 24 May 2022 10:00:26 +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: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A3469140023 X-Stat-Signature: tak8icea6yrieyh7xynyz88nsr4dumrt X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RuIliZvW; spf=pass (imf09.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1653357625-792804 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 23, 2022 at 11:12:12AM -0700, Roman Gushchin wrote: > On Sun, May 22, 2022 at 03:05:33PM +0800, Muchun Song wrote: > > 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. > > cgroup_put() is matching cgroup_get_from_id(). > > The reference grabbed by cgroup_get_e_css() shouldn't be dropped > because mem_cgroup_get_from_ino() has a "get" semantics. > My bad. I have misread it here. Thanks.