* Peter Xu (pet...@redhat.com) wrote: > On Wed, Jun 28, 2017 at 08:00:23PM +0100, Dr. David Alan Gilbert (git) wrote: > > From: "Dr. David Alan Gilbert" <dgilb...@redhat.com> > > > > Use the recently added migration flag to hold whether > > each RAMBlock has the UFFDIO_ZEROPAGE capability, use it > > when it's available. > > > > This allows the use of postcopy on tmpfs as well as hugepage > > backed files. > > > > Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com> > > --- > > migration/migration.h | 4 ++++ > > migration/postcopy-ram.c | 12 +++++++++--- > > 2 files changed, 13 insertions(+), 3 deletions(-) > > > > diff --git a/migration/migration.h b/migration/migration.h > > index d9a268a3af..d109635d08 100644 > > --- a/migration/migration.h > > +++ b/migration/migration.h > > @@ -20,6 +20,10 @@ > > #include "exec/cpu-common.h" > > #include "qemu/coroutine_int.h" > > > > +/* Migration flags to be set using qemu_ram_set_migration_flags */ > > +/* Postcopy can atomically zero pages in this RAMBlock */ > > +#define QEMU_MIGFLAG_POSTCOPY_ZERO 0x00000001 > > + > > /* State for the incoming migration */ > > struct MigrationIncomingState { > > QEMUFile *from_src_file; > > diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c > > index be2a8f8e02..96338a8070 100644 > > --- a/migration/postcopy-ram.c > > +++ b/migration/postcopy-ram.c > > @@ -408,6 +408,12 @@ static int ram_block_enable_notify(const char > > *block_name, void *host_addr, > > error_report("%s userfault: Region doesn't support COPY", > > __func__); > > return -1; > > } > > + if (reg_struct.ioctls & ((__u64)1 << _UFFDIO_ZEROPAGE)) { > > + RAMBlock *rb = qemu_ram_block_by_name(block_name); > > + qemu_ram_set_migration_flags(rb, qemu_ram_get_migration_flags(rb) | > > + QEMU_MIGFLAG_POSTCOPY_ZERO); > > Shall we use atomic_or() inside qemu_ram_set_migration_flags()? Then > no need to fetch, and we'll be thread safe as well?
I've changed it to a simple |= in the new qemu_ram_set_uf_zeroable that works on the rb->flags field. > > + } > > + > > > > return 0; > > } > > @@ -620,11 +626,11 @@ int postcopy_place_page(MigrationIncomingState *mis, > > void *host, void *from, > > int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, > > RAMBlock *rb) > > { > > + size_t pagesize = qemu_ram_pagesize(rb); > > trace_postcopy_place_page_zero(host); > > > > - if (qemu_ram_pagesize(rb) == getpagesize()) { > > - if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, > > getpagesize(), > > - rb)) { > > + if (qemu_ram_get_migration_flags(rb) & QEMU_MIGFLAG_POSTCOPY_ZERO) { > > IIUC, _UFFDIO_ZEROPAGE is not supported on huge pages. If so, would > here worth a comment? Added. Dave > > + if (qemu_ufd_copy_ioctl(mis->userfault_fd, host, NULL, pagesize, > > rb)) { > > int e = errno; > > error_report("%s: %s zero host: %p", > > __func__, strerror(e), host); > > -- > > 2.13.0 > > > > Thanks, > > -- > Peter Xu -- Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK