linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nhat Pham <nphamcs@gmail.com>
To: Kairui Song <kasong@tencent.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	 "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	 Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
	Pedro Falcato <pfalcato@suse.de>,
	 Matthew Wilcox <willy@infradead.org>,
	Hugh Dickins <hughd@google.com>,
	 David Hildenbrand <david@redhat.com>,
	Chris Li <chrisl@kernel.org>, Barry Song <baohua@kernel.org>,
	 Baoquan He <bhe@redhat.com>,
	Kemeng Shi <shikemeng@huaweicloud.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/3] mm/mincore, swap: consolidate swap cache checking for mincore
Date: Thu, 7 Aug 2025 11:06:44 -0700	[thread overview]
Message-ID: <CAKEwX=P8Qh4mOdv68UfXv-YBSnuZJkhEeuRJezZucbX7sysWvg@mail.gmail.com> (raw)
In-Reply-To: <20250807152720.62032-2-ryncsn@gmail.com>

On Thu, Aug 7, 2025 at 8:27 AM Kairui Song <ryncsn@gmail.com> wrote:
>
> From: Kairui Song <kasong@tencent.com>
>
> The filemap_get_incore_folio (previously find_get_incore_page) helper
> was introduced by commit 61ef18655704 ("mm: factor find_get_incore_page
> out of mincore_page") to be used by later commit f5df8635c5a3 ("mm: use
> find_get_incore_page in memcontrol"), so memory cgroup charge move code
> can be simplified.
>
> But commit 6b611388b626 ("memcg-v1: remove charge move code") removed
> that user completely, it's only used by mincore now.
>
> So this commit basically reverts commit 61ef18655704 ("mm: factor
> find_get_incore_page out of mincore_page"). Move it back to mincore side
> to simplify the code.
>
> Signed-off-by: Kairui Song <kasong@tencent.com>

Seems reasonable to me for the most part - just a couple of questions below.

> ---
>  mm/mincore.c    | 29 +++++++++++++++++++++++++++--
>  mm/swap.h       | 10 ----------
>  mm/swap_state.c | 38 --------------------------------------
>  3 files changed, 27 insertions(+), 50 deletions(-)
>
> diff --git a/mm/mincore.c b/mm/mincore.c
> index 10dabefc3acc..f0d3c9419e58 100644
> --- a/mm/mincore.c
> +++ b/mm/mincore.c
> @@ -64,8 +64,33 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t index)
>          * any other file mapping (ie. marked !present and faulted in with
>          * tmpfs's .fault). So swapped out tmpfs mappings are tested here.
>          */
> -       folio = filemap_get_incore_folio(mapping, index);
> -       if (!IS_ERR(folio)) {
> +       if (IS_ENABLED(CONFIG_SWAP) && shmem_mapping(mapping)) {

Do we need CONFIG_SWAP check here? I suppose if !CONFIG_SWAP we'll
never end up with an ordinary swap entry stored here right?

Saves a couple of cycles, I suppose. No strong opinions.

> +               folio = filemap_get_entry(mapping, index);
> +               /*
> +                * shmem/tmpfs may return swap: account for swapcache
> +                * page too.
> +                */
> +               if (xa_is_value(folio)) {
> +                       struct swap_info_struct *si;
> +                       swp_entry_t swp = radix_to_swp_entry(folio);
> +                       /* There might be swapin error entries in shmem mapping. */
> +                       if (non_swap_entry(swp))
> +                               return 0;
> +                       /* Prevent swap device to being swapoff under us */
> +                       si = get_swap_device(swp);
> +                       if (si) {
> +                               folio = filemap_get_folio(swap_address_space(swp),
> +                                                         swap_cache_index(swp));
> +                               put_swap_device(si);
> +                       } else {
> +                               return 0;
> +                       }
> +               }
> +       } else {
> +               folio = filemap_get_folio(mapping, index);
> +       }
> +
> +       if (folio) {

Should this check be "if (!IS_ERR(folio))"? Seems like that's how we
inspect the output of filemap_get_folio() in other locations (for e.g,
in filemap_fault()).

>                 present = folio_test_uptodate(folio);
>                 folio_put(folio);
>         }


  reply	other threads:[~2025-08-07 18:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-07 15:27 [RFC PATCH 0/3] mm/mincore: clean up swap cache helper and PTL Kairui Song
2025-08-07 15:27 ` [RFC PATCH 1/3] mm/mincore, swap: consolidate swap cache checking for mincore Kairui Song
2025-08-07 18:06   ` Nhat Pham [this message]
2025-08-07 18:23     ` Kairui Song
2025-08-07 15:27 ` [RFC PATCH 2/3] mm/mincore: use a helper for checking the swap cache Kairui Song
2025-08-07 15:27 ` [RFC PATCH 3/3] mm/mincore: avoid touching the PTL Kairui Song
2025-08-07 16:02   ` Jann Horn
2025-08-07 17:27     ` Kairui Song
2025-08-07 17:45       ` Jann Horn
2025-08-07 18:09         ` Kairui Song
2025-08-11  8:41   ` 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='CAKEwX=P8Qh4mOdv68UfXv-YBSnuZJkhEeuRJezZucbX7sysWvg@mail.gmail.com' \
    --to=nphamcs@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=bhe@redhat.com \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=pfalcato@suse.de \
    --cc=shikemeng@huaweicloud.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /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