[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 24/50] postcopy: use UFFDIO_ZEROPAGE only when ava
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL v2 24/50] postcopy: use UFFDIO_ZEROPAGE only when available |
Date: |
Tue, 20 Mar 2018 05:17:38 +0200 |
From: "Dr. David Alan Gilbert" <address@hidden>
Use a flag on the RAMBlock to state whether it 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 <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/exec/cpu-common.h | 3 +++
exec.c | 16 ++++++++++++++++
migration/postcopy-ram.c | 13 ++++++++++---
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 0d861a6..24d335f 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -73,6 +73,9 @@ void qemu_ram_set_idstr(RAMBlock *block, const char *name,
DeviceState *dev);
void qemu_ram_unset_idstr(RAMBlock *block);
const char *qemu_ram_get_idstr(RAMBlock *rb);
bool qemu_ram_is_shared(RAMBlock *rb);
+bool qemu_ram_is_uf_zeroable(RAMBlock *rb);
+void qemu_ram_set_uf_zeroable(RAMBlock *rb);
+
size_t qemu_ram_pagesize(RAMBlock *block);
size_t qemu_ram_pagesize_largest(void);
diff --git a/exec.c b/exec.c
index 2199b09..0eb890d 100644
--- a/exec.c
+++ b/exec.c
@@ -99,6 +99,11 @@ static MemoryRegion io_mem_unassigned;
*/
#define RAM_RESIZEABLE (1 << 2)
+/* UFFDIO_ZEROPAGE is available on this RAMBlock to atomically
+ * zero the page and wake waiting processes.
+ * (Set during postcopy)
+ */
+#define RAM_UF_ZEROPAGE (1 << 3)
#endif
#ifdef TARGET_PAGE_BITS_VARY
@@ -1767,6 +1772,17 @@ bool qemu_ram_is_shared(RAMBlock *rb)
return rb->flags & RAM_SHARED;
}
+/* Note: Only set at the start of postcopy */
+bool qemu_ram_is_uf_zeroable(RAMBlock *rb)
+{
+ return rb->flags & RAM_UF_ZEROPAGE;
+}
+
+void qemu_ram_set_uf_zeroable(RAMBlock *rb)
+{
+ rb->flags |= RAM_UF_ZEROPAGE;
+}
+
/* Called with iothread lock held. */
void qemu_ram_set_idstr(RAMBlock *new_block, const char *name, DeviceState
*dev)
{
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 032abfb..a75b5d3 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -481,6 +481,10 @@ 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_uf_zeroable(rb);
+ }
return 0;
}
@@ -700,11 +704,14 @@ 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)) {
+ /* Normal RAMBlocks can zero a page using UFFDIO_ZEROPAGE
+ * but it's not available for everything (e.g. hugetlbpages)
+ */
+ if (qemu_ram_is_uf_zeroable(rb)) {
+ 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);
--
MST
- [Qemu-devel] [PULL v2 19/50] tests/bios-tables-test: add test cases for DIMM proximity, (continued)
- [Qemu-devel] [PULL v2 19/50] tests/bios-tables-test: add test cases for DIMM proximity, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 18/50] hw/acpi-build: build SRAT memory affinity structures for DIMM devices, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 17/50] qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 12/50] virt_arm: acpi: reuse common build_fadt(), Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 11/50] acpi: move build_fadt() from i386 specific to generic ACPI source, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 20/50] test/acpi-test-data: add ACPI tables for dimmpxm test, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 21/50] Makefile: add target to print generated files, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 22/50] migrate: Update ram_block_discard_range for shared, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 23/50] qemu_ram_block_host_offset, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 26/50] postcopy: Add vhost-user flag for postcopy and check it, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 24/50] postcopy: use UFFDIO_ZEROPAGE only when available,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL v2 25/50] postcopy: Add notifier chain, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 27/50] vhost-user: Add 'VHOST_USER_POSTCOPY_ADVISE' message, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 28/50] libvhost-user: Support sending fds back to qemu, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 29/50] libvhost-user: Open userfaultfd, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 31/50] vhost+postcopy: Register shared ufd with postcopy, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 32/50] vhost+postcopy: Transmit 'listen' to slave, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 33/50] postcopy+vhost-user: Split set_mem_table for postcopy, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 34/50] migration/ram: ramblock_recv_bitmap_test_byte_offset, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 37/50] vhost+postcopy: Stash RAMBlock and offset, Michael S. Tsirkin, 2018/03/19
- [Qemu-devel] [PULL v2 36/50] vhost+postcopy: Send address back to qemu, Michael S. Tsirkin, 2018/03/19