* [PATCH v2 0/8] mm: remove page_swap_entry()
@ 2026-09-08 15:16 Tal Zussman
2026-09-08 15:16 ` [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry() Tal Zussman
` (8 more replies)
0 siblings, 9 replies; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
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/20260830-folio_swap_entry-v1-0-7786b52acbc8@columbia.edu
---
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,
--
Tal Zussman <tz2294@columbia.edu>
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry Tal Zussman
` (7 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
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.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index fc290e29e4a9..1d979e76e78a 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -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);
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
2026-09-08 15:16 ` [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry() Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-08 15:26 ` Zi Yan
2026-09-09 13:52 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio() Tal Zussman
` (6 subsequent siblings)
8 siblings, 2 replies; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
The 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.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/huge_memory.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index d1ce061601bc..1fabdcbd8c8f 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -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;
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
2026-09-08 15:16 ` [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry() Tal Zussman
2026-09-08 15:16 ` [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page() Tal Zussman
` (5 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
We 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.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/rmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/rmap.c b/mm/rmap.c
index 5fefe5b060b1..193e1264b631 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -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)
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
` (2 preceding siblings ...)
2026-09-08 15:16 ` [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio() Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry() Tal Zussman
` (4 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
zswap_store_page() open-codes the swap entry computation from
folio->swap and the page index. Use folio_swap_entry() instead.
No functional change.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/zswap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index 5d0d8bd72193..c27e22d067e3 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -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 */
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
` (3 preceding siblings ...)
2026-09-08 15:16 ` [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page() Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:01 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static Tal Zussman
` (3 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
folio_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.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
mm/swapfile.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 869a918b18e8..0a3a3b2218c7 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -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;
}
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
` (4 preceding siblings ...)
2026-09-08 15:16 ` [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry() Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:01 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags() Tal Zussman
` (2 subsequent siblings)
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
mte_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.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
arch/arm64/include/asm/mte.h | 2 --
arch/arm64/mm/mteswap.c | 4 ++--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h
index 7f7b97e09996..83f3b05fc784 100644
--- a/arch/arm64/include/asm/mte.h
+++ b/arch/arm64/include/asm/mte.h
@@ -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);
diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c
index 63e8d72f202a..3c54afc8b758 100644
--- a/arch/arm64/mm/mteswap.c
+++ b/arch/arm64/mm/mteswap.c
@@ -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);
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
` (5 preceding siblings ...)
2026-09-08 15:16 ` [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:06 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 8/8] mm/swap: remove page_swap_entry() Tal Zussman
2026-09-08 17:55 ` [PATCH v2 0/8] mm: " Andrew Morton
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
arch_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.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
arch/arm64/mm/mteswap.c | 30 +++++++++++++-----------------
1 file changed, 13 insertions(+), 17 deletions(-)
diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c
index 3c54afc8b758..f64202b69309 100644
--- a/arch/arm64/mm/mteswap.c
+++ b/arch/arm64/mm/mteswap.c
@@ -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;
}
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 8/8] mm/swap: remove page_swap_entry()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
` (6 preceding siblings ...)
2026-09-08 15:16 ` [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags() Tal Zussman
@ 2026-09-08 15:16 ` Tal Zussman
2026-09-09 14:06 ` David Hildenbrand (Arm)
2026-09-08 17:55 ` [PATCH v2 0/8] mm: " Andrew Morton
8 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-08 15:16 UTC (permalink / raw)
To: Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel, Tal Zussman
All callers have been converted to folio_swap_entry() and
folio_page_swap_entry(), so remove it.
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
include/linux/swap.h | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 1d979e76e78a..8032a0f3c319 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -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;
--
2.39.5
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry
2026-09-08 15:16 ` [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry Tal Zussman
@ 2026-09-08 15:26 ` Zi Yan
2026-09-09 13:52 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 21+ messages in thread
From: Zi Yan @ 2026-09-08 15:26 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park,
David Hildenbrand, Baolin Wang, Liam R. Howlett, Nico Pache,
Ryan Roberts, Dev Jain, Lance Yang, Usama Arif, Kiryl Shutsemau,
Lorenzo Stoakes, Rik van Riel, Vlastimil Babka, Harry Yoo,
Jann Horn, Johannes Weiner, Yosry Ahmed, Chengming Zhou,
Catalin Marinas, Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On Tue Sep 8, 2026 at 11:16 AM EDT, Tal Zussman wrote:
> The 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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
> mm/huge_memory.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index d1ce061601bc..1fabdcbd8c8f 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -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.
Reviewed-by: Zi Yan <ziy@nvidia.com>
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 0/8] mm: remove page_swap_entry()
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
` (7 preceding siblings ...)
2026-09-08 15:16 ` [PATCH v2 8/8] mm/swap: remove page_swap_entry() Tal Zussman
@ 2026-09-08 17:55 ` Andrew Morton
8 siblings, 0 replies; 21+ messages in thread
From: Andrew Morton @ 2026-09-08 17:55 UTC (permalink / raw)
To: Tal Zussman
Cc: Chris Li, Kairui Song, Kemeng Shi, Nhat Pham, Baoquan He,
Barry Song, Youngjun Park, David Hildenbrand, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland, linux-mm, linux-kernel,
linux-arm-kernel
On Tue, 08 Sep 2026 11:16:30 -0400 Tal Zussman <tz2294@columbia.edu> wrote:
> 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.
Thanks, I'll queue this for testing and further review.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry
2026-09-08 15:16 ` [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry Tal Zussman
2026-09-08 15:26 ` Zi Yan
@ 2026-09-09 13:52 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 13:52 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> The 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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
> mm/huge_memory.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index d1ce061601bc..1fabdcbd8c8f 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -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;
>
>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
2026-09-08 15:16 ` [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry() Tal Zussman
@ 2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-09 17:21 ` Tal Zussman
0 siblings, 1 reply; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:00 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> 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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
> include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index fc290e29e4a9..1d979e76e78a 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -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);
>
"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.
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio()
2026-09-08 15:16 ` [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio() Tal Zussman
@ 2026-09-09 14:00 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:00 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> We 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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page()
2026-09-08 15:16 ` [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page() Tal Zussman
@ 2026-09-09 14:00 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:00 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> zswap_store_page() open-codes the swap entry computation from
> folio->swap and the page index. Use folio_swap_entry() instead.
>
> No functional change.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
> mm/zswap.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 5d0d8bd72193..c27e22d067e3 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -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 */
>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry()
2026-09-08 15:16 ` [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry() Tal Zussman
@ 2026-09-09 14:01 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:01 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> folio_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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static
2026-09-08 15:16 ` [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static Tal Zussman
@ 2026-09-09 14:01 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:01 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> mte_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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags()
2026-09-08 15:16 ` [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags() Tal Zussman
@ 2026-09-09 14:06 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:06 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> arch_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.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 8/8] mm/swap: remove page_swap_entry()
2026-09-08 15:16 ` [PATCH v2 8/8] mm/swap: remove page_swap_entry() Tal Zussman
@ 2026-09-09 14:06 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 14:06 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/8/26 17:16, Tal Zussman wrote:
> All callers have been converted to folio_swap_entry() and
> folio_page_swap_entry(), so remove it.
>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
2026-09-09 14:00 ` David Hildenbrand (Arm)
@ 2026-09-09 17:21 ` Tal Zussman
2026-09-09 17:25 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 21+ messages in thread
From: Tal Zussman @ 2026-09-09 17:21 UTC (permalink / raw)
To: David Hildenbrand (Arm),
Andrew Morton, Chris Li, Kairui Song, Kemeng Shi, Nhat Pham,
Baoquan He, Barry Song, Youngjun Park, Zi Yan, Baolin Wang,
Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain, Lance Yang,
Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes, Rik van Riel,
Vlastimil Babka, Harry Yoo, Jann Horn, Johannes Weiner,
Yosry Ahmed, Chengming Zhou, Catalin Marinas, Will Deacon,
Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/9/26 5:00 PM, David Hildenbrand (Arm) wrote:
> On 9/8/26 17:16, Tal Zussman wrote:
>> 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.
>>
>> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
>> ---
>> include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++
>> 1 file changed, 33 insertions(+)
>>
>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>> index fc290e29e4a9..1d979e76e78a 100644
>> --- a/include/linux/swap.h
>> +++ b/include/linux/swap.h
>> @@ -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);
>>
>
> "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.
>
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"?
> --
> Cheers,
>
> David
>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry()
2026-09-09 17:21 ` Tal Zussman
@ 2026-09-09 17:25 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-09 17:25 UTC (permalink / raw)
To: Tal Zussman, Andrew Morton, Chris Li, Kairui Song, Kemeng Shi,
Nhat Pham, Baoquan He, Barry Song, Youngjun Park, Zi Yan,
Baolin Wang, Liam R. Howlett, Nico Pache, Ryan Roberts, Dev Jain,
Lance Yang, Usama Arif, Kiryl Shutsemau, Lorenzo Stoakes,
Rik van Riel, Vlastimil Babka, Harry Yoo, Jann Horn,
Johannes Weiner, Yosry Ahmed, Chengming Zhou, Catalin Marinas,
Will Deacon, Mark Rutland
Cc: linux-mm, linux-kernel, linux-arm-kernel
On 9/9/26 19:21, Tal Zussman wrote:
> On 9/9/26 5:00 PM, David Hildenbrand (Arm) wrote:
>> On 9/8/26 17:16, Tal Zussman wrote:
>>> 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.
>>>
>>> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
>>> ---
>>> include/linux/swap.h | 33 +++++++++++++++++++++++++++++++++
>>> 1 file changed, 33 insertions(+)
>>>
>>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>>> index fc290e29e4a9..1d979e76e78a 100644
>>> --- a/include/linux/swap.h
>>> +++ b/include/linux/swap.h
>>> @@ -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);
>>>
>>
>> "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.
>>
>
> 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"?
>
I guess we should call it "page index" in the doc.
--
Cheers,
David
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-09-09 17:25 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 15:16 [PATCH v2 0/8] mm: remove page_swap_entry() Tal Zussman
2026-09-08 15:16 ` [PATCH v2 1/8] mm/swap: add folio_swap_entry() and folio_page_swap_entry() Tal Zussman
2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-09 17:21 ` Tal Zussman
2026-09-09 17:25 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 2/8] mm/huge_memory: add a comment to the open-coded swap entry Tal Zussman
2026-09-08 15:26 ` Zi Yan
2026-09-09 13:52 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 3/8] mm/rmap: use folio_page_swap_entry() in ttu_anon_swapbacked_folio() Tal Zussman
2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 4/8] mm/zswap: use folio_swap_entry() in zswap_store_page() Tal Zussman
2026-09-09 14:00 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 5/8] mm/swapfile: use folio_page_swap_entry() Tal Zussman
2026-09-09 14:01 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 6/8] arm64: mte: make mte_save_tags() and mte_restore_tags() static Tal Zussman
2026-09-09 14:01 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 7/8] arm64: mte: pass the swap entry to mte_save_tags() Tal Zussman
2026-09-09 14:06 ` David Hildenbrand (Arm)
2026-09-08 15:16 ` [PATCH v2 8/8] mm/swap: remove page_swap_entry() Tal Zussman
2026-09-09 14:06 ` David Hildenbrand (Arm)
2026-09-08 17:55 ` [PATCH v2 0/8] mm: " Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®