From patchwork Tue Oct 31 17:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 13442153 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 4D20BC41535 for ; Tue, 31 Oct 2023 17:45:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAA568D0022; Tue, 31 Oct 2023 13:45:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5A068D0012; Tue, 31 Oct 2023 13:45:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FB688D0022; Tue, 31 Oct 2023 13:45:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7BFE28D0012 for ; Tue, 31 Oct 2023 13:45:04 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3BB3C40980 for ; Tue, 31 Oct 2023 17:45:04 +0000 (UTC) X-FDA: 81406482528.04.E6359F0 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 711FA180037 for ; Tue, 31 Oct 2023 17:45:02 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EqutzvVq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3HT1BZQsKCMwA6C9sD7s5vsy66y3w.u64305CF-442Dsu2.69y@flex--souravpanda.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3HT1BZQsKCMwA6C9sD7s5vsy66y3w.u64305CF-442Dsu2.69y@flex--souravpanda.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698774302; 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=4RErP287JmMTq7RMYkFt2o0RxUiLJfWTr4XJXoK087k=; b=ps1bzGZtxkzq9fbaD0WDcg+HFYlVrLIOjOr+eYNcozCYyUAq+6hMuPaEwt2E8kV3fd3m6D YyC7huCN1DCYiY+lB+6vdKwMT6qx8X4SR347h03uzVcMiorqaU688bxvxciRqBDIKXY6Vd gEaEo3Fi2Ebl89KoliVZNL/TwDOF+nQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EqutzvVq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3HT1BZQsKCMwA6C9sD7s5vsy66y3w.u64305CF-442Dsu2.69y@flex--souravpanda.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3HT1BZQsKCMwA6C9sD7s5vsy66y3w.u64305CF-442Dsu2.69y@flex--souravpanda.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698774302; a=rsa-sha256; cv=none; b=qrOBwnwwVQvJaLjoxz8bmXMmg50P/sL82gVQNKv2b8sIcBsHP3zErt2gsyHzHMMUcBo2JQ t8gZGG3I0DxjsdUrg2oXayAXNfhF4sLmSUwD7eBo18QCWD5h0oEzFYNPQF3tJlbfDfh1Jk Dg4rvxrWbID6eaUjvZz1sRR2DvCwwYc= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-da2b87dd614so4104046276.2 for ; Tue, 31 Oct 2023 10:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698774301; x=1699379101; darn=kvack.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4RErP287JmMTq7RMYkFt2o0RxUiLJfWTr4XJXoK087k=; b=EqutzvVqzx8tBPYfUmliViqSqamibrYcFb47vtj1rWdlASGfEbEkVAewYnYKNvYTKK ycKQhEtsCU/ngqVnxMS4wH1pI4F2pcBXaDK6GVrX+ezn2odsGNI1d/LSb+QQAlmdmpdX O1kjmn9gxhXD7GTwZx9uwEFQydmUoQbbnWODavbPoqdd2AkGx2y7MRrZWktGF+98QfBS 3augbzfhY/bNfpIGiASylElfJ9y5R8DSA9JY18x16oe6p/W+Q5Zd/Gzeh8m4KgIG8XFN p3CVsEElkRmas4hls7vqmSV02W/TMXRG4yYo70EQP/dQMh/NWCmR8xvf1TwmsZvko8PH fUOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698774301; x=1699379101; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4RErP287JmMTq7RMYkFt2o0RxUiLJfWTr4XJXoK087k=; b=hr1Bc0zTFUOeHAkE53lDBUaHwC/mc7SUFcMrZNrUorhIVxzrWTizoc49fFUfRxsXNg 5Ez/BqzCMxM2MNdBJG6JLkleWSq9Z+/H70p6Q3MwpFw3rwDwOX6YjUIP5rUO/AlNg867 RHHwYZVhH8SGor7YSKBiaFvoIPIf5PmMTX+CQH7OSY2JLDikBhD/bH1Wnnk+FH7ns4lD OdoQhokMK/VHQP2udYjoTWMKHNCUxisqDAF6cXcNnfj0FFmQw8Sa/21RE8J/g7iX4UTb tM0QikcTcc+Ldm9lw4TOI4Krp+WGa9uT6mbEI2Yf4EBlPcI3qHr+fbQvGeIOpusjH559 EBHA== X-Gm-Message-State: AOJu0Yw+kAA+EXYklC/zfn4lEXT/ieUPy3bATbwA+upvtZPci+Q4oXRK R0lQXZTOgJP/VEYCxyDGZW0FlaR+GDYPu+/Wuw== X-Google-Smtp-Source: AGHT+IGF+swsalLbjyalKCjGHosPkOKAM33GIZb7qWKiSJci1IwXcbpCIrifO0+POvPgYWVOttq1dyvPgUe86sUw8A== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:84c2:bfa0:7c62:5d77]) (user=souravpanda job=sendgmr) by 2002:a25:ac04:0:b0:d9a:520f:1988 with SMTP id w4-20020a25ac04000000b00d9a520f1988mr257775ybi.4.1698774301382; Tue, 31 Oct 2023 10:45:01 -0700 (PDT) Date: Tue, 31 Oct 2023 10:44:58 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231031174459.459480-1-souravpanda@google.com> Subject: [PATCH v3 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: 711FA180037 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: qnbb7cf9554uekp7juwubyhky9ju54pw X-HE-Tag: 1698774302-243602 X-HE-Meta: U2FsdGVkX1+r+7NRJCPElShdy3tMPTcYvDsniztngB3B+2l1hleWiWcEgwESiyjImVhwha23MjGGskHxY3ouj/+vyH6N49KqNUC47tI2ov4bP88Ox5F4oWxiIZeQpEvc7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+dHB2Qi+rPD47TPJXfy/nqjCBpwAT68zhnT3wY1SiNvphy5mLQwj5u2ZdWPwkRtERUB5AvuzTrkNajcdTCZzFTYCIAQeaOHidSkzZvWIETdC8CitxGH/mNIIXyRDLT//hvZ2FM5N+Y85EUTRCwmWRMK6GbXu9kGQcR1nVV4y3eeoVv8IspP1a3ZNbiqoN6oVI/PgV0ppvrurUkeMK84vslDEeleDj02RUjq4ph2U9s8+5Npy0jOQHuMYai+vkz8HsagYm9VxhTP5KcMiPrRbOxpbZtvQYdDAMbz0frO9yEV3Oz5u3N8bhbHBgXQyIvfEbrIzRgeYc2M4FKGKef6wFWw9VrGNpI0nryv/19Ez+P4ZNnJkcLsLSMWj2zCUKwq3ErzZEoklbkLarr/Jh2pO+VVcRwR78/byHNCD0UB1giUzHkp8SWGBACWeIpr/gseNXKCdMKcsGH7hUCMFLf+eWo0uRvD1xqV/SpM4o2LTVkvfsBeXQeD1v1ggzWfCFbMbKLJN8uaAsqMTknc2yvyBJEVd1jZdN5BXPQ21kMGuwSFQdcTXFWek4= 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: 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 ----------------------------------- 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 | 8 +++++++- 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, 93 insertions(+), 12 deletions(-)