From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>,
Hugh Dickins <hughd@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>, linux-mm@kvack.org
Subject: Re: [PATCH v3] mm/shmem: don't allocate the replacement folio with the folio locked
Date: Sat, 5 Dec 2026 18:42:06 +0100 [thread overview]
Message-ID: <af628b36-422e-4c06-b5af-cc96fb827556@kernel.org> (raw)
In-Reply-To: <20261205165318.114891-1-azpijr@gmail.com>
On 12/5/26 17:53, Jose A. Perez de Azpillaga wrote:
> shmem_swapin_folio() allocates the replacement for a swapcache folio in
> the wrong zone while holding the folio lock, usually with __GFP_FS.
>
> The zone check doesn't need the lock, so allocate the replacement before
> locking the folio. The folio can't be split in the meantime, since we
> hold a reference to it.
>
> If the allocation fails, shmem_swapin_folio() still returns -ENOMEM
> after the swap entry checks.
>
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Link: https://lore.kernel.org/c45c8b8c-0ccc-4e0e-898f-039f84fe1e56@kernel.org
> Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Thanks, this looks pretty good :)
> +
> +static void shmem_replace_folio(struct folio **foliop, struct folio *new)
> +{
> + struct swap_cluster_info *ci;
> + struct folio *old = *foliop;
> + swp_entry_t entry = old->swap;
> + int nr_pages = folio_nr_pages(old);
I assume this could be const.
>
> folio_ref_add(new, nr_pages);
> folio_copy(new, old);
> @@ -2427,7 +2427,6 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp,
> * cache.
> */
> folio_put_refs(old, nr_pages + 1);
> - return error;
> }
>
> static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
> @@ -2546,9 +2545,10 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
> swp_entry_t swap;
> softleaf_t index_entry;
> struct swap_info_struct *si;
> - struct folio *folio = NULL;
> + struct folio *folio = NULL, *new = NULL;
> int error, nr_pages, order;
> pgoff_t offset;
> + bool replace;
>
> VM_BUG_ON(!*foliop || !xa_is_value(*foliop));
> index_entry = radix_to_swp_entry(*foliop);
> @@ -2637,6 +2637,10 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
> index = round_down(index, nr_pages);
> }
>
> + replace = shmem_should_replace_folio(folio, gfp);
Could we calculate this above and make it const?
I'll wait for Baolin's review before applying :)
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
prev parent reply other threads:[~2026-12-05 17:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 16:53 [PATCH v3] mm/shmem: don't allocate the replacement folio with the folio locked Jose A. Perez de Azpillaga
2026-12-05 17:42 ` David Hildenbrand (Arm) [this message]
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=af628b36-422e-4c06-b5af-cc96fb827556@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=azpijr@gmail.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=hughd@google.com \
--cc=linux-mm@kvack.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