[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251027160923.GF760669@ziepe.ca>
Date: Mon, 27 Oct 2025 13:09:23 -0300
From: Jason Gunthorpe <jgg@...pe.ca>
To: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Janosch Frank <frankja@...ux.ibm.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>,
David Hildenbrand <david@...hat.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Gerald Schaefer <gerald.schaefer@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>, Zi Yan <ziy@...dia.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>,
Nico Pache <npache@...hat.com>, Ryan Roberts <ryan.roberts@....com>,
Dev Jain <dev.jain@....com>, Barry Song <baohua@...nel.org>,
Lance Yang <lance.yang@...ux.dev>,
Kemeng Shi <shikemeng@...weicloud.com>,
Kairui Song <kasong@...cent.com>, Nhat Pham <nphamcs@...il.com>,
Baoquan He <bhe@...hat.com>, Chris Li <chrisl@...nel.org>,
Peter Xu <peterx@...hat.com>, Matthew Wilcox <willy@...radead.org>,
Leon Romanovsky <leon@...nel.org>,
Muchun Song <muchun.song@...ux.dev>,
Oscar Salvador <osalvador@...e.de>,
Vlastimil Babka <vbabka@...e.cz>, Mike Rapoport <rppt@...nel.org>,
Suren Baghdasaryan <surenb@...gle.com>,
Michal Hocko <mhocko@...e.com>, Jann Horn <jannh@...gle.com>,
Matthew Brost <matthew.brost@...el.com>,
Joshua Hahn <joshua.hahnjy@...il.com>, Rakie Kim <rakie.kim@...com>,
Byungchul Park <byungchul@...com>,
Gregory Price <gourry@...rry.net>,
Ying Huang <ying.huang@...ux.alibaba.com>,
Alistair Popple <apopple@...dia.com>,
Pedro Falcato <pfalcato@...e.de>,
Pasha Tatashin <pasha.tatashin@...een.com>,
Rik van Riel <riel@...riel.com>, Harry Yoo <harry.yoo@...cle.com>,
kvm@...r.kernel.org, linux-s390@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org
Subject: Re: [RFC PATCH 00/12] remove is_swap_[pte, pmd]() + non-swap
confusion
On Fri, Oct 24, 2025 at 08:41:16AM +0100, Lorenzo Stoakes wrote:
> There's an established convention in the kernel that we treat leaf page
> tables (so far at the PTE, PMD level) as containing 'swap entries' should
> they be neither empty (i.e. p**_none() evaluating true) nor present
> (i.e. p**_present() evaluating true).
I have to say I've never liked the none-vs-present naming either.
> This is deeply confusing, so this series goes further and eliminates the
> non_swap_entry() predicate, replacing it with is_non_present_entry() - with
> an eye to a new convention of referring to these non-swap 'swap entries' as
> non-present.
I'm not keen on is_non_present_entry(), it seems confusing again.
It looks like we are stuck with swp_entry_t as the being the handle
for a non-present pte. Oh well, not a great name, but fine..
So we think of that swp_entry_t having multiple types: swap, migration,
device private, etc, etc
Then I'd think the general pattern should be to get a swp_entry_t:
if (pte_present(pte))
return;
swpent = pte_to_swp_entry(pte);
And then evaluate the type:
if (swpent_is_swap()) {
}
If you keep the naming as "swp_entry" indicates the multi-type value,
then "swap" can mean a swp_entry which is used by the swap subsystem.
That suggests functions like this:
swpent_is_swap()
swpent_is_migration()
..
and your higher level helpers like:
/* True if the pte is a swpent_is_swap() */
static inline bool swpent_get_swap_pte(pte_t pte, swp_entry_t *entryp)
{
if (pte_present(pte))
return false;
*swpent = pte_to_swp_entry(pte);
return swpent_is_swap(*swpent);
}
I also think it will be more readable to keep all these things under a
swpent namespace instead of using unstructured english names.
> * pte_to_swp_entry_or_zero() - allows for convenient conversion from a PTE
> to a swap entry if present, or an empty swap entry if none. This is
> useful as many swap entry conversions are simply checking for flags for
> which this suffices.
I'd expect a safe function should be more like
*swpent = pte_to_swp_entry_safe(pte);
return swpent_is_swap(*swpent);
Where "safe" means that if the PTE is None or Present then
swpent_is_XX() == false. Ie it returns a 0 swpent and 0 swpent is
always nothing.
> * get_pte_swap_entry() - Retrieves a PTE swap entry if it truly is a swap
> entry (i.e. not a non-present entry), returning true if so, otherwise
> returns false. This simplifies a lot of logic that previously open-coded
> this.
Like this is still a tortured function:
+static inline bool get_pte_swap_entry(pte_t pte, swp_entry_t *entryp)
+{
+ if (pte_present(pte))
+ return false;
+ if (pte_none(pte))
+ return false;
+
+ *entryp = pte_to_swp_entry(pte);
+ if (non_swap_entry(*entryp))
+ return false;
+
+ return true;
+}
+
static inline bool get_pte_swap_entry(pte_t pte, swp_entry_t *entryp)
{
return swpent_is_swap(*swpent = pte_to_swp_entry_safe(pte));
}
Maybe it doesn't even need an inline at that point?
> * is_huge_pmd() - Determines if a PMD contains either a present transparent
> huge page entry or a huge non-present entry. This again simplifies a lot
> of logic that simply open-coded this.
is_huge_or_swpent_pmd() would be nicer, IMHO. I think it is surprising
when any of these APIs accept swap entries without being explicit
Jason
Powered by blists - more mailing lists