[CRIU] [RFC PATCH 06/12] lazy-pages: add handling of UFFD_EVENT_MADVDONTNEED
Mike Rapoport
rppt at linux.vnet.ibm.com
Mon Jan 9 00:23:20 PST 2017
When the restored process calls madvise(MADV_DONTNEED), the memory range
specified by the madvise() call should be remapped to zero pfn and we
should stop monitoring this range in order to avoid its pollution with data
the process does not expect.
All we need to do here, is to unregister the memory range from userfaultfd
and the kernel will take care of the rest.
Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
criu/uffd.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/criu/uffd.c b/criu/uffd.c
index a5b990e..3bc7bc1 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -650,6 +650,26 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi)
return 0;
}
+static int handle_madv_dontneed(struct lazy_pages_info *lpi,
+ struct uffd_msg *msg)
+{
+ struct uffdio_range unreg;
+
+ unreg.start = msg->arg.madv_dn.start;
+ unreg.len = msg->arg.madv_dn.end - msg->arg.madv_dn.start;
+
+ if (ioctl(lpi->lpfd.fd, UFFDIO_UNREGISTER, &unreg)) {
+ pr_perror("Failed to unregister (%llx - %llx)", unreg.start,
+ unreg.start + unreg.len);
+ return -1;
+ }
+
+ if (update_lazy_iovecs(lpi, unreg.start, unreg.len))
+ return -1;
+
+ return 0;
+}
+
static int handle_page_fault(struct lazy_pages_info *lpi, struct uffd_msg *msg)
{
struct pf_info *pf;
@@ -720,6 +740,8 @@ static int handle_uffd_event(struct epoll_rfd *lpfd)
switch (msg.event) {
case UFFD_EVENT_PAGEFAULT:
return handle_page_fault(lpi, &msg);
+ case UFFD_EVENT_MADVDONTNEED:
+ return handle_madv_dontneed(lpi, &msg);
default:
pr_err("unexpected uffd event %u\n", msg.event);
return -1;
--
1.9.1
More information about the CRIU
mailing list