linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: Lokesh Gidra <lokeshgidra@google.com>,
	Suren Baghdasaryan <surenb@google.com>,
	akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
	brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com,
	hughd@google.com, mhocko@suse.com, axelrasmussen@google.com,
	rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com,
	jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com,
	kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com,
	linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kernel-team@android.com
Subject: Re: [PATCH v3 2/3] userfaultfd: UFFDIO_MOVE uABI
Date: Tue, 17 Oct 2023 17:55:10 +0200	[thread overview]
Message-ID: <8d187891-f131-4912-82d8-13112125b210@redhat.com> (raw)
In-Reply-To: <ZS2IjEP479WtVdMi@x1n>

On 16.10.23 21:01, Peter Xu wrote:
> David,

Hi Peter,

>>> Basically I see it a potential way of moving memory efficiently especially
>>> with thp.
>>
>> It's an interesting use case indeed. The questions would be if this is (a) a
>> use case we want to support; (b) why we need to make that decision now and
>> add that feature.
> 
> I would like to support that if nothing stops it from happening, but that's
> what we're discussing though..
> 
> For (b), I wanted to avoid UFFD_FEATURE_MOVE_CROSS_MM feature flag just for
> this, if they're already so close, not to mention current code already
> contains cross-mm support.

Yeah, but that implementation is apparently not sufficiently correct yet.

Don't get me wrong, but this feature is already complicated enough that 
we should really think twice if we want to make this even more 
complicated and harder to maintain -- because once it's in we all know 
it's hard to remove and we can easily end up with a maintenance 
nightmare without sufficiently good use cases.

> 
> If to support that live upgrade use case, I'd probably need to rework tlb
> flushing too to do the batching (actually tlb flush is not even needed for
> upgrade scenario..).  I'm not sure whether Lokesh's use case would move
> large chunks, it'll be perfect if Suren did it altogether.  But that one is
> much easier if transparent to userapps.  Cross-mm is not transparent and
> need another feature knob, which I want to avoid if possible.

And for me it's the other way around: the kernel doesn't have to support 
each and every use case. So we better think twice before we do something 
we can no longer undo easily.

Further, as we see, this feature without cross-mm capabilities is 
perfectly usable for other use cases. So even limited initialy support 
is extremely valuable on its own.

> 
>>
>> One question is if this kind of "moving memory between processes" really
>> should be done, because intuitively SHMEM smells like the right thing to use
>> here (two processes wanting to access the same memory).
> 
> That's the whole point, IMHO, where shmem cannot be used.  As you said, on
> when someone cannot use file memory for some reason like ksm.

Right, but as I explore below KSM will at least prohibit remapping the 
KSM pages, taking some of the benefit away again.

> 
>>
>> The downsides of shmem are lack of the shared zeropage and KSM. The shared
>> zeropage is usually less of a concern for VMs, but KSM is. However, KSM will
>> also disallow moving pages here. But all non-deduplicated ones could be
>> moved.
>>
>> [I wondered whether moving KSM pages (rmap items) could be done; probably in
>> some limited form with some more added complexity]
> 
> Yeah we can leave that complexity for later when really needed.  Here
> cross-mm support, OTOH, isn't making it so complicated, IMHO.
> 
> Btw, we don't even necessarily need to be able to migrate KSM pages for a
> VM live upgrade use case: we can unmerge the pages, upgrade, and wait for
> KSM to scan & merge again on the new binary / mmap.  Userspace can have
> that control easily, afaiu, via existing madvise().

MADV_POPULATE_WRITE would do, yes.

BTW, wasn't there a way to do VM live-upgrade using fork() and replacing 
the binary? I recall that there was at some time either an 
implementation in QEMU or a proposal for an implementation; but I don't 
know how VM memory was provided. It's certainly harder to move VM memory 
using fork().

[...]

>>
>> single-mm should at least not cause harm, but the semantics are
>> questionable. cross-mm could, especially with malicious user space that
>> wants to find ways of harming the kernel.
> 
> For kernel, I think we're discussing to see whether it's safe to do so from
> kernel pov, e.g., whether to exclude pinned pages is part of that.
> 
> For the user app, the dest process has provided the uffd descriptor on its
> own willingness, or be a child of the UFFDIO_MOVE issuer when used with
> EVENT_FORK, I assume that's already some form of safety check because it
> cannot be any process, but ones that are proactively in close cooperative
> with the issuer process.

Is that and will that remain the case? I know people have been working 
on transparent user-space swapping using monitor processes using uffd. I 
thought there would have been ways to achieve that without any 
corporation of the dst.

> 
>>
>> I'll note that mremap with pinned pages works.
> 
> But that's not "by design", am I right?  IOW, do we have any real pin user
> that rely on mremap() allowing pages to be moved?

If in doubt, usually "probably yes".

Hard to tell if the "remap" in mremap indicates that we are simply 
remapping pages , and not moving data.

> 
> I don't see any word guarantee at least from man page that mremap() will
> make sure the PFN won't change after the movement.. even though it seems to
> be what happening now.

If you managed to support page pinning with migration the exact PFN 
doesn't matter. Likely nobody would implement that due to the tracking 
complexity.

> 
> Neither do I think when designing MMF_HAS_PINNED we kept that in mind that
> it won't be affected by someone mremap() pinned pages and we want to keep
> it working.. >
> All of it just seems to be an accident..

Not necessarily my opinion, but doesn't really matter here. It's working.

At least It's reasonable to have part of a THP pinned and mremapping the 
other part of the THP. That makes things more tricky ... because you 
only know that the THP is pinned.

> 
> One step back, we're free to define UFFDIO_MOVE anyway, and we don't
> necessarily need to always follow mremap().  E.g., mremap() also supports
> ksm pages, but IIUC we already decide to not support that for now on
> UFFDIO_MOVE.  UFFDIO_MOVE seems all fine to make it clear on failing at
> pinned pages from the 1st day if that satisfies our goals, too.

Yes.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2023-10-17 15:55 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09  6:42 [PATCH v3 0/3] userfaultfd move option Suren Baghdasaryan
2023-10-09  6:42 ` [PATCH v3 1/3] mm/rmap: support move to different root anon_vma in folio_move_anon_rmap() Suren Baghdasaryan
2023-10-12 22:01   ` Peter Xu
2023-10-13  8:04     ` David Hildenbrand
2023-10-19 15:19       ` Suren Baghdasaryan
2023-10-09  6:42 ` [PATCH v3 2/3] userfaultfd: UFFDIO_MOVE uABI Suren Baghdasaryan
2023-10-09 14:38   ` David Hildenbrand
2023-10-09 16:21     ` Suren Baghdasaryan
2023-10-09 16:23       ` David Hildenbrand
2023-10-09 16:29         ` Lokesh Gidra
2023-10-09 17:56           ` Lokesh Gidra
2023-10-10  1:49             ` Suren Baghdasaryan
2023-10-12 20:11           ` Peter Xu
2023-10-13  9:56             ` David Hildenbrand
2023-10-13 16:08               ` Peter Xu
2023-10-13 16:49                 ` Lokesh Gidra
2023-10-13 17:05                   ` Peter Xu
2023-10-16 18:01                 ` David Hildenbrand
2023-10-16 19:01                   ` Peter Xu
2023-10-17 15:55                     ` David Hildenbrand [this message]
2023-10-17 18:59                       ` Peter Xu
2023-10-19 15:41                         ` David Hildenbrand
2023-10-19 19:53                           ` Peter Xu
2023-10-19 20:02                             ` Suren Baghdasaryan
2023-10-19 20:43                               ` Peter Xu
2023-10-20 10:02                             ` David Hildenbrand
2023-10-20 14:09                               ` Suren Baghdasaryan
2023-10-20 17:16                                 ` David Hildenbrand
2023-10-22 15:46                                   ` Peter Xu
2023-10-23 12:03                                     ` David Hildenbrand
2023-10-23 16:36                                       ` David Hildenbrand
2023-10-23 17:33                                         ` Suren Baghdasaryan
2023-10-19 21:45                 ` Suren Baghdasaryan
2023-10-12 21:59   ` Peter Xu
2023-10-19 21:24     ` Suren Baghdasaryan
2023-10-22 17:01       ` Peter Xu
2023-10-23 17:43         ` Suren Baghdasaryan
2023-10-23 18:37           ` Peter Xu
2023-10-23 19:01             ` Suren Baghdasaryan
2023-10-17 19:39   ` kernel test robot
2023-10-19 21:55     ` Suren Baghdasaryan
2023-10-23 12:29   ` David Hildenbrand
2023-10-23 15:53     ` David Hildenbrand
2023-10-23 19:00       ` Suren Baghdasaryan
2023-10-23 18:56     ` Suren Baghdasaryan
2023-10-24 14:27       ` David Hildenbrand
2023-10-24 14:36         ` Suren Baghdasaryan
2023-10-09  6:42 ` [PATCH v3 3/3] selftests/mm: add UFFDIO_MOVE ioctl test Suren Baghdasaryan
2023-10-12 22:29   ` Peter Xu
2023-10-19 15:43     ` Suren Baghdasaryan
2023-10-19 17:29       ` Axel Rasmussen
2023-10-19 19:33         ` 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=8d187891-f131-4912-82d8-13112125b210@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=bgeffon@google.com \
    --cc=brauner@kernel.org \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=jdduke@google.com \
    --cc=kaleshsingh@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lokeshgidra@google.com \
    --cc=mhocko@suse.com \
    --cc=ngeoffray@google.com \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --cc=zhangpeng362@huawei.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).