From mboxrd@z Thu Jan 1 00:00:00 1970 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 43A03C021B6 for ; Mon, 24 Feb 2025 21:42:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5C2F28000C; Mon, 24 Feb 2025 16:42:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0C5A280002; Mon, 24 Feb 2025 16:42:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85E8D28000C; Mon, 24 Feb 2025 16:42:57 -0500 (EST) 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 5FBED280002 for ; Mon, 24 Feb 2025 16:42:57 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 184B51A020A for ; Mon, 24 Feb 2025 21:42:57 +0000 (UTC) X-FDA: 83156163594.20.440F2C3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 226B4A0004 for ; Mon, 24 Feb 2025 21:42:52 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IPFEea1Y; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@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=1740433374; 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=rJdaIppcAF+FxsFQkO0OqCCOm0uBPZoLqjFlhCs6lzk=; b=RNwkEKQ5daEQcP2IpAknM2D5nWGSt+HfITY5GiWN/uXphaAdo+DV/w3YJ1b5Nlz2YoJh6L dAwUH284HaRGrR8YqgDdGLEHxB8RsRBG0iZsPRzMGT6puBlEhnW97wsWqmaKWnHlDJ1DNA 3gktFDsMNTBy83VAF6Dd2vqGC+Nbomk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IPFEea1Y; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740433374; a=rsa-sha256; cv=none; b=OhtyBrXpy7IkV9daRInVzOKODtLxW/06WTjT6ejLiHno2AA7k17K8CEMYwHR5fMrllqmlf /gk0LvVYHPXOLizXF2MF+CHTPxxy6RRMI4C7xtJ1hkrIYPXzJBLRPnCP2tGVaem6oOND2a 7NxCHJIvyySWXbHvxnZiIfD3Vg4eN6I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740433372; 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:autocrypt:autocrypt; bh=rJdaIppcAF+FxsFQkO0OqCCOm0uBPZoLqjFlhCs6lzk=; b=IPFEea1YA1qy2BW5NbgN7NQHNrXFygYVK9DAsqvdC5rF9s/7f6ETEZUqq2axa0s7T4QKho opuZl62z2F9ytP+mfH1ctuwzJ1RLoKD5ZIUrY7Mm4PK6mgi/MYv/j/vazVxUSwTMun/lJu dq8bNSjkta9jw8TijCkIzsfsv0KGtVU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-lv9NWs5BNKiVUNiJEOs5fw-1; Mon, 24 Feb 2025 16:42:51 -0500 X-MC-Unique: lv9NWs5BNKiVUNiJEOs5fw-1 X-Mimecast-MFC-AGG-ID: lv9NWs5BNKiVUNiJEOs5fw_1740433370 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4398e841963so40513325e9.3 for ; Mon, 24 Feb 2025 13:42:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740433370; x=1741038170; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=rJdaIppcAF+FxsFQkO0OqCCOm0uBPZoLqjFlhCs6lzk=; b=IEjb1fwsFFQEVF87yTstGelayaw4VaxzGMNQOsT82YqyBhELIAnPHWvU1rJyovQZLT RsQzLTw210kwjZ7wJvWW/fg0x9Ff1CwK2tGZiNi4VErS85YOO3L4BQYqQWb7YacX9SvN rb3wbmwNMT/L/MmXiAPvNVuYX8wZQRLchBcMhS5HFVt+MJXAM+YtQWE7FaaDop0gFW55 FEW1bsWQs6kgvbVBWCDynOnMURad72A8VvDRDhKU4ALS7GF/NPlxWUrENTd3E1BSGuRa OnSymOD6pYHVxPhZVCzfMVQ1AzBr8qKPR7eStlJSqT4CZtyMK1GKcle57p7tDUWxkzs7 2Chw== X-Forwarded-Encrypted: i=1; AJvYcCUB+28SogWbPHzWivKzQzU+EI0Uv5RtXme506JxRTb8O5Omgg5nwX+tAKA9QZpilhh1mvVsJ6WcNA==@kvack.org X-Gm-Message-State: AOJu0YwXFtIyH7j+z/Wtp+Qjs1gZbYZ80CpzDT0nIdT6vNLb2ySnxup2 Y85VMeUj2LlocuuMc+QUoI4GNh+TUETObkhDOjixkJ2t4SqoKrx2AolpQkv55+1FoaFXU43JCOt U/nrlnV+A2vFolRldNhAXde6jRn87dKKyoayNG09djJN93yCd X-Gm-Gg: ASbGnctqP1+mrhVrGchjfMpYfq3H583Zsnmvl8qNG+wFlJGTCOctIeZ0kABCkrS2BL7 moomviq9ffIq/waXclWjFRZTAKwZSya3RqcsE9mEhlOs8KLqnT2NKGiRIfLdxQMvBaIAK4qWMIy LM+OYiDPkLy8xyQv+HJIRWumo3blBbm9cFMxLyQ8EykOn9MTazc4dKnarrrE2GsJckyDyx91ctX oUQXTejR5h1M60AnAT9wdfonh0UyZDrznYV2357DEavxBphIFwPO/VF48FRdzZSnb/x/p6nT5mK /s/NnvN0/g03U+XfuSbwZHgVoZggbVs8HpdA9vY7maK2ShMURiOUeKNvhK26uerQaJqXbnFgE+J sdOpkkUPg09RcXkfW+Bj/LsPsqmhf8X0rujxscjnl+yc= X-Received: by 2002:a05:600c:3b91:b0:439:9e13:2dd7 with SMTP id 5b1f17b1804b1-43aa7a63c45mr41135155e9.2.1740433369810; Mon, 24 Feb 2025 13:42:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoC4d2j9rOE4cUzpqqA+7hSEc5qzv5dgNmeVhVNJED4tEkT5V3b2VPb/OWSe0Z/WHiHe1vcw== X-Received: by 2002:a05:600c:3b91:b0:439:9e13:2dd7 with SMTP id 5b1f17b1804b1-43aa7a63c45mr41134845e9.2.1740433369369; Mon, 24 Feb 2025 13:42:49 -0800 (PST) Received: from ?IPV6:2003:cb:c735:1900:ac8b:7ae5:991f:54fc? (p200300cbc7351900ac8b7ae5991f54fc.dip0.t-ipconnect.de. [2003:cb:c735:1900:ac8b:7ae5:991f:54fc]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43ab155eb61sm3615755e9.29.2025.02.24.13.42.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Feb 2025 13:42:48 -0800 (PST) Message-ID: <3f6b7e66-3412-4af2-97d9-6d31d6373079@redhat.com> Date: Mon, 24 Feb 2025 22:42:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 16/20] fs/proc/page: remove per-page mapcount dependency for /proc/kpagecount (CONFIG_NO_PAGE_MAPCOUNT) To: Zi Yan Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, 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 References: <20250224165603.1434404-1-david@redhat.com> <20250224165603.1434404-17-david@redhat.com> <8a5e94a2-8cd7-45f5-a2be-525242c0cd16@redhat.com> <9010E213-9FC5-4900-B971-D032CB879F2E@nvidia.com> <567b02b0-3e39-4e3c-ba41-1bc59217a421@redhat.com> <30C2A030-7438-4298-87D8-287BED1EA473@nvidia.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5j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XUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <30C2A030-7438-4298-87D8-287BED1EA473@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iox25NaToZee5OxculrllAF_Dh1HW7KkbYs-i4KyoOE_1740433370 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 226B4A0004 X-Stat-Signature: 5ocns5axziq9k83h4witq37pxt1exsfu X-HE-Tag: 1740433372-602729 X-HE-Meta: U2FsdGVkX19sIZb5r3cu3Qwn4EeBiXvrTtXWYLkLvfIqJ3M+nZl7M7p1riBCmhudEsIvJMuO8OyziNDDIdKPDmDJqL//wJ8hIzjwJb37x2KMFanqsCPrnqHM/5JxNO89Raft+FI5bi3xJEMlYfZBc0l8unfeCUzEKUvgRKMLhclUf/d4HLjxyf1XX7eVTjWxy/T6xWX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Zj8flwZwhOzWoP3kOkHBawUIGoRsWZImNPrDEh7wRom9L8E4MqYpue2PRyt1P3tjZaRnLvSSJKr6DS0jOAwK/7t35Lf9NwU/O4e1U85p+65bN7LekiYjCrYQtNA7EyVSsP1u+ILKUINY+mIbplYraMp4wNbh/aQ== 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: On 24.02.25 22:23, Zi Yan wrote: > On 24 Feb 2025, at 16:15, David Hildenbrand wrote: > >> On 24.02.25 22:10, Zi Yan wrote: >>> On 24 Feb 2025, at 16:02, David Hildenbrand wrote: >>> >>>> On 24.02.25 21:40, Zi Yan wrote: >>>>> On Mon Feb 24, 2025 at 11:55 AM EST, David Hildenbrand wrote: >>>>>> Let's implement an alternative when per-page mapcounts in large folios >>>>>> are no longer maintained -- soon with CONFIG_NO_PAGE_MAPCOUNT. >>>>>> >>>>>> For large folios, we'll return the per-page average mapcount within the >>>>>> folio, except when the average is 0 but the folio is mapped: then we >>>>>> return 1. >>>>>> >>>>>> For hugetlb folios and for large folios that are fully mapped >>>>>> into all address spaces, there is no change. >>>>>> >>>>>> As an alternative, we could simply return 0 for non-hugetlb large folios, >>>>>> or disable this legacy interface with CONFIG_NO_PAGE_MAPCOUNT. >>>>>> >>>>>> But the information exposed by this interface can still be valuable, and >>>>>> frequently we deal with fully-mapped large folios where the average >>>>>> corresponds to the actual page mapcount. So we'll leave it like this for >>>>>> now and document the new behavior. >>>>>> >>>>>> Note: this interface is likely not very relevant for performance. If >>>>>> ever required, we could try doing a rather expensive rmap walk to collect >>>>>> precisely how often this folio page is mapped. >>>>>> >>>>>> Signed-off-by: David Hildenbrand >>>>>> --- >>>>>> Documentation/admin-guide/mm/pagemap.rst | 7 +++++- >>>>>> fs/proc/internal.h | 31 ++++++++++++++++++++++++ >>>>>> fs/proc/page.c | 19 ++++++++++++--- >>>>>> 3 files changed, 53 insertions(+), 4 deletions(-) >>>>>> >>>>>> diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst >>>>>> index caba0f52dd36c..49590306c61a0 100644 >>>>>> --- a/Documentation/admin-guide/mm/pagemap.rst >>>>>> +++ b/Documentation/admin-guide/mm/pagemap.rst >>>>>> @@ -42,7 +42,12 @@ There are four components to pagemap: >>>>>> skip over unmapped regions. >>>>>> * ``/proc/kpagecount``. This file contains a 64-bit count of the number of >>>>>> - times each page is mapped, indexed by PFN. >>>>>> + times each page is mapped, indexed by PFN. Some kernel configurations do >>>>>> + not track the precise number of times a page part of a larger allocation >>>>>> + (e.g., THP) is mapped. In these configurations, the average number of >>>>>> + mappings per page in this larger allocation is returned instead. However, >>>>>> + if any page of the large allocation is mapped, the returned value will >>>>>> + be at least 1. >>>>>> The page-types tool in the tools/mm directory can be used to query the >>>>>> number of times a page is mapped. >>>>>> diff --git a/fs/proc/internal.h b/fs/proc/internal.h >>>>>> index 1695509370b88..16aa1fd260771 100644 >>>>>> --- a/fs/proc/internal.h >>>>>> +++ b/fs/proc/internal.h >>>>>> @@ -174,6 +174,37 @@ static inline int folio_precise_page_mapcount(struct folio *folio, >>>>>> return mapcount; >>>>>> } >>>>>> +/** >>>>>> + * folio_average_page_mapcount() - Average number of mappings per page in this >>>>>> + * folio >>>>>> + * @folio: The folio. >>>>>> + * >>>>>> + * The average number of present user page table entries that reference each >>>>>> + * page in this folio as tracked via the RMAP: either referenced directly >>>>>> + * (PTE) or as part of a larger area that covers this page (e.g., PMD). >>>>>> + * >>>>>> + * Returns: The average number of mappings per page in this folio. 0 for >>>>>> + * folios that are not mapped to user space or are not tracked via the RMAP >>>>>> + * (e.g., shared zeropage). >>>>>> + */ >>>>>> +static inline int folio_average_page_mapcount(struct folio *folio) >>>>>> +{ >>>>>> + int mapcount, entire_mapcount; >>>>>> + unsigned int adjust; >>>>>> + >>>>>> + if (!folio_test_large(folio)) >>>>>> + return atomic_read(&folio->_mapcount) + 1; >>>>>> + >>>>>> + mapcount = folio_large_mapcount(folio); >>>>>> + entire_mapcount = folio_entire_mapcount(folio); >>>>>> + if (mapcount <= entire_mapcount) >>>>>> + return entire_mapcount; >>>>>> + mapcount -= entire_mapcount; >>>>>> + >>>>>> + adjust = folio_large_nr_pages(folio) / 2; >>>> >>>> Thanks for the review! >>>> >>>>> >>>>> Is there any reason for choosing this adjust number? A comment might be >>>>> helpful in case people want to change it later, either with some reasoning >>>>> or just saying it is chosen empirically. >>>> >>>> We're dividing by folio_large_nr_pages(folio) (shifting by folio_large_order(folio)), so this is not a magic number at all. >>>> >>>> So this should be "ordinary" rounding. >>> >>> I thought the rounding would be (mapcount + 511) / 512. >> >> Yes, that's "rounding up". >> >>> But >>> that means if one subpage is mapped, the average will be 1. >>> Your rounding means if at least half of the subpages is mapped, >>> the average will be 1. Others might think 1/3 is mapped, >>> the average will be 1. That is why I think adjust looks like >>> a magic number. >> >> I think all callers could tolerate (or benefit) from folio_average_page_mapcount() returning at least 1 in case any page is mapped. >> >> There was a reason why I decided to round to the nearest integer instead. >> >> Let me think about this once more, I went back and forth a couple of times on this. > > Sure. Your current choice might be good enough for now. My intend of > adding a comment here is just to let people know the adjust can be > changed in the future. :) The following will make the callers easier to read, while keeping the rounding to the next integer for the other cases untouched. +/** + * folio_average_page_mapcount() - Average number of mappings per page in this + * folio + * @folio: The folio. + * + * The average number of present user page table entries that reference each + * page in this folio as tracked via the RMAP: either referenced directly + * (PTE) or as part of a larger area that covers this page (e.g., PMD). + * + * The average is calculated by rounding to the nearest integer; however, + * if at least a single page is mapped, the average will be at least 1. + * + * Returns: The average number of mappings per page in this folio. + */ +static inline int folio_average_page_mapcount(struct folio *folio) +{ + int mapcount, entire_mapcount, avg; + + if (!folio_test_large(folio)) + return atomic_read(&folio->_mapcount) + 1; + + mapcount = folio_large_mapcount(folio); + if (unlikely(mapcount <= 0)) + return 0; + entire_mapcount = folio_entire_mapcount(folio); + if (mapcount <= entire_mapcount) + return entire_mapcount; + mapcount -= entire_mapcount; + + /* Round to closest integer ... */ + avg = (mapcount + folio_large_nr_pages(folio) / 2) >> folio_large_order(folio); + avg += entire_mapcount; + /* ... but return at least 1. */ + return max_t(int, avg, 1); +} -- Cheers, David / dhildenb