From patchwork Tue Oct 31 22:38:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 13442341 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 86BB2C4332F for ; Tue, 31 Oct 2023 22:38:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20E546B0340; Tue, 31 Oct 2023 18:38:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BF9F6B0341; Tue, 31 Oct 2023 18:38:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 060016B0342; Tue, 31 Oct 2023 18:38:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E6A7C6B0340 for ; Tue, 31 Oct 2023 18:38:50 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B5AB71CB70E for ; Tue, 31 Oct 2023 22:38:50 +0000 (UTC) X-FDA: 81407222820.03.0729758 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 0FD974001C for ; Tue, 31 Oct 2023 22:38:48 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tMv6Yr6R; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3-IFBZQsKCDMhdjgPkePcSPVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--souravpanda.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3-IFBZQsKCDMhdjgPkePcSPVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--souravpanda.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698791929; 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=E4k1hGGxw36dmwLt1HOw2cRLPR7SfORP0QkzJq8sNG4=; b=JpJhZccP317PUXTIUWAxJtxwIX41LhsQYgkiu3a8ssrdq2lNt/w07cS18acHHcezzVWpq6 GyWzJbV7PNPwbstzvUTTj2wNPg6SeW2hbeam9lKeD+ZslytoWwpIYq+NMf10NDgV8oYTKc ERgnRop/y6983Jm1johFYHvAp7dTZUY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=tMv6Yr6R; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3-IFBZQsKCDMhdjgPkePcSPVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--souravpanda.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3-IFBZQsKCDMhdjgPkePcSPVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--souravpanda.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698791929; a=rsa-sha256; cv=none; b=oPS9uvGZysRgxGxCBvOGWmYJUctGda6vjFPKQ7DJjVd5E5Jcfdovj+v2RsddrBYz+vI+3x J2uKjxNTGKTKze/QY8F5Ggrq/Gl4j8ixXBn03wupbMHRuivzME35h4J3zkUEmF8JNH9qKx 3/Q+Q+Iubb9YAxlne0Omxk32Iz3a/Jw= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-da0737dcb26so6313814276.3 for ; Tue, 31 Oct 2023 15:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698791928; x=1699396728; darn=kvack.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=E4k1hGGxw36dmwLt1HOw2cRLPR7SfORP0QkzJq8sNG4=; b=tMv6Yr6R4taLS/3tQ5n/3hf3ICZnjfwo/lRw0Jw1c7OG/eMm3brIJjX3Cxeow5mzZ+ fQQ3Mo2NTurGLkY23jhXTz38e0F12Z3td+a3TnC7EDocimSlmWC1snl3OrK3mltBd5cr EuFLeglQCHC0f9jXTff3giKvcWL5dLZGMglHqsdir9bsQaCEgvLb28mrZMl1wvAmBzBD xYiXfPP+E92/w/CfHOyAyRaeD/zPlPFkfKgyRd7ZvccMjuw5QoCrUOLnFyvp7aiLDzYo MlKhKK4ULRb08gjvkiS8VA6cP82nMTwnlD2mf3aGbqSscLEx9bc+nRuNHnOFWlyf0DMm zLsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698791928; x=1699396728; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=E4k1hGGxw36dmwLt1HOw2cRLPR7SfORP0QkzJq8sNG4=; b=oFxS5gnDjgayRj0dJpI2d4Q4d5ZdOmsNIK8/alSkCTJYkdfkO+PvnMM4IpfLrIsVOh d29AdR5gt9x4arVuARmahqHPvBklriAR9fYAzO6TBG9flGB6Li4P17kRlac9vuWpTdOs 0vFMHaLiKKEtdEVxd59HUIaqJpzfc+jc9oLrj/Wcs26226+5MV+FkY0rT5E7iEO4LLHY jd+ZvK6aUCPF8/IjVYlUrXcs0XBAVbQRArCK66noi4X9H0PpmQ4CENL9WzoYXGE393op 5ckxXjXFbNqy3HxjhAjD/XhxDrK0SJC0iLlZwk4a7j8W/fpCQERnBHHh6Uw61PGW1DhR VY6g== X-Gm-Message-State: AOJu0Yy8QD1y+xlkaxcxjL3NamPcFrpAT1WvrQp7jMHf/RTwLa3vCDFL oIRVgcEqnKCSKQhjA4TuJrtUjqXJkF5zQyz3AQ== X-Google-Smtp-Source: AGHT+IFM2W41gegeIUvzp7uUlh/DfO8Ica5ODCIQO4qan/QTBGDN4jXaqaSexGBwblyANavfH28+tAwYTUKQP15dBg== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:84c2:bfa0:7c62:5d77]) (user=souravpanda job=sendgmr) by 2002:a05:6902:549:b0:da3:b96c:6c48 with SMTP id z9-20020a056902054900b00da3b96c6c48mr2053ybs.9.1698791928152; Tue, 31 Oct 2023 15:38:48 -0700 (PDT) Date: Tue, 31 Oct 2023 15:38:45 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231031223846.827173-1-souravpanda@google.com> Subject: [PATCH v4 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: 0FD974001C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: jtw6azbw7a9c5ocjo6jzepq5bid1rpgf X-HE-Tag: 1698791928-890246 X-HE-Meta: U2FsdGVkX18KkODM6DU1KI0tLqfjQ37b7gBSMWXQIljr0u86mJrXHf+wiw4FMVQlN7LR7aOPKMhZLYeaI9cORyRy+F4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AkC9qXJKAACKc8d4+kpzjx3XmiEC1+KRGCt6SI8ZB//SIQNFXROdFMzJRm2fC2DNU5mYWYS/DC0nNYv5cl7fFtjj6SRwurkejbPHfRAw7DIL7K0NN19jarIiIJZu9ts7BrzS0fXzU9sbrh0ob0vIbDS55iJ7zsxdIypeV49DR0vskyRslrKFai0M/blpCQwBpBwBLSH1+hHY0zF8W1v8cf8RFT1eRblfaV+xp4NUTsPbOOEOvn9ZvIJNGuSF/hl2gGm/3P8SibtVObmB6vPa+9eQLJPfKoDSqBpnz0ZCKMi67K6XIj4bVozeG+CYxgCuGsUatyk7c4eRRwKwz+2aDkVlzV1EA/3KJble25smdM2s+7ldZEBb8Pbau/UO/OULyWvKnSlj7IyNcgbWzSeJf/btX8HVXsUt5tWnTyHgbp4A4AFNSKDbRgGlNkYwt4injiWBg1h1S6kuoLgJ0E2woPf1j2qPW0Gmx2rfXl+IQyhW/zcSCLbfXOFFmA5emEgnJtRkEFLO2Ljq0+KN0QKwJBo17Xia3C8Zxfn02xhvpl4ds0kBYf99HxoOkoX4JzH0x/7tCcWIxOXd6YA== 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: 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 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 ----------------------------------- 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 | 8 ++++++-- 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, 94 insertions(+), 14 deletions(-)