All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>,
	"David Hildenbrand (Arm)" <david@kernel.org>,
	Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH v2] mm/shmem: don't allocate the replacement folio with the folio locked
Date: Fri, 4 Dec 2026 14:53:18 +0800	[thread overview]
Message-ID: <739c48b8-28c8-4182-a320-cfe971be2e92@linux.alibaba.com> (raw)
In-Reply-To: <b8314367-a53e-4d2e-ae1f-03fc70ecd063@gmail.com>



On 12/3/26 6:46 PM, Jose A. Perez de Azpillaga wrote:
> On 12/3/26 9:39 AM, David Hildenbrand (Arm) wrote:
>>> @@ -2636,6 +2639,9 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
>>>   		index = round_down(index, nr_pages);
>>>   	}
>>>   
>>> +	if (shmem_should_replace_folio(folio, gfp))
>>
>> Can we cache the result and reuse below?
>>
> 
> sure, will do in v3.
> 
>> Or even better, check for "new" below instead of shmem_should_replace_folio(). I
>> think that then nicely matches the "new = NULL;"
>>
>> That means we would move the
>>
>> 	if (!new)
>> 		return -ENOMEM;
>>
>> out of shmem_replace_folio() here.
>>
>> Is there something that would prevent that?
>>
>> Would look cleaner to me.
>>
>>
> 
> yes, that's the early -ENOMEM from v1, it skips the swap entry checks
> Baolin pointed out..

Maybe David wanted it this way? Then shmem_replace_folio() could be a 
void function.

@@ -2546,8 +2545,9 @@ 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;
+       bool should_replace_folio;
         pgoff_t offset;

         VM_BUG_ON(!*foliop || !xa_is_value(*foliop));
@@ -2637,6 +2637,10 @@ static int shmem_swapin_folio(struct inode 
*inode, pgoff_t index,
                 index = round_down(index, nr_pages);
         }

+       should_replace_folio = shmem_should_replace_folio(folio, gfp);
+       if (should_replace_folio)
+               new = shmem_alloc_replacement(folio, gfp, info, index, vma);
+
         /*
          * We have to do this with the folio locked to prevent races.
          * The shmem_confirm_swap below only checks if the first swap
@@ -2665,10 +2669,13 @@ static int shmem_swapin_folio(struct inode 
*inode, pgoff_t index,
          */
         arch_swap_restore(folio_swap(swap, folio), folio);

-       if (shmem_should_replace_folio(folio, gfp)) {
-               error = shmem_replace_folio(&folio, gfp, info, index, vma);
-               if (error)
+       if (should_replace_folio) {
+               if (!new) {
+                       error = -ENOMEM;
                         goto failed;
+               }
+
+               shmem_replace_folio(&folio, new);
         }

         error = shmem_add_to_page_cache(folio, mapping, index,
@@ -2708,6 +2715,8 @@ static int shmem_swapin_folio(struct inode *inode, 
pgoff_t index,
         if (folio)
                 folio_unlock(folio);
  failed_nolock:
+       if (new)
+               folio_put(new);
         if (folio)
                 folio_put(folio);
         put_swap_device(si);



  reply	other threads:[~2026-12-04  6:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 22:19 [PATCH v2] mm/shmem: don't allocate the replacement folio with the folio locked Jose A. Perez de Azpillaga
2026-12-03  8:39 ` David Hildenbrand (Arm)
2026-12-03 10:46   ` Jose A. Perez de Azpillaga
2026-12-04  6:53     ` Baolin Wang [this message]
2026-12-04  9:17       ` Jose A. Perez de Azpillaga

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=739c48b8-28c8-4182-a320-cfe971be2e92@linux.alibaba.com \
    --to=baolin.wang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=azpijr@gmail.com \
    --cc=david@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.