All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
	linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
	peterx@redat.com, John Hubbard <jhubbard@nvidia.com>,
	Ralph Campbell <rcampbell@nvidia.com>
Subject: Re: [PATCH] mm/migrate_device.c: Fix a misleading and out-dated comment
Date: Mon, 29 Aug 2022 17:09:25 +1000	[thread overview]
Message-ID: <87tu5v7blr.fsf@nvdebian.thelocal> (raw)
In-Reply-To: <Ywk/pZoYoy4BDO0n@xz-m1.local>


Peter Xu <peterx@redhat.com> writes:

[...]

>> >>> Meanwhile it'll be great to also mention about why trylock is needed and no
>> >>> further attempt to use lock_page().  The comment in prepare() previously
>> >>> was great but unfortunately that code clip was removed.
>> >>
>> >> Will add.
>> >>
>> >>> In short, do you think something like this might be clearer?
>> >>
>> >> I think it's important to mention the optimisation, otherwise the
>> >> temptation is to remove the installation of migration entries here and
>> >> rely on try_to_migrate() to do it later. I would actually like to be
>> >> able to do that because it simplifies the code in many ways but based on
>> >> my testing the optimisation turns out to be very worth while.
>> >>
>> >>> 		/*
>> >>> 		 * We rely on the trylock() to migrate the pte.  If this
>> >>> 		 * fails, we'll fail the migration of this page.  IOW, the
>> >>> 		 * migration is very much best-effort, just like we'll also
>> >>> 		 * bail out if we found page pinned by other users after
>> >>> 		 * page being locked.
>> >>
>> >> Honestly I think this describes what the code does rather than why and
>> >> is likely to become outdated and confusing. IMHO it's quite clear from
>> >> the code that the migration will fail here if we can't lock the page.
>> >
>> > If you see that's what I was struggling to understand previously, so not
>> > clear at least to me. :) Since normally a function like page migration
>> > should (from the gut feeling) not rely on trylock only.
>>
>> IIRC, ordinary page migration will also only trylock. See
>> isolate_movable_page().
>
> Fair enough.
>
> I think it depends on what we want to do with the migration.  I think not
> even all users of isolate_movable_page() only depend on trylock, and it can
> retry with lock_page later.  E.g.:
>
> - soft_offline_in_use_page
>   - isolate_page
>     - isolate_movable_page <----- trylock here
>   - (if isolate_page fails...) migrate_pages
>     - unmap_and_move       <----- lock_page here after 2 unsuccessful rounds
>
> And I also agree migration may always fail (e.g. by spurious page refcounts
> being taken), so feel free to ignore the "gut feeling" - that's indeed kind
> of subjective.

So how about the following:

		/*
		 * We rely on trylock_page() to avoid deadlock between
		 * concurrent migrations where each is waiting on the others
		 * page lock. If we can't immediately lock the page we fail this
		 * migration as it is only best effort anyway.
		 *
		 * If we can lock the page it's safe to set up a migration entry
		 * now. In the common case where the page is mapped once in a
		 * single process setting up the migration entry now is an
		 * optimisation to avoid walking the rmap later with
		 * try_to_migrate().
		 */

Thanks.

 - Alistair


  reply	other threads:[~2022-08-29  7:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25  1:49 [PATCH] mm/migrate_device.c: Fix a misleading and out-dated comment Alistair Popple
2022-08-25 23:51 ` Peter Xu
2022-08-26  0:34   ` Alistair Popple
2022-08-26 15:03     ` Peter Xu
2022-08-26 17:17       ` David Hildenbrand
2022-08-26 21:48         ` Peter Xu
2022-08-29  7:09           ` Alistair Popple [this message]
2022-08-29 15:30             ` Peter Xu

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=87tu5v7blr.fsf@nvdebian.thelocal \
    --to=apopple@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redat.com \
    --cc=peterx@redhat.com \
    --cc=rcampbell@nvidia.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 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.