Re: [PATCH v1 0/5] arm64/mm: uffd write-protect and soft-dirty tracking

From: David Hildenbrand
Date: Fri Apr 19 2024 - 13:13:10 EST


On 19.04.24 18:30, Mike Rapoport wrote:
On Fri, Apr 19, 2024 at 11:45:14AM +0200, David Hildenbrand wrote:
On 19.04.24 10:33, Shivansh Vij wrote:
On 19/04/2024 08:43, Ryan Roberts wrote:
Hi All,

This series adds uffd write-protect and soft-dirty tracking support for arm64. I
consider the soft-dirty support (patches 3 and 4) as RFC - see rationale below.

That said, these are the last 2 SW bits and we may want to keep 1 bit in reserve
for future use. soft-dirty is only used for CRIU to my knowledge, and it is
thought that their use case could be solved with the more generic uffd-wp. So
unless somebody makes a clear case for the inclusion of soft-dirty support, we
are probably better off dropping patches 3 and 4 and keeping bit 63 for future
use. Although note that the most recent attempt to add soft-dirty for arm64 was
last month [1] so I'd like to give Shivansh Vij the opportunity to make the
case.

Appreciate the opportunity to provide input here.

I picked option one (dirty tracking in arm) because it seems to be the
simplest way to move forward, whereas it would be a relatively heavy
effort to add uffd-wp support to CRIU.

From a performance perspective I am also a little worried that uffd
will be slower than just tracking the dirty bits asynchronously with
sw dirty, but maybe that's not as much of a concern with the addition
of uffd-wp async.

With all this being said, I'll defer to the wisdom of the crowd about
which approach makes more sense - after all, with this patch we should
get uffd-wp support on arm so at least there will be _a_ way forward
for CRIU (albeit one requiring slightly more work).

Ccing Mike and Peter. In 2017, Mike gave a presentation "Memory tracking for
iterative container migration"[1] at LPC

Some key points are still true I think:
(1) More flexible and robust than soft-dirty
(2) May obsolete soft-dirty

We further recently added a new UFFD_FEATURE_WP_ASYNC feature as part of
[2], because getting soft-dirty return reliable results in some cases turned
out rather hard to fix.

We might still have to optimize that approach for some very sparse large
VMAs, but that should be solvable.

"The major defect of this approach of dirty tracking is we need to
populate the pgtables when tracking starts. Soft-dirty doesn't do it
like that. It's unwanted in the case where the range of memory to track
is huge and unpopulated (e.g., tracking updates on a 10G file with
mmap() on top, without having any page cache installed yet). One way to
improve this is to allow pte markers exist for larger than PTE level
for PMD+. That will not change the interface if to implemented, so we
can leave that for later.")[3]


If we can avoid adding soft-dirty on arm64 that would be great. This will
require work on the CRIU side. One downside of uffd-wp is that it is
currently not as avilable on architectures as soft-dirty.

Using uffd-wp instead of soft-dirty in CRIU will require quite some work on
CRIU side and probably on the kernel side too.

And as of now we'll anyway have to maintain soft-dirty because powerpc and
s390 don't have uffd-wp.

With UFFD_FEATURE_WP_ASYNC the concern that uffd-wp will be slower than
soft-dirty probably doesn't exist, but we won't know for sure until
somebody will try.

But there were other limitations, the most prominent was checkpointing an
application that uses uffd. If CRIU is to use uffd-wp for tracking of the
dirty pages, there should be some support for multiple uffd contexts for a
VMA and that's surely a lot of work.

Is it even already supported to checkpoint an application that is using uffd? Hard to believe, what if the monitor is running in a completely different process than the one being checkpointed?

Further ... isn't CRIU already using uffd in some cases? ..documentation mentions [1] that it is used for "lazy (or post-copy) restore in CRIU". At least if the documentation is correct and its actually implemented.

[1] https://criu.org/Userfaultfd


But I'll throw in another idea: do we really need soft-dirty and uffd-wp to
exist at the same time in the same process (or the VMA?). In theory, we

For instance to have dirty memory tracking in CRIU for an application that
uses uffd-wp :)


Hah! Not a concern for application on architectures where uffd-wp does not exist yet! Well, initially, until these applications exist and make use of it :P

Also, I'm not sure if CRIU can checkpoint each and every application ... I suspect one has to draw a line what can be supported and what not.

Case in point: how should CRIU checkpoint an application that is using softdirty tracking itself? If I'm not missing something important, that might not work ....

If the answer is "no other application is using soft-dirty tracking", then it's really a shame we have to carry this baggage (+waste precious PTE bits) only for one application ...

--
Cheers,

David / dhildenb