All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Pratyush Yadav <pratyush@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v3] mm/memfd_luo: don't use memfd_pin_folios()
Date: Tue, 24 Nov 2026 20:01:30 +0200	[thread overview]
Message-ID: <awXQ-sYNkY-TALqE@kernel.org> (raw)
In-Reply-To: <2vxztsl6xj59.fsf@kernel.org>

On Tue, Nov 24, 2026 at 04:56:50PM +0000, Pratyush Yadav wrote:
> On Tue, Nov 24 2026, Mike Rapoport wrote:
> 
> > On Tue, Nov 24, 2026 at 02:51:59PM +0000, Pratyush Yadav wrote:
> >> On Mon, Nov 23 2026, Mike Rapoport wrote:
> [...]
> > v2 was better I think, but it still had that
> >
> > 		if (err == -EBUSY && ++busy_retries < MEMFD_LUO_MIGRATE_RETRIES)
> > 			continue;
> > 		if (err)
> > 			return err;
> >
> > which I don't really like.
> >
> > I came up with a variant below that IMHO makes things more explicit:
> >
> > static int memfd_luo_get_folio(struct inode *inode, pgoff_t index,
> > 			       struct folio **foliop)
> > {
> > 	int err, retries = 0;
> > 	struct folio *folio;
> >
> > 	for (;;) {
> > 		if (retries > MEMFD_LUO_MIGRATE_RETRIES)
> > 			return -EBUSY;
> >
> > 		err = shmem_get_folio(inode, index, 0, &folio, SGP_CACHE);
> > 		if (err)
> > 			return err;
> >
> > 		if (likely(folio_is_longterm_pinnable(folio)))
> > 			break;
> >
> > 		folio_unlock(folio);
> > 		err = memfd_luo_migrate_folio(folio);
> > 		if (err) {
> > 			if (err != -EBUSY)
> > 				return err;
> > 			retries++;
> > 		}
> > 	}
> 
> This has a super theoretical corner case where the migration can
> succeed, then the folio can migrate back to CMA by the time we do
> shmem_get_folio(). So we can loop infinitely.

Oops :)
 
> I think the if (retries > MEMFD_LUO_MIGRATE_RETRIES) should be after the
> folio_is_longterm_pinnable() check and retries should increment after

Maybe after folio_unlock() then?

> every migration, not only failed ones.
> 
> Apart from that, your variant looks nicer.
> 
> Does that sound good?
> 
> >
> > 	*foliop = folio;
> > 	return 0;
> > }
> >
> > It does an iteration more than v2 with the same MEMFD_LUO_MIGRATE_RETRIES,
> > but that's not really important.
> >
> > Your call really, I can live with either of them.
> 
> -- 
> Regards,
> Pratyush Yadav

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2026-11-24 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 13:01 [PATCH v3] mm/memfd_luo: don't use memfd_pin_folios() Pratyush Yadav
2026-11-23 19:54 ` Mike Rapoport
2026-11-24 14:51   ` Pratyush Yadav
2026-11-24 15:48     ` Mike Rapoport
2026-11-24 16:56       ` Pratyush Yadav
2026-11-24 18:01         ` Mike Rapoport [this message]
2026-11-24 18:27           ` Pratyush Yadav
2026-11-24 13:01 ` sashiko-bot

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=awXQ-sYNkY-TALqE@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.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.