Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp173319pxf; Thu, 11 Mar 2021 00:39:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxl9pXe5+1E5bByAYzLEsjcb4vtgH9el85m4TjQpfxhWRURVKx51FRbtoZOQFKPFM9ABy2g X-Received: by 2002:a17:906:af97:: with SMTP id mj23mr2049946ejb.419.1615451950722; Thu, 11 Mar 2021 00:39:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615451950; cv=none; d=google.com; s=arc-20160816; b=UuyQSD/K05UbI5yZu6aMYh92KCjNJPluGgw4qugpOlAHiJmBj5wjuBmvkr6Z+zXvHb e8gIlTXos48qhqAhSkr7oEHQl9owj7pMrf978MkTWK45UPyGNnTdEeymsydx/K1GTeUZ M9db8MGCOeixXSBUr7L8UEpzJNRnjotqLBBOV4znt7pfyU1WtkHi0qCcwqrltFPuNjjp CbZ+AewbFxK0WUVxCAL98JNsJbBQu3ZNzuzwWxhXerZuPJ2cIZI+kAorFf8QcOF6Ckb+ fl7wUbKBZ48ie/CystLxA9nw/xBWPn+8OnDIJwMliAxuCqsZJGFiLeKVA6i4lPQlXDB0 q56A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=aT+IcvZ/LIbE+g8vm51cCvXAltMkbBPr5mv3CdiYJpY=; b=mYz2h6OIyNfLg9hPtE0fL5q/FZcBAuEbBfVLyWFxSsoz0A9FEAqRK51AE+VRO9kzlX D335BltuJlpZSAiawgUDvMNCB/fj3jKjgExpUJFpU8rgimbv3SV67CY/yJ8LhVNycAi1 J41AOJh+zsrRRUApong24YGz+ulrTee7M4X6lMMM6iu0RwoMsXXUMB51QRXIqsavl2B2 LMcL4pj+XrbHhjvTkLPsda3YmJsDFy5uucvd+kHvDZt2nBqZlqHMGwDD0yqIK+GDgG5R tURBReQ13ra1o1p0wUUSmsLMlVbytr9dZpj2pHRAaejvMs6lgH2qyy9L3XYotrpjZQQb qO7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=metQ+sXs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c10si1339344edv.12.2021.03.11.00.38.40; Thu, 11 Mar 2021 00:39:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=metQ+sXs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbhCKIh3 (ORCPT + 99 others); Thu, 11 Mar 2021 03:37:29 -0500 Received: from mx2.suse.de ([195.135.220.15]:46370 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231356AbhCKIhE (ORCPT ); Thu, 11 Mar 2021 03:37:04 -0500 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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