linux-kernel.vger.kernel.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>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrea Arcangeli <aarcange@redhat.com>,
	David Hildenbrand <david@redhat.com>,
	Minchan Kim <minchan@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Nadav Amit <nadav.amit@gmail.com>,
	Hugh Dickins <hughd@google.com>,
	Andi Kleen <andi.kleen@intel.com>,
	"Kirill A . Shutemov" <kirill@shutemov.name>,
	Christoph Hellwig <hch@lst.de>, Jason Gunthorpe <jgg@ziepe.ca>
Subject: Re: [PATCH v2 2/2] mm: Remember young/dirty bit for page migrations
Date: Thu, 11 Aug 2022 15:44:24 +1000	[thread overview]
Message-ID: <8735e3xqqz.fsf@nvdebian.thelocal> (raw)
In-Reply-To: <YvQFMMKxO2SD0T1T@xz-m1.local>


Peter Xu <peterx@redhat.com> writes:

> On Wed, Aug 10, 2022 at 08:53:49AM +0800, Huang, Ying wrote:
>> Peter Xu <peterx@redhat.com> writes:
>>
>> > On Tue, Aug 09, 2022 at 04:40:12PM +0800, Huang, Ying wrote:
>> [snip]
>> >
>> >> I don't find pte_dirty() is synced to PageDirty() as in
>> >> try_to_migrate_one().  Is it a issue in the original code?
>> >
>> > I think it has?  There is:
>> >
>> > 		/* Set the dirty flag on the folio now the pte is gone. */
>> > 		if (pte_dirty(pteval))
>> > 			folio_mark_dirty(folio);
>> >
>>
>> Sorry, my original words are confusing.  Yes, there's dirty bit syncing
>> in try_to_migrate_one().  But I don't find that in migrate_device.c
>>
>>  $ grep dirty mm/migrate_device.c
>> 				if (pte_soft_dirty(pte))
>> 					swp_pte = pte_swp_mksoft_dirty(swp_pte);
>> 				if (pte_swp_soft_dirty(pte))
>> 					swp_pte = pte_swp_mksoft_dirty(swp_pte);
>> 			entry = pte_mkwrite(pte_mkdirty(entry));
>>
>> I guess that migrate_device.c is used to migrate between CPU visible
>> page to CPU un-visible page (device visible), so the rule is different?
>
> IIUC migrate_vma_collect() handles migrations for both directions (RAM <->
> device mem).

That's correct.

> Yeah, indeed I also didn't see how migrate_vma_collect_pmd() handles the
> carry-over of pte dirty to page dirty, which looks a bit odd.  I also don't
> see why the dirty bit doesn't need to be maintained, e.g. when a previous
> page was dirty then after migration of ram->dev->ram it seems to be clean
> with current code.

That's a bug - it does need to be maintained. migrate_vma_*() currently
only works with anonymous private mappings. We could still loose data if
we attempt (but fail) to migrate a page that has been swapped in from
disk though, depending on the precise sequence.

Will post a fix for this, thanks for pointing it out.

> Another scenario is, even if the page was clean, as long as page migrated
> to device mem, device DMAed to the page, then page migrated back to RAM.  I
> also didn't see how we could detect the DMAs and set pte/page dirty
> properly after migrated back.

That would be up to the driver, unless we assume the page is always
dirty which is probably not a bad default. In practice I don't think
this will currently be a problem as any pages migrated to the device
won't have pages allocated in swap and this only works with private
anonymous mappings. But I think we should fix it anyway so will include
it in the fix.

> Copy Alistair and Jason..

Thanks. I will take a look at this series too, but probably won't get to
it until next week.

 - Alistair

  reply	other threads:[~2022-08-11  6:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 20:39 [PATCH v2 0/2] mm: Remember a/d bits for migration entries Peter Xu
2022-08-04 20:39 ` [PATCH v2 1/2] mm/swap: Add swp_offset_pfn() to fetch PFN from swap entry Peter Xu
2022-08-04 20:39 ` [PATCH v2 2/2] mm: Remember young/dirty bit for page migrations Peter Xu
2022-08-04 22:40   ` Nadav Amit
2022-08-05 16:30     ` Peter Xu
2022-08-09  8:45       ` Huang, Ying
2022-08-09  8:47         ` David Hildenbrand
2022-08-09 14:59         ` Peter Xu
2022-08-05 12:17   ` David Hildenbrand
2022-08-05 16:36     ` Peter Xu
2022-08-09  8:40   ` Huang, Ying
2022-08-09 17:59     ` Peter Xu
2022-08-10  0:53       ` Huang, Ying
2022-08-10 19:21         ` Peter Xu
2022-08-11  5:44           ` Alistair Popple [this message]
2022-08-04 22:17 ` [PATCH v2 0/2] mm: Remember a/d bits for migration entries Nadav Amit

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=8735e3xqqz.fsf@nvdebian.thelocal \
    --to=apopple@nvidia.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi.kleen@intel.com \
    --cc=david@redhat.com \
    --cc=hch@lst.de \
    --cc=hughd@google.com \
    --cc=jgg@ziepe.ca \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nadav.amit@gmail.com \
    --cc=peterx@redhat.com \
    --cc=vbabka@suse.cz \
    --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;
as well as URLs for NNTP newsgroup(s).