mm: remove page_swap_entry()
Subsystems (6)
v2 cover mm: remove page_swap_entry()
A folio in the swap cache occupies folio_nr_pages() contiguous swap entries starting at folio->swap, so a page's swap entry is just folio->swap plus the page's index in the folio. The swap entry is folio state, but the only helper for it is page-based:page_swap_entry() takes a page and recomputes the folio its callers already hold. Several callers avoid it by open-coding the arithmetic on folio->swap instead.
Add folio_swap_entry() and folio_page_swap_entry(), convert all users, and remove page_swap_entry(), with a few other cleanups along the way.
---
Changes in v2:
- Keep the swap entry computation in __split_folio_to_order() open-coded
and add a comment, per Zi Yan.
- Reduce the zswap patch to using folio_swap_entry(), as the folio
conversion landed separately.
- Link to v1: https://patch.msgid.link/[email protected]
---
Tal Zussman (8):
mm/swap: add folio_swap_entry() and folio_page_swap_entry() mm/huge_memory: add a comment to the open-coded swap entry mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio() mm/zswap: use folio_swap_entry() in zswap_store_page() mm/swapfile: use folio_page_swap_entry()
arm64: mte: make mte_save_tags() and mte_restore_tags() static
arm64: mte: pass the swap entry to mte_save_tags() mm/swap: remove page_swap_entry()
arch/arm64/include/asm/mte.h | 2 -- arch/arm64/mm/mteswap.c | 32 ++++++++++++++------------------ include/linux/swap.h | 30 +++++++++++++++++++++++++++--- mm/huge_memory.c | 4 ++++ mm/rmap.c | 2 +- mm/swapfile.c | 4 ++-- mm/zswap.c | 3 +-- 7 files changed, 49 insertions(+), 28 deletions(-)
---
base-commit: 9d3243fc689fef444f87e0a703b4c99653137e1b
change-id: 20260807-folio_swap_entry-e53d68610de0
Best regards,
Signature · 1 line
Tal Zussman <[email protected]>
PATCH v2 1/8 mm/swap: add folio_swap_entry() and folio_page_swap_entry()
A folio in the swap cache occupies folio_nr_pages() contiguous swap entries starting at folio->swap, so a page's swap entry is just folio->swap plus the page's index in the folio. page_swap_entry() hides this behind a compound_head() call, and callers that already have the folio sometimes open-code the arithmetic instead.
Add folio_swap_entry(), which takes a folio and a page index, and folio_page_swap_entry() for callers that have the page.
--- include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
include/linux/swap.h +33 -0
@@ -272,6 +272,39 @@ struct swap_info_struct {const struct swap_ops *ops; }; +/** +* folio_swap_entry - Return the swap entry for a page within a folio. +* @folio: The folio. +* @idx: The index of the page within the folio. +* +* A folio in the swap cache occupies folio_nr_pages() contiguous swap +* entries starting at folio->swap. The caller must ensure the folio is +* in the swap cache and that @idx is within the folio. +*/ +static inline +swp_entry_t folio_swap_entry (const struct folio *folio,unsigned long idx) +{ +swp_entry_t entry = folio->swap; + +VM_WARN_ON_ONCE_FOLIO (idx >=folio_nr_pages (folio), folio); + entry.val += idx; +return entry; +} + +/** +* folio_page_swap_entry - Return the swap entry of a page in a folio. +* @folio: The folio containing @page. +* @page: A page within @folio. +* +* The caller must ensure the folio is in the swap cache and that @page +* is part of @folio. +*/ +static inline swp_entry_t folio_page_swap_entry (const struct folio *folio, +const struct page *page) +{ +return folio_swap_entry (folio,folio_page_idx (folio, page)); +} +static inline swp_entry_t page_swap_entry (struct page *page) {struct folio *folio =page_folio (page);
Signature · 1 line
2.39.5
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
Quoted 49 lines · Tal Zussman
A folio in the swap cache occupies
folio_nr_pages()contiguous swap entries starting atfolio->swap, so a page's swap entry is justfolio->swapplus the page's index in the folio.page_swap_entry()hides this behind acompound_head()call, and callers that already have the folio sometimes open-code the arithmetic instead.Add
folio_swap_entry(), which takes a folio and a page index, andfolio_page_swap_entry()for callers that have the page.Signed-off-by Tal Zussman <[email protected]>--- include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)include/linux/swap.h +26
-0@@ -272,6 +272,39 @@ struct swap_info_struct {const struct swap_ops *ops; }; +/** +* folio_swap_entry - Return the swap entry for a page within a folio. +* @folio: The folio. +* @idx: The index of the page within the folio. +* +* A folio in the swap cache occupies folio_nr_pages() contiguous swap +* entries starting at folio->swap. The caller must ensure the folio is +* in the swap cache and that @idx is within the folio. +*/ +static inline +swp_entry_t folio_swap_entry (const struct folio *folio,unsigned long idx) +{ +swp_entry_t entry = folio->swap; + +VM_WARN_ON_ONCE_FOLIO (idx >=folio_nr_pages (folio), folio); + entry.val += idx; +return entry; +} + +/** +* folio_page_swap_entry - Return the swap entry of a page in a folio. +* @folio: The folio containing @page. +* @page: A page within @folio. +* +* The caller must ensure the folio is in the swap cache and that @page +* is part of @folio.
include/linux/swap.h struct swap_info_struct { · line 310
Quoted 10 lines
include/linux/swap.h +7
-0+*/ +static inline swp_entry_t folio_page_swap_entry (const struct folio *folio, +const struct page *page) +{ +return folio_swap_entry (folio,folio_page_idx (folio, page)); +} +static inline swp_entry_t page_swap_entry (struct page *page) {struct folio *folio =page_folio (page);
"Return the swap entry for a page within a folio" vs. "Return the swap entry of a page in a folio."
yet only of the variants has a "page" in the name :)
A bit confusing.
Not immediately sure how it could be done cleaner. The minority of cases seem to use folio_swap_entry.
Signature · 3 lines
Cheers, David
Re: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
Quoted 64 lines · David Hildenbrand (Arm)
Quoted 49 lines · Tal Zussman
A folio in the swap cache occupies
folio_nr_pages()contiguous swap entries starting atfolio->swap, so a page's swap entry is justfolio->swapplus the page's index in the folio.page_swap_entry()hides this behind acompound_head()call, and callers that already have the folio sometimes open-code the arithmetic instead.Add
folio_swap_entry(), which takes a folio and a page index, andfolio_page_swap_entry()for callers that have the page.Signed-off-by Tal Zussman <[email protected]>--- include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)include/linux/swap.h +26
-0@@ -272,6 +272,39 @@ struct swap_info_struct {const struct swap_ops *ops; }; +/** +* folio_swap_entry - Return the swap entry for a page within a folio. +* @folio: The folio. +* @idx: The index of the page within the folio. +* +* A folio in the swap cache occupies folio_nr_pages() contiguous swap +* entries starting at folio->swap. The caller must ensure the folio is +* in the swap cache and that @idx is within the folio. +*/ +static inline +swp_entry_t folio_swap_entry (const struct folio *folio,unsigned long idx) +{ +swp_entry_t entry = folio->swap; + +VM_WARN_ON_ONCE_FOLIO (idx >=folio_nr_pages (folio), folio); + entry.val += idx; +return entry; +} + +/** +* folio_page_swap_entry - Return the swap entry of a page in a folio. +* @folio: The folio containing @page. +* @page: A page within @folio. +* +* The caller must ensure the folio is in the swap cache and that @page +* is part of @folio. include/linux/swap.h struct swap_info_struct { · line 310
Quoted 10 lines
include/linux/swap.h +7
-0+*/ +static inline swp_entry_t folio_page_swap_entry (const struct folio *folio, +const struct page *page) +{ +return folio_swap_entry (folio,folio_page_idx (folio, page)); +} +static inline swp_entry_t page_swap_entry (struct page *page) {struct folio *folio =page_folio (page);"Return the swap entry for a page within a folio" vs. "Return the swap entry of a page in a folio."
Quoted 7 lines
yet only of the variants has a "page" in the name :)
A bit confusing.
Not immediately sure how it could be done cleaner. The minority of cases seem to use
folio_swap_entry.
Yeah... I considered naming them folio_swap_entry() and folio_swap_entry_idx() (or a variant of that) but I liked the page version more. I can update the comments to try to differentiate between the two a little more if that would help. How's "Return the swap entry at an index within a folio"?
Quoted 5 lines
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
Quoted 69 lines · Tal Zussman
Quoted 68 lines · David Hildenbrand (Arm)
Quoted 49 lines · Tal Zussman
A folio in the swap cache occupies
folio_nr_pages()contiguous swap entries starting atfolio->swap, so a page's swap entry is justfolio->swapplus the page's index in the folio.page_swap_entry()hides this behind acompound_head()call, and callers that already have the folio sometimes open-code the arithmetic instead.Add
folio_swap_entry(), which takes a folio and a page index, andfolio_page_swap_entry()for callers that have the page.Signed-off-by Tal Zussman <[email protected]>--- include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)include/linux/swap.h +26
-0@@ -272,6 +272,39 @@ struct swap_info_struct {const struct swap_ops *ops; }; +/** +* folio_swap_entry - Return the swap entry for a page within a folio. +* @folio: The folio. +* @idx: The index of the page within the folio. +* +* A folio in the swap cache occupies folio_nr_pages() contiguous swap +* entries starting at folio->swap. The caller must ensure the folio is +* in the swap cache and that @idx is within the folio. +*/ +static inline +swp_entry_t folio_swap_entry (const struct folio *folio,unsigned long idx) +{ +swp_entry_t entry = folio->swap; + +VM_WARN_ON_ONCE_FOLIO (idx >=folio_nr_pages (folio), folio); + entry.val += idx; +return entry; +} + +/** +* folio_page_swap_entry - Return the swap entry of a page in a folio. +* @folio: The folio containing @page. +* @page: A page within @folio. +* +* The caller must ensure the folio is in the swap cache and that @page +* is part of @folio. include/linux/swap.h struct swap_info_struct { · line 310
Quoted 10 lines
include/linux/swap.h +7
-0+*/ +static inline swp_entry_t folio_page_swap_entry (const struct folio *folio, +const struct page *page) +{ +return folio_swap_entry (folio,folio_page_idx (folio, page)); +} +static inline swp_entry_t page_swap_entry (struct page *page) {struct folio *folio =page_folio (page);"Return the swap entry for a page within a folio" vs. "Return the swap entry of a page in a folio."
yet only of the variants has a "page" in the name :)
A bit confusing.
Quoted 9 lines
Quoted 3 lines
Not immediately sure how it could be done cleaner. The minority of cases seem to use
folio_swap_entry.Yeah... I considered naming them
folio_swap_entry()andfolio_swap_entry_idx()(or a variant of that) but I liked the page version more. I can update the comments to try to differentiate between the two a little more if that would help. How's "Return the swap entry at an index within a folio"?
I guess we should call it "page index" in the doc.
Signature · 3 lines
Cheers, David
Re: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
Andrew, could you please apply this as a fix patch?
-- >8 --
Subject: [PATCH] mm/swap: adjust the folio_swap_entry() kerneldoc summary
--- include/linux/swap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/swap.h +1 -1
@@ -273,7 +273,7 @@ struct swap_info_struct { };/** -* folio_swap_entry - Return the swap entry for a page within a folio. +* folio_swap_entry - Return the swap entry at a page index within a folio. * @folio: The folio. * @idx: The index of the page within the folio. *
Signature · 1 line
2.39.5
Re: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
Quoted 15 lines · Tal Zussman
Andrew, could you please apply this as a fix patch?
-- >8 --
Subject: [PATCH] mm/swap: adjust thefolio_swap_entry()kerneldoc summarySigned-off-by Tal Zussman <[email protected]>--- include/linux/swap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/swap.h +0
-0
include/linux/swap.h struct swap_info_struct { · line 279
Quoted 8 lines
include/linux/swap.h +1
-1@@ -273,7 +273,7 @@ struct swap_info_struct { };/** -* folio_swap_entry - Return the swap entry for a page within a folio. +* folio_swap_entry - Return the swap entry at a page index within a folio. * @folio: The folio. * @idx: The index of the page within the folio. *
Signature · 3 lines
Cheers, David
PATCH v2 2/8 mm/huge_memory: add a comment to the open-coded swap entry
In reply to Tal ZussmanThe swap entry of each new folio in __split_folio_to_order() is computed by hand from folio->swap rather than with folio_swap_entry(), because the folio's page count is not valid while it is being split. Add a comment explaining this.
--- mm/huge_memory.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/huge_memory.c +4 -0
@@ -3763,6 +3763,10 @@ static void __split_folio_to_order(struct folio *folio, int old_order,*/ VM_WARN_ON_ONCE_PAGE (new_folio->private, new_head); +/* +* Not all folio fields are valid during a split, so open-code +* the swap entry rather than using folio_swap_entry(). +*/ if (folio_test_swapcache (folio)) new_folio->swap.val = folio->swap.val + i;
Signature · 1 line
2.39.5
Re: [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry
Quoted 15 lines · Tal Zussman
The swap entry of each new folio in
__split_folio_to_order()is computed by hand fromfolio->swaprather than withfolio_swap_entry(), because the folio's page count is not valid while it is being split. Add a comment explaining this.Signed-off-by Tal Zussman <[email protected]>--- mm/huge_memory.c | 4 ++++ 1 file changed, 4 insertions(+)mm/huge_memory.c +0
-0
mm/huge_memory.c static void __split_folio_to_order(struct folio *folio, int old_order, · line 3772
Quoted 10 lines
mm/huge_memory.c +4
-0@@ -3763,6 +3763,10 @@ static void __split_folio_to_order(struct folio *folio, int old_order,*/ VM_WARN_ON_ONCE_PAGE (new_folio->private, new_head); +/* +* Not all folio fields are valid during a split, so open-code +* the swap entry rather than using folio_swap_entry(). +*/ if (folio_test_swapcache (folio)) new_folio->swap.val = folio->swap.val + i;
LGTM.
Signature · 2 lines
Best Regards, Yan, Zi
Re: [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry
In reply to Tal ZussmanQuoted 16 lines · Tal Zussman
The swap entry of each new folio in
__split_folio_to_order()is computed by hand fromfolio->swaprather than withfolio_swap_entry(), because the folio's page count is not valid while it is being split. Add a comment explaining this.Signed-off-by Tal Zussman <[email protected]>--- mm/huge_memory.c | 4 ++++ 1 file changed, 4 insertions(+)mm/huge_memory.c +0
-0
mm/huge_memory.c static void __split_folio_to_order(struct folio *folio, int old_order, · line 3772
Quoted 10 lines
mm/huge_memory.c +4
-0@@ -3763,6 +3763,10 @@ static void __split_folio_to_order(struct folio *folio, int old_order,*/ VM_WARN_ON_ONCE_PAGE (new_folio->private, new_head); +/* +* Not all folio fields are valid during a split, so open-code +* the swap entry rather than using folio_swap_entry(). +*/ if (folio_test_swapcache (folio)) new_folio->swap.val = folio->swap.val + i;
Signature · 3 lines
Cheers, David
PATCH v2 3/8 mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio()
In reply to Tal ZussmanWe already have the folio here, so use folio_page_swap_entry() instead of going through page_swap_entry(). This saves a call to compound_head().
No functional change.
--- mm/rmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/rmap.c +1 -1
@@ -2147,7 +2147,7 @@ static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma, {const bool anon_exclusive =folio_test_anon (folio) &&PageAnonExclusive (page); -swp_entry_t entry =page_swap_entry (page); +swp_entry_t entry =folio_page_swap_entry (folio, page);struct mm_struct *mm = vma->vm_mm;if (folio_dup_swap (folio, page) <0 )
Signature · 1 line
2.39.5
Re: [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio()
Quoted 8 lines · Tal Zussman
We already have the folio here, so use
folio_page_swap_entry()instead of going throughpage_swap_entry(). This saves a call tocompound_head().No functional change.
Signed-off-by Tal Zussman <[email protected]>---
Signature · 3 lines
Cheers, David
PATCH v2 4/8 mm/zswap: use folio_swap_entry() in zswap_store_page()
In reply to Tal Zussmanzswap_store_page() open-codes the swap entry computation from folio->swap and the page index. Use folio_swap_entry() instead.
No functional change.
--- mm/zswap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/zswap.c +1 -2
@@ -1398,8 +1398,7 @@ static bool zswap_store_page(struct folio *folio, long index,struct obj_cgroup *objcg, struct zswap_pool *pool) { - swp_entry_t page_swpentry = swp_entry(swp_type(folio->swap), -swp_offset (folio->swap) + index); + swp_entry_t page_swpentry = folio_swap_entry(folio, index);struct zswap_entry *entry, *old;/* allocate entry */
Signature · 1 line
2.39.5
Re: [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page()
Quoted 16 lines · Tal Zussman
zswap_store_page()open-codes the swap entry computation fromfolio->swapand the page index. Usefolio_swap_entry()instead.No functional change.
Signed-off-by Tal Zussman <[email protected]>--- mm/zswap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/zswap.c +0
-0
mm/zswap.c static bool zswap_store_page(struct folio *folio, long index, · line 1404
Quoted 9 lines
mm/zswap.c +1
-2@@ -1398,8 +1398,7 @@ static bool zswap_store_page(struct folio *folio, long index,struct obj_cgroup *objcg, struct zswap_pool *pool) { - swp_entry_t page_swpentry = swp_entry(swp_type(folio->swap), -swp_offset (folio->swap) + index); + swp_entry_t page_swpentry = folio_swap_entry(folio, index);struct zswap_entry *entry, *old;/* allocate entry */
Signature · 3 lines
Cheers, David
PATCH v2 5/8 mm/swapfile: use folio_page_swap_entry()
In reply to Tal Zussmanfolio_dup_swap() and folio_put_swap() open-code the swap entry computation from folio->swap and folio_page_idx(). Use folio_page_swap_entry() instead.
No functional change.
--- mm/swapfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/swapfile.c +2 -2
@@ -1822,7 +1822,7 @@ int folio_dup_swap(struct folio *folio, struct page *page)VM_WARN_ON_FOLIO (!folio_test_swapcache (folio), folio);if (page) { - entry.val +=folio_page_idx (folio, page); + entry =folio_page_swap_entry (folio, page); nr_pages =1 ; }
@@ -1849,7 +1849,7 @@ void folio_put_swap(struct folio *folio, struct page *page)VM_WARN_ON_FOLIO (!folio_test_swapcache (folio), folio);if (page) { - entry.val +=folio_page_idx (folio, page); + entry =folio_page_swap_entry (folio, page); nr_pages =1 ; }
Signature · 1 line
2.39.5
Re: [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry()
Quoted 8 lines · Tal Zussman
folio_dup_swap()andfolio_put_swap()open-code the swap entry computation fromfolio->swapandfolio_page_idx(). Usefolio_page_swap_entry()instead.No functional change.
Signed-off-by Tal Zussman <[email protected]>---
Signature · 3 lines
Cheers, David
PATCH v2 6/8 arm64: mte: make mte_save_tags() and mte_restore_tags() static
In reply to Tal Zussmanmte_save_tags() and mte_restore_tags() are only used by arch_prepare_to_swap() and arch_swap_restore() in mteswap.c. Make them static and remove their declarations from mte.h.
No functional change.
--- arch/arm64/include/asm/mte.h | 2 -- arch/arm64/mm/mteswap.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/arm64/include/asm/mte.h +0 -2
@@ -23,9 +23,7 @@ unsigned long mte_copy_tags_from_user(void *to, const void __user *from, unsigned long n);unsigned long mte_copy_tags_to_user (void __user *to,void *from,unsigned long n); -int mte_save_tags (struct page *page);void mte_save_page_tags (const void *page_addr,void *tag_storage); -void mte_restore_tags (swp_entry_t entry,struct page *page);void mte_restore_page_tags (void *page_addr,const void *tag_storage);void mte_invalidate_tags (int type,pgoff_t offset);void mte_invalidate_tags_area (int type);
arch/arm64/mm/mteswap.c +2 -2
@@ -20,7 +20,7 @@ void mte_free_tag_storage(char *storage)kfree (storage); } -int mte_save_tags (struct page *page) +static int mte_save_tags (struct page *page) {void *tag_storage, *ret;
@@ -47,7 +47,7 @@ int mte_save_tags(struct page *page)return 0 ; } -void mte_restore_tags (swp_entry_t entry,struct page *page) +static void mte_restore_tags (swp_entry_t entry,struct page *page) {void *tags =xa_load (&mte_pages, entry.val);
Signature · 1 line
2.39.5
Re: [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static
Quoted 8 lines · Tal Zussman
mte_save_tags()andmte_restore_tags()are only used byarch_prepare_to_swap()andarch_swap_restore()inmteswap.c. Make them static and remove their declarations frommte.h.No functional change.
Signed-off-by Tal Zussman <[email protected]>---
Signature · 3 lines
Cheers, David
PATCH v2 7/8 arm64: mte: pass the swap entry to mte_save_tags()
In reply to Tal Zussmanarch_prepare_to_swap() derives a page from the folio only for mte_save_tags() to recompute the folio's swap entry from that page. Pass the entry in directly with folio_swap_entry(), matching mte_restore_tags(), and move the page_mte_tagged() check into the caller so we only compute the entry for tagged pages.
__mte_invalidate_tags() loses its only user, so remove it and call mte_invalidate_tags() directly in the error path. This removes two calls to compound_head().
No functional change.
--- arch/arm64/mm/mteswap.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
arch/arm64/mm/mteswap.c +13 -17
@@ -20,22 +20,17 @@ void mte_free_tag_storage(char *storage)kfree (storage); } -static int mte_save_tags (struct page *page) +static int mte_save_tags (swp_entry_t entry,struct page *page) {void *tag_storage, *ret; -if (!page_mte_tagged (page)) -return 0 ; - tag_storage =mte_allocate_tag_storage ();if (!tag_storage)return -ENOMEM ;mte_save_page_tags (page_address (page), tag_storage); -/* lookup the swap entry.val from the page */ - ret =xa_store (&mte_pages,page_swap_entry (page).val, tag_storage, -GFP_KERNEL ); + ret =xa_store (&mte_pages, entry.val, tag_storage,GFP_KERNEL );if (WARN (xa_is_err (ret),"Failed to store MTE tags" )) {mte_free_tag_storage (tag_storage);return xa_err (ret);
@@ -68,13 +63,6 @@ void mte_invalidate_tags(int type, pgoff_t offset)mte_free_tag_storage (tags); } -static inline void __mte_invalidate_tags (struct page *page) -{ -swp_entry_t entry =page_swap_entry (page); - -mte_invalidate_tags (swp_type (entry),swp_offset (entry)); -} -void mte_invalidate_tags_area (int type) {swp_entry_t entry =swp_entry (type,0 );
@@ -102,15 +90,23 @@ int arch_prepare_to_swap(struct folio *folio) nr =folio_nr_pages (folio);for (i =0 ; i < nr; i++) { - err =mte_save_tags (folio_page (folio, i)); +struct page *page =folio_page (folio, i); + +if (!page_mte_tagged (page)) +continue ; + + err =mte_save_tags (folio_swap_entry (folio, i), page);if (err) goto out; }return 0 ; out: -while (i--) -__mte_invalidate_tags (folio_page (folio, i)); +while (i--) { +swp_entry_t swap =folio_swap_entry (folio, i); + +mte_invalidate_tags (swp_type (swap),swp_offset (swap)); + }return err; }
Signature · 1 line
2.39.5
Re: [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags()
Quoted 6 lines · Tal Zussman
arch_prepare_to_swap()derives a page from the folio only formte_save_tags()to recompute the folio's swap entry from that page. Pass the entry in directly withfolio_swap_entry(), matchingmte_restore_tags(), and move thepage_mte_tagged()check into the caller so we only compute the entry for tagged pages.
Quoted 8 lines
__mte_invalidate_tags()loses its only user, so remove it and callmte_invalidate_tags()directly in the error path. This removes two calls tocompound_head().No functional change.
Signed-off-by Tal Zussman <[email protected]>---
Signature · 3 lines
Cheers, David
PATCH v2 8/8 mm/swap: remove page_swap_entry()
In reply to Tal ZussmanAll callers have been converted to folio_swap_entry() and folio_page_swap_entry(), so remove it.
--- include/linux/swap.h | 9 --------- 1 file changed, 9 deletions(-)
include/linux/swap.h +0 -9
@@ -305,15 +305,6 @@ static inline swp_entry_t folio_page_swap_entry(const struct folio *folio,return folio_swap_entry (folio,folio_page_idx (folio, page)); } -static inline swp_entry_t page_swap_entry (struct page *page) -{ -struct folio *folio =page_folio (page); -swp_entry_t entry = folio->swap; - - entry.val +=folio_page_idx (folio, page); -return entry; -} -/* linux/mm/page_alloc.c */ extern unsigned long totalreserve_pages;
Signature · 1 line
2.39.5
Re: [PATCH v2 8/8] mm/swap: remove page_swap_entry()
Quoted 4 lines · Tal Zussman
All callers have been converted to
folio_swap_entry()andfolio_page_swap_entry(), so remove it.Signed-off-by Tal Zussman <[email protected]>
Signature · 3 lines
Cheers, David
Andrew Morton
maintainerQuoted 10 lines · On Tue, 08 Sep 2026 11:16:30 -0400 Tal Zussman <[email protected]> wrote:
A folio in the swap cache occupies
folio_nr_pages()contiguous swap entries starting atfolio->swap, so a page's swap entry is justfolio->swapplus the page's index in the folio. The swap entry is folio state, but the only helper for it is page-based:page_swap_entry()takes a page and recomputes the folio its callers already hold. Several callers avoid it by open-coding the arithmetic onfolio->swapinstead.Add
folio_swap_entry()andfolio_page_swap_entry(), convert all users, and removepage_swap_entry(), with a few other cleanups along the way.
Thanks, I'll queue this for testing and further review.