From patchwork Tue Dec 5 22:31:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 13480841 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 28D5FC4167B for ; Tue, 5 Dec 2023 22:31:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3BFE6B0080; Tue, 5 Dec 2023 17:31:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9EB9F6B0081; Tue, 5 Dec 2023 17:31:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88CCA6B0082; Tue, 5 Dec 2023 17:31:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 747C26B0080 for ; Tue, 5 Dec 2023 17:31:23 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4879DC0306 for ; Tue, 5 Dec 2023 22:31:23 +0000 (UTC) X-FDA: 81534212046.19.39AA31E Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 672F08002A for ; Tue, 5 Dec 2023 22:31:21 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4tmEoLql; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3uKRvZQsKCPElhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3uKRvZQsKCPElhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701815481; 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=uKnmnhbaB6MZWD6KtkJPA2pbRvwEpH4SeUxeebTu4PU=; b=N1nqcQjpr3D6OKD9NNwkMOBJwB/Tb7ZaG0tQdI6Ttg4vxbwTCTeHzG88h7CH1q74VZs6b6 BLh+pVtgZRflnUmXbyGT/sspQ7zSdoZnEo361ZjwjB+a5uYwApLZ8DLSBTrX3OB7ytAM3H 9Yxs+3HWMs5i/zA1d+lYIJtLAMkQhgg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4tmEoLql; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3uKRvZQsKCPElhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3uKRvZQsKCPElhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701815481; a=rsa-sha256; cv=none; b=avKPvDMqUR71Xp5cO7MI5WElT1dr/J4Mm0zY6uaCPXZKGQy7PlPDlqBoBnJIGGVofzbgDN tBp+MGeeoLTq5NFx8+Mb6NNBDHdyxceLo1e4lsBl/MKnukfdZ8XGuFP6xHxdaejyCcn3Al K0XmO79e+cf0JmZSiHWp1X2teSJvBds= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5ca2e530041so96330277b3.3 for ; Tue, 05 Dec 2023 14:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701815480; x=1702420280; darn=kvack.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=uKnmnhbaB6MZWD6KtkJPA2pbRvwEpH4SeUxeebTu4PU=; b=4tmEoLqlYrxB267W0iOlk0YnaDYntPnpi3KvUvqIIzNRTUe3jh2elQ0ygTGttVCH0P h583KYEeyqFaSyakCW47D6hx+2/XXOtiMp+ZC1ePD7TJT0nqmyE4oItHesAJu1CWIHUo NB+EkJRBRUc01iMuxb17cv7yOqNvoV3C3EzHXj+8H9nOWVl61O1vu64Q4pe5R/a+4TpR B4nzoN65YVX4VDLp/L8KRnw0hMupGzoHYATew+8LgVXHyzoJ8UsiEoyfHJLhBJaeQjAy /osxAWAarJy/9UTYa9tIUkBUHWPP1px2qZNMrsjhg/5JPVCqd4yk893TSV4WZW/NQ5fg ihGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701815480; x=1702420280; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uKnmnhbaB6MZWD6KtkJPA2pbRvwEpH4SeUxeebTu4PU=; b=d/PSzE8F7OvNQMEbY9uEnE5wEe27mxgwil1LBT50mDWQ6k8jl++CgZfsal18R1yrZf NddwVnLaLCmSBpAU9B6kRR90mPmIKvcrO2W5ILOq6oQq9ZhLKVopzwfwMh1HzH9tWGb+ ycsODSVMWgMjiSSY5PoCPtghLrKB5UShEhrPK4eGWWXf0DJlWfo5ebcDn3LBU62oDqRU 15BBlc+EcG8iavx9wzLBdeRjFfC8T/cVSOjcUlFIycnKTvyBEVT/89MX00EdeZNvvPWp 5frDKn1tc3012vuj3n/lv9cbkXEFhfy+GYoz88pcXxlPhXKlyCoilWAJ8rB2xrU0Bas6 ZoZQ== X-Gm-Message-State: AOJu0YxYOjS7aOlvSh+Pc8l4buW7wj9/Lk25cgVd5+yoyATrgodqTb2Y drDzXGJQBRbbJlh9hpwo4m67V5CpnbWe49Urew== X-Google-Smtp-Source: AGHT+IG94DctHBHUgLw+r9Z4psNv0tqS0WCNoREA6Q3QtdPaC54TMWcnYVFwHQT6waXor5yVQr6dfzH9vExG9KDf/Q== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:f645:15:697e:b77b]) (user=souravpanda job=sendgmr) by 2002:a25:7082:0:b0:da0:59f7:3c97 with SMTP id l124-20020a257082000000b00da059f73c97mr1098248ybc.12.1701815480325; Tue, 05 Dec 2023 14:31:20 -0800 (PST) Date: Tue, 5 Dec 2023 14:31:17 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231205223118.3575485-1-souravpanda@google.com> Subject: [PATCH v6 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, weixugc@google.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 672F08002A X-Stat-Signature: obt761qg96ohyewdbj4b1h38o5s4naor X-HE-Tag: 1701815481-611422 X-HE-Meta: U2FsdGVkX1+K6emgSuetOY+oliv2rQBkL91cL+3QgJZTOqk59Zdssas/XIGTRoTl6L7uUP7foM+fUQ8+SuW5izyMKLShjE0Wk8q5mI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Cx8Ty3a7z2mlHZsLy1S4ALk0DUaebJ/++DSVuKyTQnTWfkYvfenJFbNYAizX75fqDMg+QdIbt9+NTkIWrd8Goh1hoRUJwo5aTcHrpxqbtI0s60xZtojLxbGUKgH/EL+3N4uLBLK0w3E0mshn60qHlFURzZlCZxs6arvazUmNHG6T+pTZOrHakJht+bZnuG936sJAilavNa/mxvqfQOHohBd7eDwuKY66R0YAGE4yF9OIclJpmCojX0AUOCAqghkh7CX1hIOkOII6Xc0EJMM9GICaYIePvb+H55SLdewt+GFXj4oUBXPHlbOa+AcbkaRRIThO8xylb5IiedoMxyCUUpRw6bU1s+BOMaaRBu+k/lHsM5icukM1IMNh5+jTTGxQ4xt69A9D4Bmbd4CIB8gC75tPaQpHyeZTX815L9MvbgCgOEIZKjWZujlrSYM0Pqz0IXT9hrDxAU1pr/Xtzv60f4nDLbrNK4n+jV6C1hNkLgG0m5QPucYzgKH5qWVTXBh1EQTWqbBgIscqJ5zBoIIB0ceY6DbNbrsNwCEPPQ/MvCjBFxO18IXuTr96NYUCtloXnobQjNLhQC9eo/idIJfkp4Ohi4zbnvHoNw== 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: List-Subscribe: List-Unsubscribe: Changelog: v6: - Interface changes - Added per-node nr_page_metadata and nr_page_metadata_boot fields that are exported in /sys/devices/system/node/nodeN/vmstat - nr_page_metadata exclusively tracks buddy allocations while nr_page_metadata_boot exclusively tracks memblock allocations. - Modified PageMetadata in /proc/meminfo to only include buddy allocations so that it is comparable against MemTotal in /proc/meminfo - Removed the PageMetadata field added in /sys/devices/system/node/nodeN/meminfo - Addressed bugs reported by the kernel test bot. - All occurences of __mod_node_page_state have been replaced by mod_node_page_state. - Addressed comments from Muchun Song. - Removed page meta data accouting from mm/hugetlb.c. When CONFIG_SPARSEMEM_VMEMMAP is disabled struct pages should not be returned to buddy. - Modified the cover letter with the results and analysis - From when memory_hotplug.memmap_on_memory is alternated between 0 and 1. - To account for the new interface changes. v5: - Addressed comments from Muchun Song. - Fixed errors introduced in v4 when CONFIG_SPARSEMEM_VMEMMAP is disabled by testing against FLATMEM and SPARSEMEM memory models. - Handled the condition wherein the allocation of walk.reuse_page fails, by moving NR_PAGE_METADATA update into the clause if( walk.reuse_page ). - Removed the usage of DIV_ROUND_UP from alloc_vmemmap_page_list since "end - start" is always a multiple of PAGE_SIZE. - Modified alloc_vmemmap_page_list to update NR_PAGE_METADATA once instead of every loop. v4: - Addressed comment from Matthew Wilcox. - Used __node_stat_sub_folio and __node_stat_add_folio instead of __mod_node_page_state in mm/hugetlb.c. - Used page_pgdat wherever possible in the entire patch. - Used DIV_ROUND_UP() wherever possible in the entire patch. v3: - Addressed one comment from Matthew Wilcox. - In free_page_ext, page_pgdat() is now extracted prior to freeing the memory. 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 ----------------------------------- v5: https://lore.kernel.org/all/20231101230816.1459373-1-souravpanda@google.com v4: https://lore.kernel.org/all/20231031223846.827173-1-souravpanda@google.com v3: https://lore.kernel.org/all/20231031174459.459480-1-souravpanda@google.com v2: https://lore.kernel.org/all/20231018005548.3505662-1-souravpanda@google.com v1: https://lore.kernel.org/r/20230913173000.4016218-2-souravpanda@google.com Hi! This patch adds two new per-node fields, namely nr_page_metadata and nr_page_metadata_boot to /sys/devices/system/node/nodeN/vmstat 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 new metrics. nr_page_metadata and nr_page_metadata_boot exclusively track the struct page and page ext allocations made by the buddy allocator and memblock allocator, respectively for each node. PageMetadata in /proc/meminfo would report the struct page and page ext allocations made by the buddy allocator. Results and analysis -------------------- Memory model: Sparsemem-vmemmap $ echo 1 > /proc/sys/vm/hugetlb_optimize_vmemmap $ cat /proc/meminfo | grep MemTotal MemTotal: 32919124 kB $ cat /proc/meminfo | grep Meta PageMetadata: 65536 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 AFTER HUGTLBFS RESERVATION $ echo 512 > /proc/sys/vm/nr_hugepages $ cat /proc/meminfo | grep MemTotal MemTotal: 32935508 kB $ cat /proc/meminfo | grep Meta PageMetadata: 67584 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 8448 nr_page_metadata_boot 63488 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 8448 nr_page_metadata_booy 63488 AFTER FREEING HUGTLBFS RESERVATION $ echo 0 > /proc/sys/vm/nr_hugepages $ cat /proc/meminfo | grep MemTotal MemTotal: 32935508 kB $ cat /proc/meminfo | grep Meta PageMetadata: 81920 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 10240 nr_page_metadata_boot 63488 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 10240 nr_page_metadata_boot 63488 ------------------------ Memory Hotplug with memory_hotplug.memmap_on_memory=1 BEFORE HOTADD $ cat /proc/meminfo | grep MemTotal MemTotal: 32919124 kB $ cat /proc/meminfo | grep PageMeta PageMetadata: 65536 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 AFTER HOTADDING 1GB $ cat /proc/meminfo | grep MemTotal MemTotal: 33951316 kB $ cat /proc/meminfo | grep PageMeta PageMetadata: 83968 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 12800 nr_page_metadata_boot 65536 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 -------------------------- Memory Hotplug with memory_hotplug.memmap_on_memory=0 BEFORE HOTADD $ cat /proc/meminfo | grep MemTotal MemTotal: 32919124 kB $ cat /proc/meminfo | grep PageMeta PageMetadata: 65536 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 AFTER HOTADDING 1GB $ cat /proc/meminfo | grep MemTotal MemTotal: 33967700 kB $ cat /proc/meminfo | grep PageMeta PageMetadata: 83968 kB $ cat /sys/devices/system/node/node0/vmstat | grep "nr_page_metadata" nr_page_metadata 12800 nr_page_metadata_boot 65536 $ cat /sys/devices/system/node/node1/vmstat | grep "nr_page_metadata" nr_page_metadata 8192 nr_page_metadata_boot 65536 Sourav Panda (1): mm: report per-page metadata information Documentation/filesystems/proc.rst | 3 +++ fs/proc/meminfo.c | 7 +++++++ include/linux/mmzone.h | 4 ++++ include/linux/vmstat.h | 4 ++++ mm/hugetlb_vmemmap.c | 19 ++++++++++++++---- mm/mm_init.c | 3 +++ mm/page_alloc.c | 1 + mm/page_ext.c | 32 +++++++++++++++++++++--------- mm/sparse-vmemmap.c | 8 ++++++++ mm/sparse.c | 7 ++++++- mm/vmstat.c | 26 +++++++++++++++++++++++- 11 files changed, 99 insertions(+), 15 deletions(-)