From patchwork Wed Oct 18 00:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 15517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4490139vqb; Tue, 17 Oct 2023 17:56:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4CjWTLZR4rgkPChr6vS03F9hHzKGoPpBc0fv7Zv/Q4ctAU2lpmLF1QqGK+bJ9YFM+g2Iq X-Received: by 2002:a05:6870:15c2:b0:1e9:a8ff:67e3 with SMTP id k2-20020a05687015c200b001e9a8ff67e3mr4554335oad.4.1697590581844; Tue, 17 Oct 2023 17:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697590581; cv=none; d=google.com; s=arc-20160816; b=nW/L0i16mdFJlUboYS+kuGxTQ38VbTFGEsd4+O2jvvRUNWbrwarETlDUwBRVN0HV8N O2KGwOutjWJFdmcErue+A+VzK+iV6hce+F/jiqIajWCcutV5rCfKHMO9AFecGREMb7oG OUrwABiGpp8/m2dwFZdgsot8IcSemW2+Or2tk5guGfcXTqfu8ZThyHk55pCmHfz+3EoX 7W/pLR/jR4v2v/nohbz3F0IP29k+EF0XiCdnsouWzbovJyoCBGnUG6V9Pgkq9+pSOnm8 ghlnAdFh0KUi7cyESHhD1Tn1bQnoJMzhfSe6vN3ITO4TCiY8VQ+1TrD6yzFQ1DCiDWns bpqg== 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=RtN1cX7OnFY4c89ZOmsAINIHxJE4cdFfX8n5PNBpJGI=; fh=iu/P836aAwCRikxsfqdm6fprX6HyNtoHPqgWDCyb7cI=; b=t+XE9L9L3ERvXeKypg3OPMFZPu6U5x2j0Q058yjolz3Q/PqyW6rwHnVDu+dSL3k7qC MvLQRMcbFeGCG9i8ghxpuFt8voB7TYF568+ks3C/9RVPuz+T84ZqMNL8aiZw769Brkdf l4ZoYtevkigJL7yNUsQuTDqy0K2DPcF656xP9V1I3JwofUlJ1t0cOTqkNo1cxJk2xMnt zza1htqoOeuufB9uCyYPvlash3RPuMrHbPKbvABQufWSmeXakYt7B2U9m822hz4xNHfB NG4N2zg2OgVOkT/FOPw8Epp42iBVYGqWYHMKZ2eRvd0AtyhIzOAs0NcMzTDR01AWqUd1 BjYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KgneW3Oe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bw18-20020a056a02049200b005a019d60ffbsi1137507pgb.78.2023.10.17.17.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 17:56:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KgneW3Oe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 6267780E60AB; Tue, 17 Oct 2023 17:56:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344258AbjJRAz5 (ORCPT + 23 others); Tue, 17 Oct 2023 20:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJRAzx (ORCPT ); Tue, 17 Oct 2023 20:55:53 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57441FA for ; Tue, 17 Oct 2023 17:55:51 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7dd655566so97655997b3.2 for ; Tue, 17 Oct 2023 17:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697590550; x=1698195350; darn=vger.kernel.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=RtN1cX7OnFY4c89ZOmsAINIHxJE4cdFfX8n5PNBpJGI=; b=KgneW3Oe5RHM8xksCub1w77ZaBsnFs5fWKyELoxmpt+V5UjkrheW3h5b9u/KAVAc3Y Go8N4AsXF7YHU84oRKrLsb+WxZVl5H27os50mzHla9C0a0FH3OiAC8g8rW5elmDHox50 QgFIxZpcVe665cpWJvsN1vSb0sC8Vl7zeq+BxNRGvGdHiwHnAsEj6+2/2MfdUS0GN4TI kypfYCKgObKZoSU11IJnGFyR+lOLCYulYfgBGgDlwouTA2twT/sSUIuhuAggBWYUrZLD bv89JGD9YhKGVEeNMCK/7ZC2UqFmFxX5IeyqWsYtFR+T+JWWEVe5oL6rZCNqZwNYtB/V 2NGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697590550; x=1698195350; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=RtN1cX7OnFY4c89ZOmsAINIHxJE4cdFfX8n5PNBpJGI=; b=cUw0j+DFFBuj1FswRgf66HvCExfXySG58bE2hh+5ze8thGEOn2Yh37VfnasirXAMGy L22HbUoLKkT+MzagCJvmQgCrgpk8E+qRco59i6Cw45ahzv9T4nr+MEbzG7n2PQbehutq WEWqsorLKENaoUiOKedly4PgQ1kWD0K+Vw1DbCfEEhTS4E2s/XG5JjSmW0KGbtuuhTHI JkVU+ALiZXmOtl550ShA8RStvu1ar1qo9VjmOpzKx9GGkqrjXyp22TQkS+N6j8tACrz/ qVbmR3BsqlT2SyyFi4L3iXDu99i7zOy3WfTauBWPqm7bxGI336TDGjrnvzazSY9vdS+q dL+A== X-Gm-Message-State: AOJu0YzTfGLWjoIPMTog3B4UzR3XHRKqdAuu6vo36Hew+fRCO8Ig9q1r FhHjQAbLuaZoiZlHFhnEKu6S8/EuslP/apk2nw== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:26ea:df99:e4a5:e557]) (user=souravpanda job=sendgmr) by 2002:a81:4f94:0:b0:5a7:b9b0:d23f with SMTP id d142-20020a814f94000000b005a7b9b0d23fmr80315ywb.6.1697590550545; Tue, 17 Oct 2023 17:55:50 -0700 (PDT) Date: Tue, 17 Oct 2023 17:55:47 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231018005548.3505662-1-souravpanda@google.com> Subject: [PATCH v2 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 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,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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 17 Oct 2023 17:56:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780052742331308213 X-GMAIL-MSGID: 1780052742331308213 Changelog: 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 ----------------------------------- 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 | 18 ++++++++++++++---- mm/sparse-vmemmap.c | 3 +++ mm/sparse.c | 7 ++++++- mm/vmstat.c | 24 ++++++++++++++++++++++++ 13 files changed, 84 insertions(+), 7 deletions(-)