From: David Hildenbrand <david@redhat.com>
To: Kairui Song <kasong@tencent.com>, linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Hugh Dickins <hughd@google.com>, Chris Li <chrisl@kernel.org>,
Yosry Ahmed <yosryahmed@google.com>,
"Huang, Ying" <ying.huang@linux.alibaba.com>,
Nhat Pham <nphamcs@gmail.com>,
Johannes Weiner <hannes@cmpxchg.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 5/6] mm: move folio_index to mm/swap.h and remove no longer needed helper
Date: Tue, 29 Apr 2025 14:24:16 +0200 [thread overview]
Message-ID: <78487605-8b83-4b77-8147-9e34e4f8fda2@redhat.com> (raw)
In-Reply-To: <20250429114949.41124-6-ryncsn@gmail.com>
On 29.04.25 13:49, Kairui Song wrote:
> From: Kairui Song <kasong@tencent.com>
>
> There are no remaining users of folio_index() outside the mm subsystem.
> Move it to mm/swap.h to co-locate it with swap_cache_index(), eliminating
> a forward declaration, and a function call overhead.
>
> Also remove the helper that was used to fix circular header dependency
> issue.
>
> Signed-off-by: Kairui Song <kasong@tencent.com>
> ---
> include/linux/pagemap.h | 20 --------------------
> mm/memfd.c | 1 +
> mm/migrate.c | 1 +
> mm/swap.h | 23 +++++++++++++++++++++++
> mm/swapfile.c | 6 ------
> 5 files changed, 25 insertions(+), 26 deletions(-)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 1dc3416a9c0d..47b5746d5a65 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -884,26 +884,6 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping,
> mapping_gfp_mask(mapping));
> }
>
> -extern pgoff_t __folio_swap_cache_index(struct folio *folio);
> -
> -/**
> - * folio_index - File index of a folio.
> - * @folio: The folio.
> - *
> - * For a folio which is either in the page cache or the swap cache,
> - * return its index within the address_space it belongs to. If you know
> - * the page is definitely in the page cache, you can look at the folio's
> - * index directly.
> - *
> - * Return: The index (offset in units of pages) of a folio in its file.
> - */
> -static inline pgoff_t folio_index(struct folio *folio)
> -{
> - if (unlikely(folio_test_swapcache(folio)))
> - return __folio_swap_cache_index(folio);
> - return folio->index;
> -}
> -
> /**
> * folio_next_index - Get the index of the next folio.
> * @folio: The current folio.
> diff --git a/mm/memfd.c b/mm/memfd.c
> index c64df1343059..ab367e61553d 100644
> --- a/mm/memfd.c
> +++ b/mm/memfd.c
> @@ -20,6 +20,7 @@
> #include <linux/memfd.h>
> #include <linux/pid_namespace.h>
> #include <uapi/linux/memfd.h>
> +#include "swap.h"
>
> /*
> * We need a tag: a new tag would expand every xa_node by 8 bytes,
> diff --git a/mm/migrate.c b/mm/migrate.c
> index f3ee6d8d5e2e..662e5dc44b33 100644
> --- a/mm/migrate.c
> +++ b/mm/migrate.c
> @@ -50,6 +50,7 @@
> #include <trace/events/migrate.h>
>
> #include "internal.h"
> +#include "swap.h"
>
> bool isolate_movable_page(struct page *page, isolate_mode_t mode)
> {
> diff --git a/mm/swap.h b/mm/swap.h
> index 6f4a3f927edb..91439d0ce50b 100644
> --- a/mm/swap.h
> +++ b/mm/swap.h
> @@ -50,6 +50,24 @@ static inline pgoff_t swap_cache_index(swp_entry_t entry)
> return swp_offset(entry) & SWAP_ADDRESS_SPACE_MASK;
> }
>
> +/**
> + * folio_index - File index of a folio.
> + * @folio: The folio.
> + *
> + * For a folio which is either in the page cache or the swap cache,
> + * return its index within the address_space it belongs to. If you know
> + * the folio is definitely in the page cache, you can look at the folio's
> + * index directly.
> + *
> + * Return: The index (offset in units of pages) of a folio in its file.
> + */
> +static inline pgoff_t folio_index(struct folio *folio)
> +{
> + if (unlikely(folio_test_swapcache(folio)))
> + return swap_cache_index(folio->swap);
> + return folio->index;
> +}
> +
> void show_swap_cache_info(void);
> void *get_shadow_from_swap_cache(swp_entry_t entry);
> int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
> @@ -125,6 +143,11 @@ static inline pgoff_t swap_cache_index(swp_entry_t entry)
> return 0;
> }
>
> +static inline pgoff_t folio_index(struct folio *folio)
> +{
> + return folio->index;
> +}
> +
Could we just have a single generic function that does something like:
static inline pgoff_t folio_index(struct folio *folio)
{
if (unlikely(IS_ENABLED(CONFIG_SWAP) &&
folio_test_swapcache(folio)))
return swap_cache_index(folio->swap);
return folio->index;
}
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-04-29 12:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 11:49 [PATCH v2 0/6] mm, swap: clean up swap cache mapping helper Kairui Song
2025-04-29 11:49 ` [PATCH v2 1/6] fuse: drop usage of folio_index Kairui Song
2025-04-29 11:49 ` [PATCH v2 2/6] btrfs: " Kairui Song
2025-04-29 11:49 ` [PATCH v2 3/6] f2fs: " Kairui Song
2025-06-09 20:56 ` [f2fs-dev] " patchwork-bot+f2fs
2025-04-29 11:49 ` [PATCH v2 4/6] filemap: do not use folio_contains for swap cache folios Kairui Song
2025-04-29 12:22 ` David Hildenbrand
2025-04-29 13:32 ` Kairui Song
2025-04-29 13:43 ` David Hildenbrand
2025-04-29 11:49 ` [PATCH v2 5/6] mm: move folio_index to mm/swap.h and remove no longer needed helper Kairui Song
2025-04-29 12:24 ` David Hildenbrand [this message]
2025-04-29 13:35 ` Kairui Song
2025-04-29 11:49 ` [PATCH v2 6/6] mm, swap: remove no longer used swap mapping helper Kairui Song
2025-04-29 12:24 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78487605-8b83-4b77-8147-9e34e4f8fda2@redhat.com \
--to=david@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox