diff mbox series

[v4,11/12] mm: drop page_index and convert folio_index to use folio

Message ID 20240502084939.30250-4-ryncsn@gmail.com (mailing list archive)
State New
Headers show
Series mm/swap: clean up and optimize swap cache index | expand

Commit Message

Kairui Song May 2, 2024, 8:49 a.m. UTC
From: Kairui Song <kasong@tencent.com>

There are two helpers for retrieving the index within address space
for mixed usage of swap cache and page cache:

- page_index
- folio_index (wrapper of page_index)

This commit drops page_index, as we have eliminated all users, and
converts folio_index to use folio internally.

Signed-off-by: Kairui Song <kasong@tencent.com>
---
 include/linux/mm.h      | 13 -------------
 include/linux/pagemap.h |  8 ++++----
 mm/swapfile.c           |  7 +++----
 3 files changed, 7 insertions(+), 21 deletions(-)

Comments

David Hildenbrand May 2, 2024, 9:12 a.m. UTC | #1
On 02.05.24 10:49, Kairui Song wrote:
> From: Kairui Song <kasong@tencent.com>
> 
> There are two helpers for retrieving the index within address space
> for mixed usage of swap cache and page cache:
> 
> - page_index
> - folio_index (wrapper of page_index)
> 
> This commit drops page_index, as we have eliminated all users, and
> converts folio_index to use folio internally.

The latter does not make sense. folio_index() already is using a folio 
internally. Maybe a leftover from reshuffling/reworking patches?
Kairui Song May 2, 2024, 9:32 a.m. UTC | #2
On Thu, May 2, 2024 at 5:12 PM David Hildenbrand <david@redhat.com> wrote:
>
> On 02.05.24 10:49, Kairui Song wrote:
> > From: Kairui Song <kasong@tencent.com>
> >
> > There are two helpers for retrieving the index within address space
> > for mixed usage of swap cache and page cache:
> >
> > - page_index
> > - folio_index (wrapper of page_index)
> >
> > This commit drops page_index, as we have eliminated all users, and
> > converts folio_index to use folio internally.
>
> The latter does not make sense. folio_index() already is using a folio
> internally. Maybe a leftover from reshuffling/reworking patches?

Hi, David,

folio_index calls swapcache_index, and swapcache_index is defined as:

#define swapcache_index(folio) __page_file_index(&(folio)->page)

Where it casts the folio to page first, then call __page_file_index,
__page_file_index is a function and works on pages.

After this commit __page_file_index is converted to
__folio_swap_cache_index. This change is a bit of trivial but we get
rid of the internal page conversion.

I can simplify the commit message, just say drop page_index to make
the code cleaner, if this is confusing.
Kairui Song May 2, 2024, 9:38 a.m. UTC | #3
On Thu, May 2, 2024 at 5:32 PM Kairui Song <ryncsn@gmail.com> wrote:
>
> On Thu, May 2, 2024 at 5:12 PM David Hildenbrand <david@redhat.com> wrote:
> >
> > On 02.05.24 10:49, Kairui Song wrote:
> > > From: Kairui Song <kasong@tencent.com>
> > >
> > > There are two helpers for retrieving the index within address space
> > > for mixed usage of swap cache and page cache:
> > >
> > > - page_index
> > > - folio_index (wrapper of page_index)
> > >
> > > This commit drops page_index, as we have eliminated all users, and
> > > converts folio_index to use folio internally.
> >
> > The latter does not make sense. folio_index() already is using a folio
> > internally. Maybe a leftover from reshuffling/reworking patches?
>
> Hi, David,
>
> folio_index calls swapcache_index, and swapcache_index is defined as:
>
> #define swapcache_index(folio) __page_file_index(&(folio)->page)
>
> Where it casts the folio to page first, then call __page_file_index,
> __page_file_index is a function and works on pages.
>
> After this commit __page_file_index is converted to
> __folio_swap_cache_index. This change is a bit of trivial but we get
> rid of the internal page conversion.
>
> I can simplify the commit message, just say drop page_index to make
> the code cleaner, if this is confusing.

Ah, you are right folio_index is not a simple wrapper of page_index
indeed, that sentence in the commit message doesn't make sense, so it
should be deleted, my bad for this leftover.
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 9849dfda44d4..e2718cac0fda 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2290,19 +2290,6 @@  static inline void *folio_address(const struct folio *folio)
 	return page_address(&folio->page);
 }
 
-extern pgoff_t __page_file_index(struct page *page);
-
-/*
- * Return the pagecache index of the passed page.  Regular pagecache pages
- * use ->index whereas swapcache pages use swp_offset(->private)
- */
-static inline pgoff_t page_index(struct page *page)
-{
-	if (unlikely(PageSwapCache(page)))
-		return __page_file_index(page);
-	return page->index;
-}
-
 /*
  * Return true only if the page has been allocated with
  * ALLOC_NO_WATERMARKS and the low watermark was not
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index a324582ea702..0cfa5810cde3 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -778,7 +778,7 @@  static inline struct page *grab_cache_page_nowait(struct address_space *mapping,
 			mapping_gfp_mask(mapping));
 }
 
-#define swapcache_index(folio)	__page_file_index(&(folio)->page)
+extern pgoff_t __folio_swap_cache_index(struct folio *folio);
 
 /**
  * folio_index - File index of a folio.
@@ -793,9 +793,9 @@  static inline struct page *grab_cache_page_nowait(struct address_space *mapping,
  */
 static inline pgoff_t folio_index(struct folio *folio)
 {
-        if (unlikely(folio_test_swapcache(folio)))
-                return swapcache_index(folio);
-        return folio->index;
+	if (unlikely(folio_test_swapcache(folio)))
+		return __folio_swap_cache_index(folio);
+	return folio->index;
 }
 
 /**
diff --git a/mm/swapfile.c b/mm/swapfile.c
index f6ca215fb92f..0b0ae6e8c764 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3474,12 +3474,11 @@  struct address_space *swapcache_mapping(struct folio *folio)
 }
 EXPORT_SYMBOL_GPL(swapcache_mapping);
 
-pgoff_t __page_file_index(struct page *page)
+pgoff_t __folio_swap_cache_index(struct folio *folio)
 {
-	swp_entry_t swap = page_swap_entry(page);
-	return swp_offset(swap);
+	return swp_offset(folio->swap);
 }
-EXPORT_SYMBOL_GPL(__page_file_index);
+EXPORT_SYMBOL_GPL(__folio_swap_cache_index);
 
 /*
  * add_swap_count_continuation - called when a swap count is duplicated