From patchwork Tue Nov 10 03:10:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11892995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F12B214C0 for ; Tue, 10 Nov 2020 03:10:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7E9E32065E for ; Tue, 10 Nov 2020 03:10:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="R9EijyKW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E9E32065E 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 722066B005C; Mon, 9 Nov 2020 22:10:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6D1ED6B005D; Mon, 9 Nov 2020 22:10:35 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 525156B006C; Mon, 9 Nov 2020 22:10:35 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 1FA596B005C for ; Mon, 9 Nov 2020 22:10:35 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C118D1EE6 for ; Tue, 10 Nov 2020 03:10:34 +0000 (UTC) X-FDA: 77467030788.21.rest14_3f08ee5272f1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id A4EEA180442C0 for ; Tue, 10 Nov 2020 03:10:34 +0000 (UTC) X-Spam-Summary: 1,0,0,a048c46b53ed3e2f,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1437:1515:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2895:3138:3139:3140:3141:3142:3352:3865:3866:3867:3871:3872:4385:5007:6261:6653:6737:7875:8603:10004:11026:11473:11658:11914:12048:12296:12297:12438:12517:12519:12555:12679:12895:13069:13161:13229:13311:13357:13894:14093:14096:14181:14384:14394:14721:21080:21444:21451:21627:21740:30054:30064:30070,0,RBL:209.85.215.194:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yfmwjurnd7tnqgcdqarhq4r9k4nocdr1qf13ts5cfxs9axnkwne893reufayn.iyej9mnqw3ktrnruzywh1puc6sxoz6d6kugzm5xicfpi8n8uc9415mihpaabxi8.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:69,LUA_SUMMARY:none X-HE-Tag: rest14_3f08ee5272f1 X-Filterd-Recvd-Size: 4485 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 03:10:33 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id i26so8920858pgl.5 for ; Mon, 09 Nov 2020 19:10:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KlEMtRRnho5R/oyJ91jqGRJUyzsYfbjHE3I8y8AmGbY=; b=R9EijyKWLRbgDkV06Ti/5mY8HOQ6susqJloDOVCXIqcYpJ5pb7SPWMpqTcgVWIVS5r UiWNh/k9/+E8/5FvOJc5/z01kkQXtzYtvo34o/4wSuS14FkmgIttf4P8P51S7wPytvTS 5B66HUz6Mu3iZsXyOCgw3HOm4eH0CCd4a6HCYOPQim/YG48Q9J2GvppV+acfVBsj2I+n qEn/5duGPZYda8iUehkSKlqVH8gb6oxgUD0TIuYpwuflNL+sFFjEq8RYaStSNbgWxyWf Rfb8TgiWxwR4PAcKDy7UXYv2O0tWoo2fhiZMf9o29JfklOxBeWfqWY/mi6EqSdgIBNWZ nvTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KlEMtRRnho5R/oyJ91jqGRJUyzsYfbjHE3I8y8AmGbY=; b=dld5zsof4aEM0qM5MmybHC9WUkzzO5vO0HdhRPnf3YPDdQv/+MX904dTVTynWrpO3O gCJpq74HvmfkJwS6xPhCZ1mW5OV1fBYUNtNO9Huv9YQlMjlJoCgTG9VvhVY7ihFi0icJ 5pxZNI6D1X/8pwxRaQfPLM/xCyOF787Y7NHD8s+AtLFPvj46ok0Ep2SBhXTRJO8FiCmz OrM+7Si01dnHZLBZiMOhHfWX7KNOT9xTU0t+04VKnjU02WkhGzkC2lqTClywnTMr7TDu qRzXFl3ef1s29i1kIuru10tj/9xFho9YbvxOwdpUK9IIJ0CgiKbv0jw5YDddA/gkp8lq DMtA== X-Gm-Message-State: AOAM533uojgHjCkehfCl/3pjcXqmH7kG2jD5eG0VTD7GVFmtbTDdS4ob Xo7wsSmXRTfc7/uXzzYhFpda/V+5N11SOh6YgtU= X-Google-Smtp-Source: ABdhPJzMwdYeC7bP7dbpCG3uH9hlZ//GTpy7Fpt+Z4ZQZ5rEo1kP/4pXtYH8kMPqENENg+OpZFmrWA== X-Received: by 2002:a17:90a:80c6:: with SMTP id k6mr2547448pjw.73.1604977832879; Mon, 09 Nov 2020 19:10:32 -0800 (PST) Received: from Smcdef-MBP.local.net ([61.120.150.78]) by smtp.gmail.com with ESMTPSA id i11sm12116305pfd.211.2020.11.09.19.10.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2020 19:10:32 -0800 (PST) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, shakeelb@google.com, guro@fb.com, vbabka@suse.cz, laoar.shao@gmail.com, songmuchun@bytedance.com, chris@chrisdown.name Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] mm: memcg/slab: Fix root memcg vmstats Date: Tue, 10 Nov 2020 11:10:15 +0800 Message-Id: <20201110031015.15715-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.001378, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt Acked-by: Johannes Weiner Acked-by: David Rientjes --- v1->v2: - Just resend the patch. mm/memcontrol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2dde734df7d1..bbd40c5af61e 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);