From patchwork Wed Oct 18 00:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 13426215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A592CDB474 for ; Wed, 18 Oct 2023 00:55:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73F3A8D0128; Tue, 17 Oct 2023 20:55:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 715D48D011E; Tue, 17 Oct 2023 20:55:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DDD38D0128; Tue, 17 Oct 2023 20:55:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4F1338D011E for ; Tue, 17 Oct 2023 20:55:53 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 22BF740EA8 for ; Wed, 18 Oct 2023 00:55:53 +0000 (UTC) X-FDA: 81356764986.22.D6BAD1E Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 8B1F3A0022 for ; Wed, 18 Oct 2023 00:55:51 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TFuUaZuY; spf=pass (imf15.hostedemail.com: domain of 3Fi0vZQsKCF0NJPM5QK5I85BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--souravpanda.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Fi0vZQsKCF0NJPM5QK5I85BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--souravpanda.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697590551; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=RtN1cX7OnFY4c89ZOmsAINIHxJE4cdFfX8n5PNBpJGI=; b=y4i1LAFdEvNxO1vv0jhu5UJ9LPknVUedgTZSlEtG8gT1j6JkXIh4Cn0HNeLyfFtTzIh+FP 3Arw8vQFcEsMRfnAR6hKzQDmU0rxK8Sp9clwxyeDfsl5O8Fu7NhjFcU+CqOhVDms8jSURE GPK6s/Gsgo32bKR4IrC/Om+a/x1uVA4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=TFuUaZuY; spf=pass (imf15.hostedemail.com: domain of 3Fi0vZQsKCF0NJPM5QK5I85BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--souravpanda.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Fi0vZQsKCF0NJPM5QK5I85BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--souravpanda.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697590551; a=rsa-sha256; cv=none; b=Rr/dA2IakiQPwSLrLnDrT7D4POkT+q1LQir7vxDZKl5WA8BYezk/3fN6Jr3ndc+eRrpG+B Eq/pPJ7Kf2k4BckLnblwnNcPznkOBXccqxdtlQYa3M7wVGpsVPgdLl87wJc4SBFyvabvgA q2JlZjNzuERYdP1u4AQtoPX9FvQGPQg= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5a81cd8d267so75142117b3.1 for ; Tue, 17 Oct 2023 17:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697590550; x=1698195350; darn=kvack.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=RtN1cX7OnFY4c89ZOmsAINIHxJE4cdFfX8n5PNBpJGI=; b=TFuUaZuYGs9kDcMgqLJ+ll84iTsCCJ0yZoxoNOlV/S9/8JJMnbg67bz/WodsK5VDy5 q2A+C1nXMIIpCUmF5uxr6T3CTyk5c3wQJwtXGHlSRvVRkOHYq/iJ1PE+oUUgmuyC77Lc tPgZXStDdcfXkfcNRUREtP6YRKORj42/whsCRJY+reCENXc75JJbZvc8dyC6d7TPbiuP Bnc+a3k0gwTa1HR9U/+uudD35B038+J9isgLyGAWn75XLmTfO13/NJl6eDP7f6vXTZOm nKh7s8+UkpIODgneR48oRH5X5udB16K5TXSBhEgde4GRQng9o81YJnxkUBjK0skdblCL Z23A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697590550; x=1698195350; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RtN1cX7OnFY4c89ZOmsAINIHxJE4cdFfX8n5PNBpJGI=; b=Zc3K0x2+OzSkOiCSF5xfTBDM0Hi0692XXXHB2cwHrxKNkJ3lDBNfx12fS3qLysUg9W 9Kpr9nfnybLfsmlKfOcXqjv7YWtE5Yj4jWt2FI7HU4QZ+fRje2yf+7N/K8JABwU7BFwT 4QqLjL9D2p071WncB/fqJUb0shCAbyaBcyJ4ctF7PsRGUdA3h15PZf0mWPcdlhGDFF3B N6Gaucrpth4ckljhqqzVqEccbe0vbNUsxZeCfa71rBXwbfnMAGB0WtguKEcgc4JvqOs8 ZdSekrPvcDw/8LOXLs3Na9qS0xkcMfcf6r/m2kt1ZliMYxvqgcU3O/h1ZHU0tD4hMx2H p2jQ== X-Gm-Message-State: AOJu0YxxfuVePjRao9IZy3EKCVCvMdGpF4czo1dPGWaQ7QudkkSkX/iW gl8cr5HYF/oe9/rpa9OSFPnsuBEsbZM7cMESsg== X-Google-Smtp-Source: AGHT+IG3xQKinhI0hluOWrkIGk67L4r7161FfPWTDhQsiOFXX1Myf7Znfr216Md1QRT5RSFMskz/ufJkibAIW2xRaw== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:26ea:df99:e4a5:e557]) (user=souravpanda job=sendgmr) by 2002:a81:4f94:0:b0:5a7:b9b0:d23f with SMTP id d142-20020a814f94000000b005a7b9b0d23fmr80315ywb.6.1697590550545; Tue, 17 Oct 2023 17:55:50 -0700 (PDT) Date: Tue, 17 Oct 2023 17:55:47 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231018005548.3505662-1-souravpanda@google.com> Subject: [PATCH v2 0/1] mm: report per-page metadata information From: Sourav Panda To: corbet@lwn.net, gregkh@linuxfoundation.org, rafael@kernel.org, akpm@linux-foundation.org, mike.kravetz@oracle.com, muchun.song@linux.dev, rppt@kernel.org, david@redhat.com, rdunlap@infradead.org, chenlinxuan@uniontech.com, yang.yang29@zte.com.cn, souravpanda@google.com, tomas.mudrunka@gmail.com, bhelgaas@google.com, ivan@cloudflare.com, pasha.tatashin@soleen.com, yosryahmed@google.com, hannes@cmpxchg.org, shakeelb@google.com, kirill.shutemov@linux.intel.com, wangkefeng.wang@huawei.com, adobriyan@gmail.com, vbabka@suse.cz, Liam.Howlett@Oracle.com, surenb@google.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org X-Rspamd-Queue-Id: 8B1F3A0022 X-Rspam-User: X-Stat-Signature: 56cphxiog63xj13hgnz6xt3om8fts371 X-Rspamd-Server: rspam01 X-HE-Tag: 1697590551-352189 X-HE-Meta: U2FsdGVkX1/yZ09myPzliB4fe+VsPrXl/8H0X9OoliubEcI6xs8/yOo6S7cXka6xbe63Y0d8KMA3lI+4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EGNCeQbTA3zw8z+fw/xCrSE/5KLWjF8DVnpKET++TCNNOQsULSKEYXObhrP2+RLzWcBIIbxUW7bJAxs9G67hUjiZEt87Bq8MV6Epm1+iE6qmRyh9ux3Y3rEsvUAwpR+0OVeKvbZDa1KT1fIQEeWXj6+S74k3STfOVr7mxcRVP10EZalWGsQAbXazE2EbEvkVoI8XsitMOlO2AIyI/64ShMLxhFmMB5sRE/tASmNshQLgPavt/KMb0bBDErIZ+ff1HI9itXxFCyXAMP/tI60gNUpvlObj5Ugb6XsmIk1isPXeZS7kelmZ5D5UCDtzChE1pe/qPnNVoCYKecaUsC1QijlxQh2aTDCVQtDgYJaR28CqYfGkm9t4LuO8DMvPGNwGtWKiUwzw2IIHr5RwiHyNKv4wwyXG+z1U1bce7IIp97wON5GytAx4w/zO6EgVI/vdlRemtI0MBPWn7ethQrNLeo6e2Qb5gOhyfpdwkDT2ty7BXqtaDgumqXmtYLnlEfCQFYfKHk40j/kVRLjwu4SurWXiPzBx1RWlLt3tLhFHCuNTslj2lbdKvyXLP4YvglUjVNXSKlB+IbiFwRE6D6cSCwl24qFWkja8nWgutF+rQ== 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: Changelog: v2: - Fixed the three bugs reported by kernel test robot. - Enhanced the commit message as recommended by David Hildenbrand. - Addressed comments from Matthew Wilcox: - Simplified alloc_vmemmap_page_list() and free_page_ext() as recommended. - Used the appropriate comment style in mm/vmstat.c. - Replaced writeout_early_perpage_metadata() with store_early_perpage_metadata() to reduce ambiguity with what swap does. - Addressed comments from Mike Rapoport: - Simplified the loop in alloc_vmemmap_page_list(). - Could NOT address a comment to move store_early_perpage_metadata() near where nodes and page allocator are initialized. - Included the vmalloc()ed page_ext in accounting within free_page_ext(). - Made early_perpage_metadata[MAX_NUMNODES] static. Previous approaches and discussions ----------------------------------- v1: https://lore.kernel.org/r/20230913173000.4016218-2-souravpanda@google.com Hi! This patch adds a new per-node PageMetadata field to /sys/devices/system/node/nodeN/meminfo and a global PageMetadata field to /proc/meminfo. This information can be used by users to see how much memory is being used by per-page metadata, which can vary depending on build configuration, machine architecture, and system use. Per-page metadata is the amount of memory that Linux needs in order to manage memory at the page granularity. The majority of such memory is used by "struct page" and "page_ext" data structures. Background ---------- Kernel overhead observability is missing some of the largest allocations during runtime, including vmemmap (struct pages) and page_ext. This patch aims to address this problem by exporting a new metric PageMetadata. On the contrary, the kernel does provide observibility for boot memory allocations. For example, the metric reserved_pages depicts the pages allocated by the bootmem allocator. This can be simply calculated as present_pages - managed_pages, which are both exported in /proc/zoneinfo. The metric reserved_pages is primarily composed of struct pages and page_ext. What about the struct pages (allocated by bootmem allocator) that are free'd during hugetlbfs allocations and then allocated by buddy-allocator once hugtlbfs pages are free'd? /proc/meminfo MemTotal changes: MemTotal does not include memblock allocations but includes buddy allocations. However, during runtime memblock allocations can be shifted into buddy allocations, and therefore become part of MemTotal. Once the struct pages get allocated by buddy allocator, we lose track of these struct page allocations overhead accounting. Therefore, we must export a new metric that we shall refer to as PageMetadata (exported by node). This shall also comprise the struct page and page_ext allocations made during runtime. Results and analysis -------------------- Memory model: Sparsemem-vmemmap $ echo 1 > /proc/sys/vm/hugetlb_optimize_vmemmap $ cat /proc/meminfo | grep MemTotal MemTotal: 32918196 kB $ cat /proc/meminfo | grep Meta PageMetadata: 589824 kB $ cat /sys/devices/system/node/node0/meminfo | grep Meta Node 0 PageMetadata: 294912 kB $ cat /sys/devices/system/node/node1/meminfo | grep Meta Node 1 PageMetadata: 294912 kB AFTER HUGTLBFS RESERVATION $ echo 512 > /proc/sys/vm/nr_hugepages $ cat /proc/meminfo | grep MemTotal MemTotal: 32934580 kB $ cat /proc/meminfo | grep Meta PageMetadata: 575488 kB $ cat /sys/devices/system/node/node0/meminfo | grep Meta Node 0 PageMetadata: 287744 kB $ cat /sys/devices/system/node/node1/meminfo | grep Meta Node 1 PageMetadata: 287744 kB AFTER FREEING HUGTLBFS RESERVATION $ echo 0 > /proc/sys/vm/nr_hugepages $ cat /proc/meminfo | grep MemTotal MemTotal: 32934580 kB $ cat /proc/meminfo | grep Meta PageMetadata: 589824 kB $ cat /sys/devices/system/node/node0/meminfo | grep Meta Node 0 PageMetadata: 294912 kB $ cat /sys/devices/system/node/node1/meminfo | grep Meta Node 1 PageMetadata: 294912 kB Sourav Panda (1): mm: report per-page metadata information Documentation/filesystems/proc.rst | 3 +++ drivers/base/node.c | 2 ++ fs/proc/meminfo.c | 7 +++++++ include/linux/mmzone.h | 3 +++ include/linux/vmstat.h | 4 ++++ mm/hugetlb.c | 8 +++++++- mm/hugetlb_vmemmap.c | 8 +++++++- mm/mm_init.c | 3 +++ mm/page_alloc.c | 1 + mm/page_ext.c | 18 ++++++++++++++---- mm/sparse-vmemmap.c | 3 +++ mm/sparse.c | 7 ++++++- mm/vmstat.c | 24 ++++++++++++++++++++++++ 13 files changed, 84 insertions(+), 7 deletions(-)