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: 13383641 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 E708AEE01F1 for ; Wed, 13 Sep 2023 17:30:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56E3A6B0280; Wed, 13 Sep 2023 13:30:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51DF06B0281; Wed, 13 Sep 2023 13:30:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E6566B0282; Wed, 13 Sep 2023 13:30:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2B8C86B0280 for ; Wed, 13 Sep 2023 13:30:05 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0238BB3FB8 for ; Wed, 13 Sep 2023 17:30:04 +0000 (UTC) X-FDA: 81232262370.09.19D1691 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 585A240019 for ; Wed, 13 Sep 2023 17:30:03 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ON+imxRO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3mvEBZQsKCLMlhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3mvEBZQsKCLMlhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694626203; 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=nQYKtEx2Ahg/EgiBcTyeql1DXcav92WH1KFkTagbIIU=; b=Zagw8HnE+/w7X5z2es6OchQFe3NLWYKHOPLxXIr806yh6xvrqLMrgQq0KNtrKXeW9ETGNl NWvOnO4nzGI/ElyAZ9b9jKrUSUsT1aPiR97CmQx6TCBNi00Rqin+TTuNEb/KU/W4vTvz7W tvANgtvLfiu7/EKZK9F1O2eX0OGnrAE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ON+imxRO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3mvEBZQsKCLMlhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3mvEBZQsKCLMlhnkToiTgWTZhhZeX.Vhfebgnq-ffdoTVd.hkZ@flex--souravpanda.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694626203; a=rsa-sha256; cv=none; b=TaA9KS/bqmu1pyTDpvON9nHV3DDiUQAA2zjrcON3NvFsenI/XjVSYR/GQrwxYsZfiOFaWm 7BsCJ7adFTqVz41zbKGrMoOxfw7OdwLVbJBZcPuLDSXKYSJzgz9cfVCUueeifNT2K2wbOP 6GXxHwiUqAuvm9hxxBbterzlxaCuXwM= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-59b5884836cso906947b3.0 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=kvack.org; h=to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=nQYKtEx2Ahg/EgiBcTyeql1DXcav92WH1KFkTagbIIU=; b=ON+imxROZL/HRH6Q/embAswrNIHnpPWvGON1+/Bt+vxFzlncZ2zTl4j7JkjDXtgPU9 qsU3H/fegi5lpReoUf8VziPojAoQs8qtcsBxe3Ie218L9eU143t+UZDTV61igU2JgmGD UD9upVGA8DPfo4CBUtj8yaP5PhwX1J83JrVnLOyM01r9pW0h+M2gh8m1rJLNN2qFJPxB bf4OiXDm8g9nu3x80vm6aqXwIimGynnVAKEByUI/LH5rx29cQclQbWIGHQ4XmNiupz0Z 4HNB8I+ANR13m1wv+EA+KFk7knAxtm25GE70fWNia7Sw5NlCaYoGic6KyGqn8I1OyB/w Juzg== 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=D/TspFx+MRDODzi4D0ibEcEiUrJFX4NzUJye+nerag6tQLhO1aO9vinJZuofLcRUde E2B0FXrdGXb/KriRB7CzNl0mWbWznlXFMebFq235jLVY/zEiP05dTisJHb7lApTxjIf/ qcm+5Cyp2irG4g9D8WMCWsZBBvFnI5UhWEHwKSoAdG1oHX5aaRoJqQhuFPa+ep/piegy UJYHCRIJ0BuMQK+iewDvPZkrh6TupbxP3VBAd8X34ELqPOkNsADm8po1nURqLXYvHalP 7zHyJvwPsFGGthqOWIDrX2pRCzrns7l5QGswHHyfk3A7C4vRu8TILtqb38TogzLT1U3R m7ZQ== X-Gm-Message-State: AOJu0YygDCVG/cnWgu6NMdkEuoFaPW0TmMo7gSnAFLWfLbT+5pB/f2BI 6bBd2dsS3e9xFDGff0g8owOZbXbswWi4L7Qriw== X-Google-Smtp-Source: AGHT+IE5cLs10j5eM7g1XBTKf4J/Tj20JYHER+8VUILJlyo+8XOTakwpxeH8VGHFwpoyBFxAjTheI7UpMFKI+r/eiQ== 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 X-Rspamd-Queue-Id: 585A240019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: mkrrs8oradk1azuo785w69hf31ejbarx X-HE-Tag: 1694626203-376458 X-HE-Meta: U2FsdGVkX18Kb1JSU7rMosAVr7VhJsX5NftKv+QuzlqN8qLMPJgKRR87zNhVIRyS/97CHlLIELdtJGV5ZEH5sdrXORUVKGCYVvu07ChCHwCuAIc5xLWjEiiDknJr6mJITEhfa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YsUj9AegGHgLxQPHdOEIrg9AmGxIPRZ3XwDryBavBHRz2NUye+mtOjfBweAPQpiqTTdYEvcPqYxPsfrKvhynZlXDJH5wu9RBvn3j+zYeF3NyxNecLpJPM1PLY3Ny0aUgJ2nU9UZbAJupVQNbQRVrhxJ1NNcs/iSClzr0yy4neMXLbOH281E9H+3z9zyClcM7IW+6oOcsacUBMzw+iGyfePuCNee4H82g9gIGp2q0+cJ/08Kc57V7UBYEvhpyBdj9v+c1pTzGMU3Ek1LOJ1WKgBYZqqb4qg0zuNd++r1QuCpcXgFzy/Ki2CukmZ/Qqqx05283tFJu05vSkTCQbHIGOlGZX0IAq5DIZknQriDPtv8qdl5w978gtgmuw2/cTK81pRo05y7CKVh3Gh4u+6Kpv5vVZnb674AXnVxzKSyyRiaFnTa4o0WFuKBE/MChg5qHOMYt82c2NSE+vkKrtBPTWg4T7pOrV1z/Nr 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: 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(-)