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=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 6F644C388F9 for ; Wed, 28 Oct 2020 02:57:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AF9D42242B for ; Wed, 28 Oct 2020 02:57:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="Wzk2Avte" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF9D42242B 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 BC9826B005C; Tue, 27 Oct 2020 22:56:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B52D26B005D; Tue, 27 Oct 2020 22:56:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1A866B0062; Tue, 27 Oct 2020 22:56:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 723DA6B005C for ; Tue, 27 Oct 2020 22:56:59 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 032013629 for ; Wed, 28 Oct 2020 02:56:59 +0000 (UTC) X-FDA: 77419822158.06.spark98_10025a727281 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id D842810041660 for ; Wed, 28 Oct 2020 02:56:58 +0000 (UTC) X-HE-Tag: spark98_10025a727281 X-Filterd-Recvd-Size: 5745 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 28 Oct 2020 02:56:58 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id t22so1773478plr.9 for ; Tue, 27 Oct 2020 19:56:57 -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=haZrmfpmntdtUu2HCrdM+P5anuz4VVrL1riml318t4Y=; b=Wzk2Avtec2wOG385ie+/41UyVjBLOdjL67AfpTMKR1mWo6L8Zr7gbQPfRXt0daWbLj 9eIB3qmpCLwzx260I5fxzOXhphezCgWwHOKXei6mqi7QJCLgPp1CjDceRVH/VQ+T04tP Zp86Sl6fFQHrllc1YWvLf5gS7HNMYxqKEt2BklLyD5IESzi12hAxi4Mx5L6ZjoARRl5z sPqXr9IRoISiz3eC5SCMsbpQn7okBqOVhaov6DVO+UGsl3Q+x8qCxRofoIlNWcwpekWD /4ri1aA6jajwfQ1lbm6ANjSbkWqAQC6vPpi5cTlU0sW9mFfnbh9Fj6+s+Gm3xin24haD uMYw== 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=haZrmfpmntdtUu2HCrdM+P5anuz4VVrL1riml318t4Y=; b=ZpcXLAUNI9hm6laICNscirsJRj167sxQ8zrn5LFQ3WYolI8zyfOkKuWm1HRjR08sXl VY/YYQf7dLXjPeI2y3F/rw4C0FQ4ftut7Bva59GfVJ/l/sHXAGNx3Vxqy6FjY9Z9lahx Nj+8s8lu5VgOsgHpVy89XV3KMxc8ppX1xTev7+frxbSwIyFCI2r1PLdIS5FyLWF2aP82 Wm8pgM6AwftqyIG/KKsnMAxdO146Jv0vvbzn6j+ClKfMCrQy9n4u7nnJ09GKK1zlZ9dI tMTYFwwyNm4zlXhAVXlyfsdGFTyyQG1zrXX9driWE1JQBGC5QRMjVgqO7nGtHzYevWJZ B8Tw== X-Gm-Message-State: AOAM532Z8yQlCp1/Wdivk65KHiNbs3177M5IICT9XDzMwB3CWq0l01t2 GU+vwOpfFlV8Nx1gCpyciOlR7ckqD7P5hXW91vZ9Ag== X-Google-Smtp-Source: ABdhPJxJ9lMlqruIazh/zmZBtfs/xi9mwEd63/HHgyDcIyU0v+lL5EPTcLvnSae+vVd+E1dNAvJuDTLaKiW21MT/xdI= X-Received: by 2002:a17:90a:890f:: with SMTP id u15mr4764490pjn.147.1603853816824; Tue, 27 Oct 2020 19:56:56 -0700 (PDT) MIME-Version: 1.0 References: <20201027080256.76497-1-songmuchun@bytedance.com> <20201027080256.76497-5-songmuchun@bytedance.com> <20201027184835.GB827280@carbon.dhcp.thefacebook.com> In-Reply-To: <20201027184835.GB827280@carbon.dhcp.thefacebook.com> From: Muchun Song Date: Wed, 28 Oct 2020 10:56:20 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 4/5] mm: memcg/slab: Fix root memcg vmstats To: Roman Gushchin Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Shakeel Butt , Joonsoo Kim , laoar.shao@gmail.com, Chris Down , Christian Brauner , Peter Zijlstra , Ingo Molnar , Kees Cook , Thomas Gleixner , esyr@redhat.com, Suren Baghdasaryan , areber@redhat.com, Marco Elver , LKML , Cgroups , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" 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 Wed, Oct 28, 2020 at 2:48 AM Roman Gushchin wrote: > > On Tue, Oct 27, 2020 at 04:02:55PM +0800, Muchun Song wrote: > > If we reparent the slab objects to the root memcg, when we free > > the slab object, we need to update the per-memcg vmstats to keep > > it correct for the root memcg. Now this at least affects the vmstat > > of NR_KERNEL_STACK_KB for !CONFIG_VMAP_STACK when the thread stack > > size is smaller than the PAGE_SIZE. > > > > Fixes: ec9f02384f60 ("mm: workingset: fix vmstat counters for shadow nodes") > > Signed-off-by: Muchun Song > > Can you, please, drop this patch for now? > > I'm working on a bigger cleanup related to the handling of the root memory > cgroup (I sent a link earlier in this thread), which already does a similar change. > There are several issues like this one, so it will be nice to fix them all at once. I have read the patch of https://lkml.org/lkml/2020/10/14/869. You mean this patch fixes this issue? It chooses to uncharge the root memcg. But here we may need to uncharge the root memcg to keep root vmstats correct. If we do not do this, we can see the wrong vmstats via root memory.stat(e.g. NR_KERNEL_STACK_KB). Thanks. > > Thank you! > > > --- > > mm/memcontrol.c | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index 22b4fb941b54..70345b15b150 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -875,8 +875,13 @@ void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val) > > rcu_read_lock(); > > memcg = mem_cgroup_from_obj(p); > > > > - /* Untracked pages have no memcg, no lruvec. Update only the node */ > > - if (!memcg || memcg == root_mem_cgroup) { > > + /* > > + * Untracked pages have no memcg, no lruvec. Update only the > > + * node. If we reparent the slab objects to the root memcg, > > + * when we free the slab object, we need to update the per-memcg > > + * vmstats to keep it correct for the root memcg. > > + */ > > + if (!memcg) { > > __mod_node_page_state(pgdat, idx, val); > > } else { > > lruvec = mem_cgroup_lruvec(memcg, pgdat); > > -- > > 2.20.1 > > -- Yours, Muchun