Received: by 2002:aa6:c429:0:b029:98:93ff:f56f with SMTP id g9csp3397608lkq; Mon, 23 Nov 2020 04:48:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWDBs0jY7HGO/2eFq6DL34OxmjWKkYa8R8N0z/HpWmKo7VxApJGMn1zKOqlN9C3V+aUZ7L X-Received: by 2002:a17:906:d931:: with SMTP id rn17mr43271010ejb.308.1606135704920; Mon, 23 Nov 2020 04:48:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606135704; cv=none; d=google.com; s=arc-20160816; b=0KvwYZAtjIExNEvJozMQkhhJ7+vhkZG/+y0Y7n+k7COlLoF7fx5Zrk/MKa4GbaCB4c Dsdbci5ibOnLMHtV2uMCD4r+c9fczoOeQrOc8vcfVH/pVLF8p5KPJVpIeuSdrTq8iUG2 FTPiD8g6sarIhyF+abX0lguXz9C1yvVMawHUDelj8WLrdxmhakqRLQee0UaSpvsANr1F VrlQPFzCdiETPgXskTJvLizmm2VRIHi4bKT52Hqn2Sadr80OP8SO4lWVMViNM9QFPWxM wxNscu8hvA2rwqZ9J0+tZXmrg+9+jx/PwSsgbetOUqWtlfjvw87b+CaisK+T2toivftP ZVRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m/DMhf1rfmisE0erj9iVfvGmQa/sha5+P4+p6X+mIBQ=; b=xCR5xMXga2GSM45NrNBP+e1SwwSyyQ4DlV9yD7nBY/5yORd3u6I+HcgcuTlE9xwuF4 4+vFOrxSiDgJP1AhoCeJRY8+AdgKkyZvIX1dwhGl/Ez1FLjagVGSwAIYmxtm4fU6aGC0 xlEGb6tgLy27+/JvoH25TPoDjIG89uKfT4jcmtmkkrAzVKqyVlJv1L9YxSINo+Oncm1f Fh3fzk+vw2EUBTz9TsC9/xQ4Nmra2rkotA1aKBEoSTtBXyXQuLArJdYVRux2VXJsCRnj yEuHrgMEs6CJgWpOjWQ9V5l7KdE4TCg2Zxue9AjasOj6wa+DmRjXyw+sMgSFti43RdX4 LyeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kmjITSNH; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nw19si6353372ejb.586.2020.11.23.04.48.01; Mon, 23 Nov 2020 04:48:24 -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=@linuxfoundation.org header.s=korg header.b=kmjITSNH; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733001AbgKWMm6 (ORCPT + 99 others); Mon, 23 Nov 2020 07:42:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:53844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732575AbgKWMk6 (ORCPT ); Mon, 23 Nov 2020 07:40:58 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 31C14208FE; Mon, 23 Nov 2020 12:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135258; bh=vcHKR/V4bgCOZFiB5PWRCL90ggMqMg4rXt+HijycRJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmjITSNH+dpzw2wj5ejS6SUb6BPnzu30BUUIK2j2T/n+rZwqb/MoB9uSiEmiD1nsm OYq/NX4+4d5RpKTJZ4tRPJtpT+sHWS9x/mseyemKd21GIJVSMu8DQWEmQlRmitCb/Z +7wGYAXM8ek83caSKINlM4aW04X2PxwRV0hggp7k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Muchun Song , Andrew Morton , Shakeel Butt , Roman Gushchin , Johannes Weiner , David Rientjes , Michal Hocko , Vladimir Davydov , Christopher Lameter , Pekka Enberg , Joonsoo Kim , Vlastimil Babka , Yafang Shao , Chris Down , Linus Torvalds Subject: [PATCH 5.4 155/158] mm: memcg/slab: fix root memcg vmstats Date: Mon, 23 Nov 2020 13:23:03 +0100 Message-Id: <20201123121827.411498013@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Muchun Song commit 8faeb1ffd79593c9cd8a2a80ecdda371e3b826cb upstream. 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. David said: "I assume that without this fix that the root memcg's vmstat would always be inflated if we reparented" Fixes: ec9f02384f60 ("mm: workingset: fix vmstat counters for shadow nodes") Signed-off-by: Muchun Song Signed-off-by: Andrew Morton Reviewed-by: Shakeel Butt Acked-by: Roman Gushchin Acked-by: Johannes Weiner Acked-by: David Rientjes Cc: Michal Hocko Cc: Vladimir Davydov Cc: Christopher Lameter Cc: Pekka Enberg Cc: Joonsoo Kim Cc: Roman Gushchin Cc: Vlastimil Babka Cc: Yafang Shao Cc: Chris Down Cc: [5.3+] Link: https://lkml.kernel.org/r/20201110031015.15715-1-songmuchun@bytedance.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -776,8 +776,13 @@ void __mod_lruvec_slab_state(void *p, en rcu_read_lock(); memcg = memcg_from_slab_page(page); - /* 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(pgdat, memcg);