From patchwork Mon Feb 24 16:56:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13988512 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 71AE1C021BB for ; Mon, 24 Feb 2025 16:57:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C2FF280009; Mon, 24 Feb 2025 11:56:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1733E280002; Mon, 24 Feb 2025 11:56:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB97F280009; Mon, 24 Feb 2025 11:56:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CA795280002 for ; Mon, 24 Feb 2025 11:56:51 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7F7371218EB for ; Mon, 24 Feb 2025 16:56:51 +0000 (UTC) X-FDA: 83155442622.16.2DA4B44 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 26C2E1C0011 for ; Mon, 24 Feb 2025 16:56:48 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PK8AnGaP; spf=pass (imf18.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740416209; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YYLglXDyFMXUmuyPM7L4Wt5NI1TaS59XhalfSABwrEE=; b=DoV/4Y4J+Vw2+MUZKAeLF69UOS3Cngr1DLS6lrjUN5HVZ5nrHT0oddYwha1/PeMiKsPIra 4SdsX8k05ZnMgaeZBucp2vCvNrdD0dKp+JmCdh4CXV8py/yFOXkVCPDKG/UGpI+8HQiHM1 lWJC1KcOnIpJgKCl+M87TnTvNfbNVtw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PK8AnGaP; spf=pass (imf18.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740416209; a=rsa-sha256; cv=none; b=2KLuSf87pNAD+RfMFHGY5B0+OG7X7mFd7i+erVtpAfK5YfpG8p/C0KikyHHW1ihqFWmrPK shH8fxzVUjrNM7Q9uaRcZ66h9m2pMpWMe9GmtzvTUV75hWSh8JKta9wThzO3WStD3rslDR 6IMz3RvkPKOtulhvVwPxMmIDychJHX8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740416208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YYLglXDyFMXUmuyPM7L4Wt5NI1TaS59XhalfSABwrEE=; b=PK8AnGaPVfFzTpwr7RnfruTlOZMZfmx860HxQ5MTIbJy/eD72qGAVdzCFM1gAxzsVeOaUi VtptPJeZj78v1rWmc0DpmdofIV7aqA8SgdWICU5U3WCCrCC8HMGiy9PaMiZJYZy4hy1PDx q/jKj4Pje22Jj9bsSyYkQSl9vlbgGM0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-492-gk4fGlr0P6OPfleVOuYr0A-1; Mon, 24 Feb 2025 11:56:47 -0500 X-MC-Unique: gk4fGlr0P6OPfleVOuYr0A-1 X-Mimecast-MFC-AGG-ID: gk4fGlr0P6OPfleVOuYr0A_1740416206 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38f27acb979so4601945f8f.0 for ; Mon, 24 Feb 2025 08:56:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740416206; x=1741021006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YYLglXDyFMXUmuyPM7L4Wt5NI1TaS59XhalfSABwrEE=; b=tkI7KIanUvmfACNvnoQ2MjN5wwJnf3HPcRPKYSRQ/S7MtQHccmhc0XHhpOrK3Fp0kS vxUhD+f+EThul/sAUHbrk+3u+fzfxRlLhKkXNRipRnSm/eZYOX+blpbE+8m63SVNuGWQ JeTupRuKVVhdUDNZXmojpCcXeW8z/qAwx4+0+Rf0ze/fK4kFnZKSPkJewHcbeTQ/1Y91 p/JcvTXS+QhS64pfKipeqq7+pZhfBy1VTXjW92AvOEgKv0/7hmmvkSUDPrcP6sumQlk9 c5AxOcnEgd8HZRJwHV3k3e1BF+56A4zH07TcSccJ6yDN6q9Q9+6b8fv8FtqZjOXeLsgj fnhA== X-Forwarded-Encrypted: i=1; AJvYcCWkeT7p1fDwO2mtOTmHKHAPF+FmeOvLKLJTnbyUU7lfCjjIjs8KpQ4kUm3+JXukCiG58/ks8GC2Gg==@kvack.org X-Gm-Message-State: AOJu0Yx0NKuxT+zkXa+RABpparfnbeNVkRfQIHuwk83qNWJQSgt5jtdu sbH+uAMzQ4AKlm27EGPK5BIsPftPzqezcV8LN3mlVqLi9h4y/P+MKKFvjuuIoGtPA8MTJV8KGdz 385Y0DBsU2HE54Cq6GL1ST65QaIpKqwv7HaFy6PAIJLb5c6pA X-Gm-Gg: ASbGncv8XFY0VzIcx8yb925r3F26jmK1lJMZigqorC4NXpbdSg5T6jYyIw/7nhWOwoz mxCT69YdNnQepuqclnTY6sisupCHuvQfYIidei+VfJaVtxJXc6rhQuFescw2BgB1tdnjdoHJZ1o 5JTKtKoIrsSinCdUZvI0nsQTuZsDEuJjxmrmGEnUgSE+esDqpDvFGHsvyyqc7slO9605+3bO6Jq JD5131D60/QGDypeua22fbfXmu9sdG3NWBApTuIRvu3oS1UBcwFXAajqOedt5BQ3x7mNR6AmkVM fCZVEToVTrt0Bp2qhDHUeUS0u1VVu96Bv6r0GINIsQ== X-Received: by 2002:a5d:6da5:0:b0:38d:cf33:31a1 with SMTP id ffacd0b85a97d-38f707afc79mr12824178f8f.23.1740416206025; Mon, 24 Feb 2025 08:56:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7oc6/f/Omy9ecKXhn6XnBr6bqzxs+GSFB5uGM8J4SWQqdkeD7RWsCxWskwEhPaUkzkpZm0Q== X-Received: by 2002:a5d:6da5:0:b0:38d:cf33:31a1 with SMTP id ffacd0b85a97d-38f707afc79mr12824140f8f.23.1740416205579; Mon, 24 Feb 2025 08:56:45 -0800 (PST) Received: from localhost (p4ff234b6.dip0.t-ipconnect.de. [79.242.52.182]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38f259f7998sm31659273f8f.82.2025.02.24.08.56.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Feb 2025 08:56:45 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Tejun Heo , Zefan Li , Johannes Weiner , =?utf-8?q?Michal_Koutn=C3=BD?= , Jonathan Corbet , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Muchun Song , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn Subject: [PATCH v2 19/20] fs/proc/task_mmu: remove per-page mapcount dependency for smaps/smaps_rollup (CONFIG_NO_PAGE_MAPCOUNT) Date: Mon, 24 Feb 2025 17:56:01 +0100 Message-ID: <20250224165603.1434404-20-david@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250224165603.1434404-1-david@redhat.com> References: <20250224165603.1434404-1-david@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xJT_O8Rm-x3gkIMq2RXKKDvcZt8dFI27D3gK7AoxMOo_1740416206 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: 26C2E1C0011 X-Stat-Signature: 7cjbm46ruezna1e8yrdz5w9zpr394h3d X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1740416208-187688 X-HE-Meta: U2FsdGVkX1+witqDHZ7uc3UahdNRXYboXpoDRLjdr8BGNtywybKWSz8hyR69HDy2sIuTCtcG4nlUTRX3XpJiEWCJWNNspU81DhtBtNADW70RJ5cm46k8uUeQ4E6l0xa6u0evzWmKBSt6hY7eVe12+KZzMJdnNXimgF+R3P0rPxybKUpm2WjMv+cuxudBJ9LmLk2JjiplC0GSUSJwfGZGwNb6xoeLSvCaFGucONfrOHRdtJLkwZ4SJ47G9IZZuZz0otJVkcx6vABXU2sReq4tNFczaBY4OpozMX63Q6h1I4lBHmLSsCu8zunszAZZsL6IegcuMEZ2fJA9VF8b6+Jl0G1sMUSjEKJ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PvUdXZIq7Chr13f7Ne+PM+zIbBCJKEPwm0J8AH+PdCZMiMmyUSHlEAt9KN+1U4iev0zNuON8LYwLlDauv7Q7L7Cr0nja9Va1xf8A5xOCtPi/AeApLmx8= 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: Let's implement an alternative when per-page mapcounts in large folios are no longer maintained -- soon with CONFIG_NO_PAGE_MAPCOUNT. When computing the output for smaps / smaps_rollups, in particular when calculating the USS (Unique Set Size) and the PSS (Proportional Set Size), we still rely on per-page mapcounts. To determine private vs. shared, we'll use folio_likely_mapped_shared(), similar to how we handle PM_MMAP_EXCLUSIVE. Similarly, we might now under-estimate the USS and count pages towards "shared" that are actually "private" ("exclusively mapped"). When calculating the PSS, we'll now also use the average per-page mapcount for large folios: this can result in both, an over-estimation and an under-estimation of the PSS. The difference is not expected to matter much in practice, but we'll have to learn as we go. We can now provide folio_precise_page_mapcount() only with CONFIG_PAGE_MAPCOUNT, and remove one of the last users of per-page mapcounts when CONFIG_NO_PAGE_MAPCOUNT is enabled. Document the new behavior. Signed-off-by: David Hildenbrand --- Documentation/filesystems/proc.rst | 13 +++++++++++++ fs/proc/internal.h | 8 ++++++++ fs/proc/task_mmu.c | 17 +++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 1aa190017f796..57d55274a1f42 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -506,6 +506,19 @@ Note that even a page which is part of a MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used by only one process, is accounted as private and not as shared. +Note that in some kernel configurations, all pages part of a larger allocation +(e.g., THP) might be considered "shared" if the large allocation is +considered "shared": if not all pages are exclusive to the same process. +Further, some kernel configurations might consider larger allocations "shared", +if they were at one point considered "shared", even if they would now be +considered "exclusive". + +Some kernel configurations do not track the precise number of times a page part +of a larger allocation is mapped. In this case, when calculating the PSS, the +average number of mappings per page in this larger allocation might be used +as an approximation for the number of mappings of a page. The PSS calculation +will be imprecise in this case. + "Referenced" indicates the amount of memory currently marked as referenced or accessed. diff --git a/fs/proc/internal.h b/fs/proc/internal.h index 16aa1fd260771..70205425a2daa 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -143,6 +143,7 @@ unsigned name_to_int(const struct qstr *qstr); /* Worst case buffer size needed for holding an integer. */ #define PROC_NUMBUF 13 +#ifdef CONFIG_PAGE_MAPCOUNT /** * folio_precise_page_mapcount() - Number of mappings of this folio page. * @folio: The folio. @@ -173,6 +174,13 @@ static inline int folio_precise_page_mapcount(struct folio *folio, return mapcount; } +#else /* !CONFIG_PAGE_MAPCOUNT */ +static inline int folio_precise_page_mapcount(struct folio *folio, + struct page *page) +{ + BUILD_BUG(); +} +#endif /* CONFIG_PAGE_MAPCOUNT */ /** * folio_average_page_mapcount() - Average number of mappings per page in this diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index d7ee842367f0f..7ca0bc3bf417d 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -707,6 +707,8 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page, struct folio *folio = page_folio(page); int i, nr = compound ? compound_nr(page) : 1; unsigned long size = nr * PAGE_SIZE; + bool exclusive; + int mapcount; /* * First accumulate quantities that depend only on |size| and the type @@ -747,18 +749,29 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page, dirty, locked, present); return; } + + if (IS_ENABLED(CONFIG_NO_PAGE_MAPCOUNT)) { + mapcount = folio_average_page_mapcount(folio); + exclusive = !folio_maybe_mapped_shared(folio); + } + /* * We obtain a snapshot of the mapcount. Without holding the folio lock * this snapshot can be slightly wrong as we cannot always read the * mapcount atomically. */ for (i = 0; i < nr; i++, page++) { - int mapcount = folio_precise_page_mapcount(folio, page); unsigned long pss = PAGE_SIZE << PSS_SHIFT; + + if (IS_ENABLED(CONFIG_PAGE_MAPCOUNT)) { + mapcount = folio_precise_page_mapcount(folio, page); + exclusive = mapcount < 2; + } + if (mapcount >= 2) pss /= mapcount; smaps_page_accumulate(mss, folio, PAGE_SIZE, pss, - dirty, locked, mapcount < 2); + dirty, locked, exclusive); } }