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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 84614C433C1 for ; Fri, 19 Mar 2021 15:58:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C1326195F for ; Fri, 19 Mar 2021 15:58:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C1326195F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E35A8D0009; Fri, 19 Mar 2021 11:58:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5B18D0001; Fri, 19 Mar 2021 11:58:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683228D0009; Fri, 19 Mar 2021 11:58:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 4ED9E8D0001 for ; Fri, 19 Mar 2021 11:58:12 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 137B6824999B for ; Fri, 19 Mar 2021 15:58:12 +0000 (UTC) X-FDA: 77937080382.36.977037D Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf05.hostedemail.com (Postfix) with ESMTP id 32968E00D7CD for ; Fri, 19 Mar 2021 15:46:14 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id c204so6173207pfc.4 for ; Fri, 19 Mar 2021 08:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qONpO4rhVUGycYg/TRvqp7wSV44IcWoCAbGRlkLp9Ss=; b=rsTx4yyQbVw/axvuQK7riy8Ifnu/2vWnC+ipHqep+SkDFx7fxZGWhhFIMWg6OVsGvh zyNlDtgVGgHkwH5IoxwYKqzCkyRHUdMfK7fn06V6lsmUcm/3uPmOG7uUS6WGTQY4Bpd+ WJV95QM9bXIgKyO4PxDQ4oC70Y43ZD1kvIdn+ikhfcGsgmgnvOadj91qkGxxuBPkSuLp v9DDfvpBKUr59vQCL5eUeTcDYyoyeT+fkdbOqQbcb8w63Hi2ci3ZkY4AIHc1igWN+6xe u9wTH9JnZ+EG0R8z4Ipx3rkZWiRk14cIpBSwHMfI5jpTVXe2HUNcRQLcl6DI11g+OPu5 xD1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qONpO4rhVUGycYg/TRvqp7wSV44IcWoCAbGRlkLp9Ss=; b=CGJ9nU+9FxIxPnddWeFfgB9hFa+QxZapVawVdOXS7hnnDjqBNfGjVoNailIuvtYKcv +4aEfD+YKtxFarvrxLMtot21VMCS/VPxyw7eosS8xXaRKtmKP2ME8DeP2iUDVW+pmFG4 lBz9+n8rfXhzO7wrFGQ1BU70Z8gX7w8uud+6vCpFF7AiaxCo5HrlLpV0a0C7oTydtWwI zQt8j1R/BzPjzC5VwayiY7FhZ/DqFHb37RQJSBQOlcGBUdf/dkBdBFRPTfupnWRnkv7a W3TrFYFD4hQ2yFy7oxo1Ex+VnyI+qVHnv9KqTc6+z99vrk3X37ujStIK4Nyu6Zzopy5I m4HA== X-Gm-Message-State: AOAM532s08s16KlVKgyqNmR/S49Zz6nK1TtCWsHLlrDEookz7lJJEOfU lrUC9uNjN188wuKa1kJ+WMJWVmQ7Uh28/YbECngKjA== X-Google-Smtp-Source: ABdhPJwwUIg8Pn8ujsnmmyz5LCe4Dmjkxby7QcP4D6KPoSbz3fTxSqAdZ1HACiuD0mvkzCmd32zZlBml8RGzzzJ/9tA= X-Received: by 2002:a63:141e:: with SMTP id u30mr12262932pgl.31.1616168771346; Fri, 19 Mar 2021 08:46:11 -0700 (PDT) MIME-Version: 1.0 References: <20210318110658.60892-1-songmuchun@bytedance.com> <20210318110658.60892-5-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Fri, 19 Mar 2021 23:45:35 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v4 4/5] mm: memcontrol: use obj_cgroup APIs to charge kmem pages To: Shakeel Butt Cc: Roman Gushchin , Johannes Weiner , Michal Hocko , Andrew Morton , Vladimir Davydov , LKML , Linux MM , Xiongchun duan Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 32968E00D7CD X-Stat-Signature: 1s14t9sdfeguw6a3zyf4je6yfm1ynmz5 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=mail-pf1-f182.google.com; client-ip=209.85.210.182 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616168774-890603 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 Fri, Mar 19, 2021 at 9:59 PM Shakeel Butt wrote: > > On Thu, Mar 18, 2021 at 9:05 PM Muchun Song wrote: > > > > On Fri, Mar 19, 2021 at 11:40 AM Shakeel Butt wrote: > > > > > > On Thu, Mar 18, 2021 at 4:08 AM Muchun Song wrote: > > > > > > > [...] > > > > > > > > +static inline struct mem_cgroup *get_obj_cgroup_memcg(struct obj_cgroup *objcg) > > > > > > I would prefer get_mem_cgroup_from_objcg(). > > > > Inspired by obj_cgroup_memcg() which returns the memcg from objcg. > > So I introduce get_obj_cgroup_memcg() which obtains a reference of > > memcg on the basis of obj_cgroup_memcg(). > > > > So that the names are more consistent. Just my thought. > > > > So should I rename it to get_mem_cgroup_from_objcg? > > > > If you look at other functions which get reference on mem_cgroup, they > have the format of get_mem_cgroup_*. Similarly the current function to > get a reference on obj_cgroup is get_obj_cgroup_from_current(). > > So, from the name get_obj_cgroup_memcg(), it seems like we are getting > reference on obj_cgroup but the function is getting reference on > mem_cgroup. Make sense. I will use get_mem_cgroup_from_objcg(). Thanks. > > > > > > > > +{ > > > > + struct mem_cgroup *memcg; > > > > + > > > > + rcu_read_lock(); > > > > +retry: > > > > + memcg = obj_cgroup_memcg(objcg); > > > > + if (unlikely(!css_tryget(&memcg->css))) > > > > + goto retry; > > > > + rcu_read_unlock(); > > > > + > > > > + return memcg; > > > > +} > > > > + > > > > #ifdef CONFIG_MEMCG_KMEM > > > > int memcg_alloc_page_obj_cgroups(struct page *page, struct kmem_cache *s, > > > > gfp_t gfp, bool new_page) > > > > @@ -3070,15 +3088,8 @@ static int obj_cgroup_charge_pages(struct obj_cgroup *objcg, gfp_t gfp, > > > > struct mem_cgroup *memcg; > > > > int ret; > > > > > > > > - rcu_read_lock(); > > > > -retry: > > > > - memcg = obj_cgroup_memcg(objcg); > > > > - if (unlikely(!css_tryget(&memcg->css))) > > > > - goto retry; > > > > - rcu_read_unlock(); > > > > - > > > > + memcg = get_obj_cgroup_memcg(objcg); > > > > ret = __memcg_kmem_charge(memcg, gfp, nr_pages); > > > > > > Why not manually inline __memcg_kmem_charge() here? This is the only user. > > > > > > Similarly manually inline __memcg_kmem_uncharge() into > > > obj_cgroup_uncharge_pages() and call obj_cgroup_uncharge_pages() in > > > obj_cgroup_release(). > > > > Good point. I will do this. > > > > > > > > > - > > > > css_put(&memcg->css); > > > > > > > > return ret; > > > > @@ -3143,18 +3154,18 @@ static void __memcg_kmem_uncharge(struct mem_cgroup *memcg, unsigned int nr_page > > > > */ > > > > int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order) > > > > { > > > > - struct mem_cgroup *memcg; > > > > + struct obj_cgroup *objcg; > > > > int ret = 0; > > > > > > > > - memcg = get_mem_cgroup_from_current(); > > > > > > This was the only use of get_mem_cgroup_from_current(). Why not remove it? > > > > I saw a potential user. > > > > [PATCH v10 0/3] Charge loop device i/o to issuing cgroup > > > > To avoid reintroducing them. So I did not remove it. > > > > Don't worry about that. Most probably that user would be changing this > function, so it would to better to introduce from scratch. OK. I will remove get_mem_cgroup_from_current(). Thanks for your suggestions.