From patchwork Wed Nov 1 23:08:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 13443115 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 0ADE8C4167B for ; Wed, 1 Nov 2023 23:08:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C0C08000C; Wed, 1 Nov 2023 19:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7709B80009; Wed, 1 Nov 2023 19:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 610E38000C; Wed, 1 Nov 2023 19:08:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 50C7E80009 for ; Wed, 1 Nov 2023 19:08:21 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 30722160D8F for ; Wed, 1 Nov 2023 23:08:21 +0000 (UTC) X-FDA: 81410926002.17.F913E17 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf08.hostedemail.com (Postfix) with ESMTP id 7A0B6160007 for ; Wed, 1 Nov 2023 23:08:19 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=nhJNy8LC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3YtpCZQsKCFMD9FCvGAv8yv19916z.x97638FI-775Gvx5.9C1@flex--souravpanda.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3YtpCZQsKCFMD9FCvGAv8yv19916z.x97638FI-775Gvx5.9C1@flex--souravpanda.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698880099; 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=5qWWijUVxf0dBo3Nq+4AwtcGaRZKaTUhIgmJU1h7y10=; b=Sf5V/F1T6OznW8ZFXtQ7q7KNdYTCniRXFC0/KxIZJ0NkoI0EUyuKBkWIKV3KGQCtjNGBq6 JViSPoTOpfNmm0mVun7HofT1IKplhSaNkypLblOGCfCejK/ZIWDChweotsbtO1GWIuWfOJ Y7ttVT+tlf/lgnRfrd1fTm14jfR6I8Q= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=nhJNy8LC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf08.hostedemail.com: domain of 3YtpCZQsKCFMD9FCvGAv8yv19916z.x97638FI-775Gvx5.9C1@flex--souravpanda.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3YtpCZQsKCFMD9FCvGAv8yv19916z.x97638FI-775Gvx5.9C1@flex--souravpanda.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698880099; a=rsa-sha256; cv=none; b=yuCbeK2sE07o15CtN+Z0IYsjrzWm9+DdbG2w57pZIZdu5Niqa4rOmY5qlkC80uNHzj5ugU p0RHFo5MjaolnGDkrpz+NNR61lzn7JGiJMjmIgXVEWWgl8qyrmsIY0XY6NOXKu/T7oOBPZ pK7wi+K7dN+Nj5QvBYLYDj6O3owMGxw= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5afbcffe454so7336737b3.3 for ; Wed, 01 Nov 2023 16:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698880098; x=1699484898; darn=kvack.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5qWWijUVxf0dBo3Nq+4AwtcGaRZKaTUhIgmJU1h7y10=; b=nhJNy8LC/AsNrYXvSulzogxgVVC4d2SrbzSdMuF9ZkdLjcdH85DZdXtjMb8zi7IPyZ I2Uoo5weBjRxKcvEQ+1LwSTirxG5i6L6kksRivp4P/3OTGeTs05JluuWWlEt1o2hLdmM 8wD2wyUxhOp0PDvUFLG7tXsageSdkeKa2N0c+Z8Jip1vBIOxpG3JECzzo+WHTt3E0DP+ NEZuhWmVlJyn2zSiVWrMMGy/AoN69ZqyHn90FNaMgmDEXIL1zCcc3leqF+4PDpuQWbSP n02nqXAnYAnQpWnzWtdxMBhd/9ER0SzNe7yDkDL+nDPKljet11U/1jkiKXKgGLuHK5Xr 7T/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698880098; x=1699484898; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5qWWijUVxf0dBo3Nq+4AwtcGaRZKaTUhIgmJU1h7y10=; b=XXiUuD0kBRQ3LXKQ/62EDS83NaJdTtlbAJ4IAmRIhe1ayi4agF7/yOCjo+UPr0CDsm CT347LeogSIq7Tazq78iH/VJHJmtHr/C8f5zcMhikhpo0QHIOI61LeVyCLiZdC0NUlol EXMd0uhDMem7e1/ro+MEBpVOx/Fh3jt7+slkvuwz/uK9JiPMXJ1GX7qv1hjn9G/JqulN c72s55HZ8ccFLj517ingR2Mxk2QhleTt5m6zqqx0oGi0ak1wBVxxqmx0noLHIKoFFThs i5afgLMlEzypp+y1kGxYEj3Z2WpXy6KOtrsUEYFwLHGWl1mzPeM/7PiZuQ2DC/IlB12Z BWtQ== X-Gm-Message-State: AOJu0YwviBkD2HYJpFTWSexBDrZ2xyiGYFlMps2h3F3BRcrmSHm/zjwS Ic5rOMwZp+RwD43vE+EoyRR2DhueVjKmpnNIwA== X-Google-Smtp-Source: AGHT+IFdYPqJCyM6xAim+PJhI90ZB8YdsXHWHdsf1a2bYh7xJWEgEFuSl7UhZ0FcxYXizhGP8t1i3U9NTQqL2dt7Ng== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:9bf9:be0e:41ed:e474]) (user=souravpanda job=sendgmr) by 2002:a25:abc7:0:b0:da0:6216:798f with SMTP id v65-20020a25abc7000000b00da06216798fmr238035ybi.13.1698880098507; Wed, 01 Nov 2023 16:08:18 -0700 (PDT) Date: Wed, 1 Nov 2023 16:08:15 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231101230816.1459373-1-souravpanda@google.com> Subject: [PATCH v5 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-Rspamd-Queue-Id: 7A0B6160007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: gtgmjbfyf9p5tfhpwb933qcqdexox415 X-HE-Tag: 1698880099-595801 X-HE-Meta: U2FsdGVkX1/TP11riK16LScvN4n721V78y/kF3Vb/p7nITssr7mqFwtyLu/WqnQW4BUvq/xCzNpw9ozBXHA0lhXSWkz392RCx6XAee1Tqf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0aJg4fYjDZ6R65Pf4XRCOGxDT3oX2/oY3rm8OOMBS4Ac0usCCi8IcAyAcFdRo3lczIkLSrfnVCMWpvR2IV3kThFWjBtM7ijYWz1GUPkRfQ+X/QeEwKpWKjInDaD3SyzAzKzoWpIx2VOvPWKH4Ydq+GjN9jFQefsW+P7ZpiEFCKSMzlfqKpFkB5AM2GgGNP8D2/flL5IdcW+ROlxoVa6meAvvUl3Sd0KzLPGfkAsFSznYlvUEm10Py/JTnxdMKOgSCFE2pTQNcDXq9OnNTto4RxuhvDGi9kTnv1InFmuIYVbrJt3cbnHHmSX7f+0D1PoBUoPvrkH1vd4mZZPnFSiyNU/zNCAna6Ctt+3p+hANpDvQXo9X9jLoiJMcRbGK7grecqGWG2qscA1J1CYTWkF47q+ysDbZ2P2b1Ti7DthMhNcM5q9PAahoD/gaMmWrrL1PyELGWnFZvc0CEHmIaznBHZ5rl9NSLpHHjuVUm02kyFDUEOQdupcMnVuVbDHKZH6lsAXNTvq7vtv/Iia+JYJK9RKFO/UUAQW9I3BNH41PIFkoukG83UMQuphsSjhrhoTGJH2Xv+bm8PoTAPxIX3E21R9nGw3lUZutz13w== 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: 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 ----------------------------------- 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 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 | 11 ++++++++-- mm/hugetlb_vmemmap.c | 12 +++++++++-- mm/mm_init.c | 3 +++ mm/page_alloc.c | 1 + mm/page_ext.c | 32 +++++++++++++++++++++--------- mm/sparse-vmemmap.c | 3 +++ mm/sparse.c | 7 ++++++- mm/vmstat.c | 24 ++++++++++++++++++++++ 13 files changed, 98 insertions(+), 14 deletions(-)