linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Popple <apopple@nvidia.com>
To: Peter Xu <peterx@redhat.com>
Cc: "Huang, Ying" <ying.huang@intel.com>,
	Nadav Amit <nadav.amit@gmail.com>,
	huang ying <huang.ying.caritas@gmail.com>,
	Linux MM <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Sierra Guiza, Alejandro (Alex)" <alex.sierra@amd.com>,
	Felix Kuehling <Felix.Kuehling@amd.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	David Hildenbrand <david@redhat.com>,
	Ralph Campbell <rcampbell@nvidia.com>,
	Matthew Wilcox <willy@infradead.org>,
	Karol Herbst <kherbst@redhat.com>, Lyude Paul <lyude@redhat.com>,
	Ben Skeggs <bskeggs@redhat.com>,
	Logan Gunthorpe <logang@deltatee.com>,
	paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] mm/migrate_device.c: Copy pte dirty bit to page
Date: Fri, 26 Aug 2022 08:09:28 +1000	[thread overview]
Message-ID: <877d2wezll.fsf@nvdebian.thelocal> (raw)
In-Reply-To: <YwePm5lMSU2tsW6f@xz-m1.local>


Peter Xu <peterx@redhat.com> writes:

> On Thu, Aug 25, 2022 at 11:24:03AM +1000, Alistair Popple wrote:
>> By the way it's still an optimisation because in most cases we can avoid
>> calling try_to_migrate() and walking the rmap altogether if we install
>> the migration entries here. But I agree the comment is misleading.
>
> There's one follow up question I forgot to ask on the trylock thing.  I
> figured maybe I should ask out loud since we're at it.
>
> Since migrate_vma_setup() always only use trylock (even if before dropping
> the prepare() code), does it mean that it can randomly fail?

Yes, migration is always best effort and can randomly fail. For example
it can also fail because there are unexpected page references or pins.

> I looked at some of the callers, it seems not all of them are ready to
> handle that (__kvmppc_svm_page_out() or svm_migrate_vma_to_vram()).  Is it
> safe?  Do the callers need to always properly handle that (unless the
> migration is only a best-effort, but it seems not always the case).

Migration is always best effort. Callers need to be prepared to handle
failure of a particular page to migrate, but I could believe not all of
them are.

> Besides, since I read the old code of prepare(), I saw this comment:
>
> -		if (!(migrate->src[i] & MIGRATE_PFN_LOCKED)) {
> -			/*
> -			 * Because we are migrating several pages there can be
> -			 * a deadlock between 2 concurrent migration where each
> -			 * are waiting on each other page lock.
> -			 *
> -			 * Make migrate_vma() a best effort thing and backoff
> -			 * for any page we can not lock right away.
> -			 */
> -			if (!trylock_page(page)) {
> -				migrate->src[i] = 0;
> -				migrate->cpages--;
> -				put_page(page);
> -				continue;
> -			}
> -			remap = false;
> -			migrate->src[i] |= MIGRATE_PFN_LOCKED;
> -		}
>
> I'm a bit curious whether that deadlock mentioned in the comment is
> observed in reality?
>
> If the page was scanned in the same address space, logically the lock order
> should be guaranteed (if both page A&B, both threads should lock in order).
> I think the order can be changed if explicitly did so (e.g. fork() plus
> mremap() for anonymous here) but I just want to make sure I get the whole
> point of it.

You seem to have the point of it. The trylock_page() is to avoid
deadlock, and failure is always an option for migration. Drivers can
always retry if they really need the page to migrate, although success
is never guaranteed. For example the page might be pinned (or have
swap-cache allocated to it, but I'm hoping to at least get that fixed).

> Thanks,


  reply	other threads:[~2022-08-25 22:18 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  7:39 Alistair Popple
2022-08-16  7:39 ` [PATCH v2 2/2] selftests/hmm-tests: Add test for dirty bits Alistair Popple
2022-08-16  8:10 ` [PATCH v2 1/2] mm/migrate_device.c: Copy pte dirty bit to page huang ying
2022-08-16 20:35   ` Peter Xu
2022-08-17  1:49     ` Alistair Popple
2022-08-17  2:45       ` Peter Xu
2022-08-17  5:41         ` Alistair Popple
2022-08-17  7:17           ` Huang, Ying
2022-08-17  9:41             ` Nadav Amit
2022-08-17 19:27               ` Peter Xu
2022-08-18  6:34                 ` Huang, Ying
2022-08-18 14:44                   ` Peter Xu
2022-08-19  2:51                     ` Huang, Ying
2022-08-24  1:56                       ` Alistair Popple
2022-08-24 20:25                         ` Peter Xu
2022-08-24 20:48                           ` Peter Xu
2022-08-25  0:42                             ` Alistair Popple
2022-08-25  1:24                               ` Alistair Popple
2022-08-25 15:04                                 ` Peter Xu
2022-08-25 22:09                                   ` Alistair Popple [this message]
2022-08-25 23:36                                     ` Peter Xu
2022-08-25 14:40                               ` Peter Xu
2022-08-18  5:59               ` Huang, Ying
2022-08-17 19:07           ` Peter Xu
2022-08-17  1:38   ` Alistair Popple

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=877d2wezll.fsf@nvdebian.thelocal \
    --to=apopple@nvidia.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.sierra@amd.com \
    --cc=bskeggs@redhat.com \
    --cc=david@redhat.com \
    --cc=huang.ying.caritas@gmail.com \
    --cc=jgg@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=kherbst@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=logang@deltatee.com \
    --cc=lyude@redhat.com \
    --cc=nadav.amit@gmail.com \
    --cc=paulus@ozlabs.org \
    --cc=peterx@redhat.com \
    --cc=rcampbell@nvidia.com \
    --cc=stable@vger.kernel.org \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox