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: 16113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp408524vqg; Tue, 31 Oct 2023 10:45:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2561FLxXPViQiFeYqY9ciCna5NFDQsckU2Ol0VBnpWfBVmTkIQ0PugwSFsd/staB3Fzv4 X-Received: by 2002:a05:6a20:b790:b0:17f:8f9f:14c2 with SMTP id fh16-20020a056a20b79000b0017f8f9f14c2mr7701590pzb.27.1698774353003; Tue, 31 Oct 2023 10:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698774352; cv=none; d=google.com; s=arc-20160816; b=kCehgXoKVhZrRfKNmWU304MqqW1e3Ld/8Yp7AUe9oyyK6D/sfIeAtleZxdSzwpkybb e+L9PyQTkqWrPM8EeNTYTGj000pHoX5eMwyglNvCDT7jZ3JU8WVa9iqBhVZ7FevOf51v nV7KckNBXJX3/5q7bhmTduqjYaht/d5ttc8uU89MKtYh9KoaSVlREALp4Bzr1lz75oD0 t5dY4h/K/Ykl4HIt30t2uDRIGHAENogzD/OVJ59YbfS5z4uJP+eWqMl18qCW1bvhaDAb AmYc/mio3kO42tp6UxCNOzpFJFURXNZ45uhMb0w289enZxCrjzF9S7jmaEjlxfSpoFEd z1zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:message-id:mime-version:date :dkim-signature; bh=4RErP287JmMTq7RMYkFt2o0RxUiLJfWTr4XJXoK087k=; fh=3KAeh75kSaTXAYbfgkJgJ72uwnVS82YU+YKFfx7rW3c=; b=UUEJRtFSj3sEkJ/slp47nY+dTSMAtDlfDsIcTb8mrb4We3YaLelPSQLHkAb5tP9tlD Wb7gsYroFxLnalys2ydmRlF48NqN2GtOl6DYviqSUlLOeHRaZknFW5wQ49w2+vbzG3KX FTks4q/fn9Q4/T8PBNc3iQPylnWuKtu1Elh2IRwzHwjJbHegqxof+dTL9S64wasWUIH1 v15WRczilGW7WZ3ahJGxjbgnPwTgSy8pD44Z8ytl19h6P9/cHQL/4SYQGnNQ7oWlBLVd x3amUB/VASbCN9s/BgwtXgXfMlyfUicnSEQLZ43+BK7xeXHVrruE0cORBG4DoIM177wV 6QOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZxZOrvRw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u191-20020a6379c8000000b005b999968b85si1266512pgc.666.2023.10.31.10.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 10:45:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZxZOrvRw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A962D8076D0D; Tue, 31 Oct 2023 10:45:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346981AbjJaRpK (ORCPT + 33 others); Tue, 31 Oct 2023 13:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346977AbjJaRpG (ORCPT ); Tue, 31 Oct 2023 13:45:06 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D5C0C2 for ; Tue, 31 Oct 2023 10:45:02 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da13698a6d3so5052268276.0 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=vger.kernel.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4RErP287JmMTq7RMYkFt2o0RxUiLJfWTr4XJXoK087k=; b=ZxZOrvRwuu1vp8hmlRAA+RT0Je5ulHjNWoOfB4E9ly8sOzcXeGFqhNQ9gLz8JsNnRB mn6pzWTAPboJNt+WNzbUklCeF80fBVici9myIUMDey7zzzPlJyakbDpLD1hLf1Mlt6lU Y//Fwn/tohhy+Lo17J/zqw9kIwcBMmUCciqFnIUpjbMfenuvrG/2wmogFvK1e+I1N1XM 7lG6onvmgYJf/eHIF7JlB6wUQdpdq7dkrpbNLq4OBXBzFfOzEYh4mlH6wq3QYJfkMz8k 24FoPh6fCkvc/dFb+kA2jvwcNWc41CssYfhWqRSsxFyyn9DJXPah6lnswGSucM7T6lta rbhg== 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=XQmiJ5z6ywQvkeGn7Jr4gz1OYPvpVWhIko0ooNvpHVM0qh27AzfA4PZVF1GeHCGPl3 3oJ+aIk5bByrRk5Q7Q41pglHUD3UPWPP6z87Ek8fFwQww/yj/S/Ru96TRlawULrSBaO+ QTow13uXEHcKK4qR/GXWM1/iRfEmod1LSlJph8GkC0mkvxwVJdLdu97iQgDV84nqHDEb ZmCNEkrVr0OlUbYAn7FzGASVo3vF+6clO42GJ/dkfzKqiKxwI0Q4DrP6LYQxw3amffPb dri3J/qODD413AzPjCICR+7pQDG9XyRmpR8cKSPCVKSuXV94r09vdbduoYLYSRtjgVYa svNw== X-Gm-Message-State: AOJu0Yw8UPiY7AKerA0qXVBFFALV6lKxSvg+bdCROquiC3I5cLpN1B3l 03qws0I3Ju3EjdFQNFEQWvJ604W3yW7oMEJmgw== 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-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 31 Oct 2023 10:45:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781294016313063841 X-GMAIL-MSGID: 1781294016313063841 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(-)