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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 A5971C433E0 for ; Thu, 11 Mar 2021 08:37:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0B4FB64F92 for ; Thu, 11 Mar 2021 08:37:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B4FB64F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E9C18D028C; Thu, 11 Mar 2021 03:37:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BFF38D0250; Thu, 11 Mar 2021 03:37:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 665AE8D028C; Thu, 11 Mar 2021 03:37:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0176.hostedemail.com [216.40.44.176]) by kanga.kvack.org (Postfix) with ESMTP id 4A4F38D0250 for ; Thu, 11 Mar 2021 03:37:05 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0785B180ACEEC for ; Thu, 11 Mar 2021 08:37:05 +0000 (UTC) X-FDA: 77906938410.03.F409489 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf18.hostedemail.com (Postfix) with ESMTP id 53EF92000390 for ; Thu, 11 Mar 2021 08:37:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615451823; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aT+IcvZ/LIbE+g8vm51cCvXAltMkbBPr5mv3CdiYJpY=; b=metQ+sXsqkfPUsi0vxW4cXWnvH5IzNBUvri643f3eYB3j4sCfZip6wmXkbo7Fgot30YYmk TWaFLtIMBxNjzvgX5tOdQhIL+AjBgRTC2Dzd/c1eqviaEP6zTOwDy1Btb/ie24qSoR8teR Dvtk+9VF2UTz5004GRcz5cI9QSHnHfc= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 456CEAC17; Thu, 11 Mar 2021 08:37:03 +0000 (UTC) Date: Thu, 11 Mar 2021 09:37:02 +0100 From: Michal Hocko To: Matthew Wilcox Cc: Zhou Guanghui , linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, hannes@cmpxchg.org, hughd@google.com, kirill.shutemov@linux.intel.com, npiggin@gmail.com, ziy@nvidia.com, wangkefeng.wang@huawei.com, guohanjun@huawei.com, dingtianhong@huawei.com, chenweilong@huawei.com, rui.xiang@huawei.com Subject: Re: [PATCH v2 2/2] mm/memcg: set memcg when split page Message-ID: References: <20210304074053.65527-1-zhouguanghui1@huawei.com> <20210304074053.65527-3-zhouguanghui1@huawei.com> <20210308210225.GF3479805@casper.infradead.org> <20210309123255.GI3479805@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 53EF92000390 X-Stat-Signature: jxodqkepb6jw9jg3u1jac4qqz667h1ks Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf18; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615451825-436232 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: Johannes, Hugh, what do you think about this approach? If we want to stick with split_page approach then we need to update the missing place Matthew has pointed out. On Tue 09-03-21 14:03:36, Michal Hocko wrote: > On Tue 09-03-21 12:32:55, Matthew Wilcox wrote: > > On Tue, Mar 09, 2021 at 10:02:00AM +0100, Michal Hocko wrote: > [...] > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > index 913c2b9e5c72..d44dea2b8d22 100644 > > > --- a/mm/memcontrol.c > > > +++ b/mm/memcontrol.c > > > @@ -3135,8 +3135,21 @@ int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order) > > > if (memcg && !mem_cgroup_is_root(memcg)) { > > > ret = __memcg_kmem_charge(memcg, gfp, 1 << order); > > > if (!ret) { > > > + int nr_pages = 1 << order; > > > page->memcg_data = (unsigned long)memcg | > > > MEMCG_DATA_KMEM; > > > + > > > + /* > > > + * Compound pages are normally split or freed > > > + * via their head pages so memcg_data in in the > > > + * head page should be sufficient but there > > > + * are exceptions to the rule (see __free_pages). > > > + * Non compound pages would need to copy memcg anyway. > > > + */ > > > + for (i = 1; i < nr_pages; i++) { > > > + struct page * p = page + i; > > > + p->memcg_data = page->memcg_data > > > + } > > > return 0; > > > > I would condition this loop on if (!(gfp & __GFP_COMP)), but yes, something > > along these lines. I might phrase the comment a little differently ... > > > > /* > > * Compound pages are treated as a single unit, > > * but non-compound pages can be freed individually > > * so each page needs to have its memcg set to get > > * the accounting right. > > */ > > OK, I must have misunderstood your __free_pages fix then. I thought this > was about compound pages. Btw. again I forgot about css ref counting so > here is an updated version. > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 913c2b9e5c72..ec2c705f38fa 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3133,10 +3133,22 @@ int __memcg_kmem_charge_page(struct page *page, gfp_t gfp, int order) > > memcg = get_mem_cgroup_from_current(); > if (memcg && !mem_cgroup_is_root(memcg)) { > - ret = __memcg_kmem_charge(memcg, gfp, 1 << order); > + int nr_pages = 1 << order; > + ret = __memcg_kmem_charge(memcg, gfp, nr_pages); > if (!ret) { > page->memcg_data = (unsigned long)memcg | > MEMCG_DATA_KMEM; > + if (nr_pages > 1) { > + /* > + * comment goes here > + */ > + for (i = 1; i < nr_pages; i++) { > + struct page * p = page + i; > + p->memcg_data = page->memcg_data > + } > + /* Head page reference from get_mem_cgroup_from_current */ > + css_get_many(&memcg->css, nr_pages - 1); > + } > return 0; > } > css_put(&memcg->css); -- Michal Hocko SUSE Labs