Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2228841pxb; Tue, 23 Feb 2021 01:36:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3Ie/oGqRo5ztcKSSsZR9cYVBwIGsVOwDnpkNZ0wR9pK69tqUmPxWtOVWCr2PnwasPtcAx X-Received: by 2002:a17:906:f891:: with SMTP id lg17mr20177164ejb.369.1614073013357; Tue, 23 Feb 2021 01:36:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614073013; cv=none; d=google.com; s=arc-20160816; b=h+GQ071jnoimAYVzFjF/a9Ne3ADDAyPevp6VyeLnAcs08EARuRzJ2caeMDSbRoGpzf cs8GbbSMNTYtsJ+kCiUNxRNYePUFEs76lfltO6+Acrxs9dakNHw5XC5uf8KSqmTcVurs WXBevkE32SVoBwOqwPskLWcNZNji4pBWewPFhxUsvwCmkpippsGjjzKTeBAHgYilfJQ2 zAVCOWOBa7eWPR9tvN0iWlM4gEsgXH66gnSS7P24ju10QpBFIlLcovvAgUxFOUHFOFaf 9+A7tdvSTkNvfOlyR4GN+sADjWooPSXiLl4m6V+N06LOmtgliJmPU9JDmnBkTu/0qWji bCSg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=mu2c4DZ3wSvp2hWIYY8iGN/5x9vHcWAfw9ARv3kyqaM=; b=kptiShe4r5aR6Xymu/pz8O63cJLORPXj5FZ9e9hIp0TR6ArPLSuQ9plK59FBVZyEUB Sa3SN2nTmIVD0DPQXost3JV0KbMHC+7eHfKS0l9XcTVf49DGUZib7K4ViLD94WbXG6Ig DI2CbofB5Th6dcYx2Uq3+YCjL/I3lpHMlgoKmlMCTOYHL+RFX1vM2ttgsH2gp1Jg7o9G Gp3Kz+j4y5w6DY8x5GYtckPwIsLCb1833raRHsxm4n30VcNkE5G0X0HyBMXTgknBV9QE XViSVhv/RWrsW8HyMYcNII8gOpbXxmlNBbxYRxde30+yJXZSPYy0GHm3fEzHYIZdTR/+ LovQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=LO30HGhJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i20si13086116ejb.131.2021.02.23.01.36.27; Tue, 23 Feb 2021 01:36:53 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=LO30HGhJ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbhBWJ1D (ORCPT + 99 others); Tue, 23 Feb 2021 04:27:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbhBWJ0g (ORCPT ); Tue, 23 Feb 2021 04:26:36 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82310C061786 for ; Tue, 23 Feb 2021 01:25:56 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id h4so110617pgf.13 for ; Tue, 23 Feb 2021 01:25:56 -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=mu2c4DZ3wSvp2hWIYY8iGN/5x9vHcWAfw9ARv3kyqaM=; b=LO30HGhJEEoDclp09pG3Zhuhe4o587oo39dmuNomrLg61H6NzuMkL0xL1vBoOKFkuy s5wFOFudC2zzK0/9HCBgmyHk5dt3QNNyE0FvMB/0LHRZjtr3OfC/Jda4G713nBDXbkUw DsvahiAtdD1q5HImPQ1tnNyvxxDLAp8akFgugDk60PJQJGTk185uuHOcXRA4aZBl2gDS hMOS3C/AZ20hOPMt7eW25LMJz7bQNwRsbBIeLbNVU7Ct3lFZ1nK7RpS847vlMYKXsgTd 8L0GHFjCVFxsl4ObqTHMsj1/xeCdD5wC1ADe1TFzPuwQvd5lHI3iYz0HRPZIOOWXpq5K i2rA== 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=mu2c4DZ3wSvp2hWIYY8iGN/5x9vHcWAfw9ARv3kyqaM=; b=tiDTvksn6viGS7t1/+dZ2Vkm/mu0eEbetwn5hNTmAaAzh7+Kg9pAG5OxbjPgzIxuBS 0OSwNbLw0Okbyx3QduvhxH51c+yC4uZ0XnAdgu2Sk/9S2Fk0EGPNLe4iwT+KFYGNNX1S KENDUjgaYs/VhlB9dE2Pfj+o0sEMoRC4AvqsLNa01ENliLvgPCVRw5D+DwG4FVU3zQ7U ZZ4a/0/FiyvCFqu4zrQmR6cbL4n3YndM3CSxmFypz71+V4202RdLYc1ShOhNPZj0x5nP nzlozWKKbShr974gqlhQFMTZU8BwRBQMIkwuCbFRRhwFHQqfdpqn2y0RdlvcKV+jp0q/ mPag== X-Gm-Message-State: AOAM530V6tU0u2yDRyObbf0W/83NW77xh+GB7X5reAio+CKwny3YB8tq Ppt5EYPrEBtsbauKj8PlKmFZqw== X-Received: by 2002:a62:ae05:0:b029:1ed:9384:3e6f with SMTP id q5-20020a62ae050000b02901ed93843e6fmr10898262pff.44.1614072355999; Tue, 23 Feb 2021 01:25:55 -0800 (PST) Received: from localhost.localdomain ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id iq6sm2397154pjb.6.2021.02.23.01.25.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Feb 2021 01:25:55 -0800 (PST) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, guro@fb.com, shakeelb@google.com Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH] mm: memcontrol: fix slub memory accounting Date: Tue, 23 Feb 2021 17:24:23 +0800 Message-Id: <20210223092423.42420-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SLUB currently account kmalloc() and kmalloc_node() allocations larger than order-1 page per-node. But it forget to update the per-memcg vmstats. So it can lead to inaccurate statistics of "slab_unreclaimable" which is from memory.stat. Fix it by using mod_lruvec_page_state instead of mod_node_page_state. Fixes: 6a486c0ad4dc ("mm, sl[ou]b: improve memory accounting") Signed-off-by: Muchun Song --- mm/slab_common.c | 4 ++-- mm/slub.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 821f657d38b5..20ffb2b37058 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -906,8 +906,8 @@ void *kmalloc_order(size_t size, gfp_t flags, unsigned int order) page = alloc_pages(flags, order); if (likely(page)) { ret = page_address(page); - mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE_B, - PAGE_SIZE << order); + mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, + PAGE_SIZE << order); } ret = kasan_kmalloc_large(ret, size, flags); /* As ret might get tagged, call kmemleak hook after KASAN. */ diff --git a/mm/slub.c b/mm/slub.c index e564008c2329..f2f953de456e 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4057,8 +4057,8 @@ static void *kmalloc_large_node(size_t size, gfp_t flags, int node) page = alloc_pages_node(node, flags, order); if (page) { ptr = page_address(page); - mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE_B, - PAGE_SIZE << order); + mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, + PAGE_SIZE << order); } return kmalloc_large_node_hook(ptr, size, flags); @@ -4193,8 +4193,8 @@ void kfree(const void *x) BUG_ON(!PageCompound(page)); kfree_hook(object); - mod_node_page_state(page_pgdat(page), NR_SLAB_UNRECLAIMABLE_B, - -(PAGE_SIZE << order)); + mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, + -(PAGE_SIZE << order)); __free_pages(page, order); return; } -- 2.11.0