From patchwork Thu Dec 3 03:11:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11947641 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 45719C83013 for ; Thu, 3 Dec 2020 03:14:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD60D2224F for ; Thu, 3 Dec 2020 03:13:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD60D2224F 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 32FDD6B0068; Wed, 2 Dec 2020 22:13:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DEAB6B006C; Wed, 2 Dec 2020 22:13:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F59B6B006E; Wed, 2 Dec 2020 22:13:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 0B5FC6B0068 for ; Wed, 2 Dec 2020 22:13:59 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id CE04A362D for ; Thu, 3 Dec 2020 03:13:58 +0000 (UTC) X-FDA: 77550501756.21.verse70_5a036c2273b8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id AA7F2180442C3 for ; Thu, 3 Dec 2020 03:13:58 +0000 (UTC) X-HE-Tag: verse70_5a036c2273b8 X-Filterd-Recvd-Size: 5028 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Dec 2020 03:13:58 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id m5so308351pjv.5 for ; Wed, 02 Dec 2020 19:13:57 -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=rwVqmku+KuF7CBDwCXmp7GQf251F6L0Ar739gqzf9cU=; b=tITewJgNthn6PxKyqtA6y7Hsga8qG37N3FDSi29gWHRtvQG+yNxwFH68T9T2/XjU2d McUpVdjLgYPQlC7j8HhQPXZO+rMwHmoB1qk4zk1HY/jZ92ViyXbppXXZsVTD8iN8M8Av TPbPm1yTQzGCsDMl7nhuEzLoA0QSHzG+aqEYuvfqcJ/7hAouPj31QXTnaVm4ZVCEB1hy WGBtEaiDvKXSp9rE0YOCwfzz5B4NsC8gRkvzGjKJZx9QyHNyuspmL6hPsDRI1+P5oYzd kEC1TPjDhslQHfF862x4i6EA/EofAGpWNJlm9oyLEjfSng0F8LXkHEddvJadX359XlfS 20Aw== 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=rwVqmku+KuF7CBDwCXmp7GQf251F6L0Ar739gqzf9cU=; b=IcypZlp0tXbAhUxcVPwvEmoL/IDOFCGzkVvTt0Ra6E4EXxzgzHlyk64VN27pVauUBN uH+OTaDzvFRLwvPabok38G/6kDLCG76VQRJMCiWpva0uR8KhERlTF6c8sIZiM/fgZ+yc FXR6PHbCZpAGLYa6WSP55nfvGPRZHD4BW/fDXGj+hpJ0XTM7MPgKLgQeP9aXCs0jGaYB nmN5KbG60XdzWMmwjUeswbBilgm7zWroIVFMW/4h3vr7ap07HRCNDdyMLtTOXUKpByDv WZMitIU4FvGYbTuurV+9WMKI/jbmDd04CL4Ee4CWcpuA/thxQ3hZk1VHCNsC6cTD7OR3 +BXw== X-Gm-Message-State: AOAM533IhxUnN9M6Mg66G8qxogANTs3en0ViFcJ9zDXL3PgI6eVgx2at EyBy28gTtlCUwP0VBDOHLl6Rkw== X-Google-Smtp-Source: ABdhPJzl03ea3XSeGXYOVgpi8aLf35MXOyZs4Z9pSvj8lIUn7ZAIrJEQm2Si9i8tcFkT/yKaS0jxEQ== X-Received: by 2002:a17:90a:4093:: with SMTP id l19mr1073959pjg.218.1606965236823; Wed, 02 Dec 2020 19:13:56 -0800 (PST) Received: from localhost.localdomain ([103.136.220.95]) by smtp.gmail.com with ESMTPSA id f17sm418336pfk.70.2020.12.02.19.13.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Dec 2020 19:13:56 -0800 (PST) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Roman Gushchin Subject: [PATCH v2] mm/memcontrol: make the slab calculation consistent Date: Thu, 3 Dec 2020 11:11:11 +0800 Message-Id: <20201203031111.3187-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.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Although the ratio of the slab is one, we also should read the ratio from the related memory_stats instead of hard-coding. And the local variable of size is already the value of slab_unreclaimable. So we do not need to read again. Simplify the code here. Signed-off-by: Muchun Song Acked-by: Roman Gushchin --- Changes in v2: - Add a comment in the memory_stat_format() suggested by Roman. mm/memcontrol.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9922f1510956..75df129b7a52 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1545,12 +1545,22 @@ static int __init memory_stats_init(void) int i; for (i = 0; i < ARRAY_SIZE(memory_stats); i++) { + switch (memory_stats[i].idx) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE - if (memory_stats[i].idx == NR_ANON_THPS || - memory_stats[i].idx == NR_FILE_THPS || - memory_stats[i].idx == NR_SHMEM_THPS) + case NR_ANON_THPS: + case NR_FILE_THPS: + case NR_SHMEM_THPS: memory_stats[i].ratio = HPAGE_PMD_SIZE; + break; #endif + case NR_SLAB_UNRECLAIMABLE_B: + VM_BUG_ON(i < 1); + VM_BUG_ON(memory_stats[i - 1].idx != NR_SLAB_RECLAIMABLE_B); + break; + default: + break; + } + VM_BUG_ON(!memory_stats[i].ratio); VM_BUG_ON(memory_stats[i].idx >= MEMCG_NR_STAT); } @@ -1586,9 +1596,15 @@ static char *memory_stat_format(struct mem_cgroup *memcg) size *= memory_stats[i].ratio; seq_buf_printf(&s, "%s %llu\n", memory_stats[i].name, size); + /* + * We are printing reclaimable, unreclaimable of the slab + * and the sum of both. + */ if (unlikely(memory_stats[i].idx == NR_SLAB_UNRECLAIMABLE_B)) { - size = memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) + - memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B); + int idx = i - 1; + + size += memcg_page_state(memcg, memory_stats[idx].idx) * + memory_stats[idx].ratio; seq_buf_printf(&s, "slab %llu\n", size); } }