[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <c30fcda1-ed87-46f5-8297-cdedbddac009@redhat.com>
Date: Wed, 24 Apr 2024 11:40:07 +0200
From: David Hildenbrand <david@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: linux-mm@...ck.org, linux-doc@...r.kernel.org, cgroups@...r.kernel.org,
linux-sh@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, Andrew Morton <akpm@...ux-foundation.org>,
"Matthew Wilcox (Oracle)" <willy@...radead.org>, Peter Xu
<peterx@...hat.com>, Ryan Roberts <ryan.roberts@....com>,
Yin Fengwei <fengwei.yin@...el.com>, Yang Shi <shy828301@...il.com>,
Zi Yan <ziy@...dia.com>, Jonathan Corbet <corbet@....net>,
Hugh Dickins <hughd@...gle.com>, Yoshinori Sato
<ysato@...rs.sourceforge.jp>, Rich Felker <dalias@...c.org>,
John Paul Adrian Glaubitz <glaubitz@...sik.fu-berlin.de>,
Chris Zankel <chris@...kel.net>, Max Filippov <jcmvbkbc@...il.com>,
Muchun Song <muchun.song@...ux.dev>, Miaohe Lin <linmiaohe@...wei.com>,
Naoya Horiguchi <naoya.horiguchi@....com>,
Richard Chang <richardycc@...gle.com>
Subject: Re: [PATCH v1 06/18] mm: make folio_mapcount() return 0 for small
typed folios
On 09.04.24 21:22, David Hildenbrand wrote:
> We already handle it properly for large folios. Let's also return "0"
> for small typed folios, like page_mapcount() currently would.
>
> Consequently, folio_mapcount() will never return negative values for
> typed folios, but may return negative values for underflows.
>
> Signed-off-by: David Hildenbrand <david@...hat.com>
> ---
> include/linux/mm.h | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index daf687f0e8e5..d453232bba62 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -1260,12 +1260,19 @@ static inline int folio_large_mapcount(const struct folio *folio)
> * references the entire folio counts exactly once, even when such special
> * page table entries are comprised of multiple ordinary page table entries.
> *
> + * Will report 0 for pages which cannot be mapped into userspace, such as
> + * slab, page tables and similar.
> + *
> * Return: The number of times this folio is mapped.
> */
> static inline int folio_mapcount(const struct folio *folio)
> {
> - if (likely(!folio_test_large(folio)))
> - return atomic_read(&folio->_mapcount) + 1;
> + int mapcount;
> +
> + if (likely(!folio_test_large(folio))) {
> + mapcount = atomic_read(&folio->_mapcount);
> + return page_type_has_type(mapcount) ? 0 : mapcount + 1;
> + }
> return folio_large_mapcount(folio);
> }
>
From 98acfb7ff35cb65fcfca5e799bf58f8afe84a645 Mon Sep 17 00:00:00 2001
From: David Hildenbrand <david@...hat.com>
Date: Wed, 24 Apr 2024 10:56:17 +0200
Subject: [PATCH] !fixup: mm: make folio_mapcount() return 0 for small typed
folios
Just like page_mapcount(), let's make folio_mapcount() slightly more
efficient.
Signed-off-by: David Hildenbrand <david@...hat.com>
---
include/linux/mm.h | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index cf700c5cdd58b..78e583b50e421 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1271,8 +1271,11 @@ static inline int folio_mapcount(const struct folio *folio)
int mapcount;
if (likely(!folio_test_large(folio))) {
- mapcount = atomic_read(&folio->_mapcount);
- return page_type_has_type(mapcount) ? 0 : mapcount + 1;
+ mapcount = atomic_read(&folio->_mapcount) + 1;
+ /* Handle page_has_type() pages */
+ if (mapcount < PAGE_MAPCOUNT_RESERVE + 1)
+ mapcount = 0;
+ return mapcount;
}
return folio_large_mapcount(folio);
}
--
2.44.0
--
Cheers,
David / dhildenb
Powered by blists - more mailing lists