From patchwork Wed Sep 13 17:29:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sourav Panda X-Patchwork-Id: 13934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp82853vqb; Wed, 13 Sep 2023 14:00:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFK8tHd06fFTPiWpdToKsJnQUTpQnMUPiiO+tYXxkifN0W5HhPi4UPt5PVffSsUuQhLc8sH X-Received: by 2002:a05:6870:7aa:b0:1bb:8333:ab8a with SMTP id en42-20020a05687007aa00b001bb8333ab8amr3476966oab.4.1694638822449; Wed, 13 Sep 2023 14:00:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694638822; cv=none; d=google.com; s=arc-20160816; b=UKBuCtFj1LmS+mc+ZooA2DyqCIgHdDnIFNrZ+kGO+RQh2T21IIw4m0p+yr8sx34Mlw yuLPfVTW4IUf1WTN8k1WPgkizKgFcWb/kHG0NFnI3M3GMCAMb3e0DO9kr6TQYxRfCfL4 uEv8ZdL1HZKnwmZTDy7aU5ZJ9O3K/i1erLICTk9s2ShxtQQgDmfKnbUt3nOAtV3VctmT s8z0792VADOnYEz2P8IJ2mmkd3opb7Wmmsw2naydrZ46MQ8wvzT3RSYocHaVN0kmpZh1 sOpDS6J1VsPSwZlSTIIuvszq8E4nckyohhRvvGrZlMLiTIiTs3gdv9xoHTr4WCuaN6cY Z4jA== 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=nQYKtEx2Ahg/EgiBcTyeql1DXcav92WH1KFkTagbIIU=; fh=M+Nnz37zPoYKD+zx5KP7hHXCFaug3UTkUdQQFCKJoPE=; b=U6YuKuUQxfSYUUMLvR+Td4GO9Va5lats0Gjbi8MrPmQRz9gbPlLj4KK3OqanfYKePq Z/JW1h/G5RhBa4LqELHtXF+i+9f5O9EBD0pHSfkt/AdFEEfmy1MN0uNPrD7GQVGSlBp0 mSICKAP2q+QlwjSY093Zq5zNJ6aiSemGH+KIvdS0Ah9ZfXH621RIx4yjO96Tm5NJnebN MaiG3t3zIeGhL3nkLHvF5E7Xt+beGO9BbSDK4T2COh3SWgl9jnrcbzKE6/lN+PCVYdLb bg10VncaC8WYfJsSVOlYbCcsC8euofYpxB3wLQKwF+vpLElaY5P2Hx68wWATUvWPfyVW ueQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QcZGQlJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x18-20020a63b212000000b0057795cb4f16si4667425pge.684.2023.09.13.14.00.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 14:00:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QcZGQlJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 914CF80968A1; Wed, 13 Sep 2023 10:30:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjIMRaI (ORCPT + 34 others); Wed, 13 Sep 2023 13:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjIMRaH (ORCPT ); Wed, 13 Sep 2023 13:30:07 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3654B9E for ; Wed, 13 Sep 2023 10:30:03 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-58fc448ee4fso639267b3.2 for ; Wed, 13 Sep 2023 10:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694626202; x=1695231002; darn=vger.kernel.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=nQYKtEx2Ahg/EgiBcTyeql1DXcav92WH1KFkTagbIIU=; b=QcZGQlJFPD7rOD8ukzyNgU4IKqt4aKsgMSJHXOPq0kzX2xLz8OeX5oHGHvOzZlCvID +weXoFNpjn8TKNRouilDr2s0covfCzgMXwabba0Dw3WZJQuK47MWwafZavej3GrK4Rwv aisp03OFpxns1K+GnZ8NI54KZJX66yoiEIjxJVpJvkLOlkV8rCWlAvXZihIia/kuAJGL txHZldYGrijNylL5LtyKgIwPKB4yCSeTmuj13EoCVCEJc/SIBgvMGJJ8AK/UMV/K0VBR 68FKRV+QkUKIYmfB0IUlfn02vnV4Npr9124pdet16QX5+rly28snLHE3GosYLx3968b+ 6lFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694626202; x=1695231002; h=to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nQYKtEx2Ahg/EgiBcTyeql1DXcav92WH1KFkTagbIIU=; b=Rak9tjlgrQLaI01icJ/K3+D8jIWDTITzwlV3WG+uGh/8ftQ4SHQWKjdMvtW+Gi7sE2 ELK7iTfqu7NS7lGyQltQJ+W/VflkwSzES8vrMjOI1yQX6dgOcCTto60JFD5MVrdVneAU cQMMJ80Ps81PWe5fSbD0WIQbMZWbGI8vibvVYW0e+VGx5gspOXP+zkzYqIR98JpeL6c5 z7CNzK3stqBw172qJHU0NT31i9VlZBC7haKNA3GqYBQTzJ6f/UD0MwIRbhhvnxY4wVUw fA4bcDuRldH/+Bzg3UuhEjQ90n/LbaCfssWeJbjeOpbYX4Dtxztp4p3bnsuHbQBkxRlx J+iw== X-Gm-Message-State: AOJu0YxC5iPVOlo2FQoHfdFMkU5W9cIDmtjFKaCXQx5zNorQvdE10KLH UiC8SN7Ni2NBX+Losa7Oyi9WlnB8va+EnG4Ifw== X-Received: from souravpanda.svl.corp.google.com ([2620:15c:2a3:200:2718:5cf5:d91:d21d]) (user=souravpanda job=sendgmr) by 2002:a05:690c:4703:b0:59b:e86f:ed2d with SMTP id gz3-20020a05690c470300b0059be86fed2dmr3605ywb.5.1694626202437; Wed, 13 Sep 2023 10:30:02 -0700 (PDT) Date: Wed, 13 Sep 2023 10:29:59 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230913173000.4016218-1-souravpanda@google.com> Subject: [PATCH v1 0/1] Report perpage 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 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 (fry.vger.email [0.0.0.0]); Wed, 13 Sep 2023 10:30:22 -0700 (PDT) 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 fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776957598204539995 X-GMAIL-MSGID: 1776957598204539995 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 | 9 ++++++++- mm/mm_init.c | 3 +++ mm/page_alloc.c | 1 + mm/page_ext.c | 17 +++++++++++++---- mm/sparse-vmemmap.c | 3 +++ mm/sparse.c | 7 ++++++- mm/vmstat.c | 21 +++++++++++++++++++++ 13 files changed, 81 insertions(+), 7 deletions(-)