Migration/postcopy disallow huge pages
cover Migration/postcopy disallow huge pages
From: "Dr. David Alan Gilbert" <[email protected]>
We've not got support for huge pages in postcopy yet, and it will error when it tries to use the userfaultfd on the hugepage, however the kernel is going to gain support for userfault so make sure we fail with a nice error on the new kernel until we figure out how to add support.
Dave
Dr. David Alan Gilbert (2):
RAMBlocks: Store page size migration/postcopy: Explicitly disallow huge pages
exec.c | 17 +++++++++++------ include/exec/cpu-common.h | 1 + include/exec/ram_addr.h | 1 + migration/postcopy-ram.c | 23 +++++++++++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.4
PATCH 2/2 migration/postcopy: Explicitly disallow huge pages
From: "Dr. David Alan Gilbert" <[email protected]>
At the moment postcopy will fail as soon as qemu tries to register userfault on the RAMBlock pages that are backed by hugepages. However, the kernel is going to get userfault support for hugepage at some point, and we've not got the rest of the QEMU code to support it yet, so fail neatly with an error like:
Postcopy doesn't support hugetlbfs yet (/objects/mem1)
--- migration/postcopy-ram.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
migration/postcopy-ram.c +23 -0
@@ -85,6 +85,23 @@ static bool ufd_version_check(int ufd) }/* +* Check for things that postcopy won't support; returns 0 if the block +* is fine. +*/ +static int check_range (const char *block_name,void *host_addr, +ram_addr_t offset,ram_addr_t length,void *opaque) +{ +RAMBlock *rb =qemu_ram_block_by_name (block_name); + +if (qemu_ram_pagesize (rb) >getpagesize ()) { +error_report ("Postcopy doesn't support hugetlbfs yet (%s)" , block_name); +return -E2BIG ; + } + +return 0 ; +} + +/* * Note: This has the side effect of munlock'ing all of RAM, that's * normally fine since if the postcopy succeeds it gets turned back on at the * end.
@@ -104,6 +121,12 @@ bool postcopy_ram_supported_by_host(void) goto out; } +/* Check for anything about the RAMBlocks we don't support */ +if (qemu_ram_foreach_block (check_range,NULL )) { +/* check_range will have printed its own error */ + goto out; + } + ufd =syscall (__NR_userfaultfd,O_CLOEXEC );if (ufd ==-1 ) { error_report("%s: userfaultfd not available: %s", __func__,
Signature · 1 line
2.7.4
PATCH 1/2 RAMBlocks: Store page size
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Store the page size in each RAMBlock, we need it later.
--- exec.c | 17 +++++++++++------ include/exec/cpu-common.h | 1 + include/exec/ram_addr.h | 1 + 3 files changed, 13 insertions(+), 6 deletions(-)
exec.c +11 -6
@@ -1201,7 +1201,6 @@ static void *file_ram_alloc(RAMBlock *block,char *c;void *area =MAP_FAILED ;int fd =-1 ; -int64_t page_size;if (kvm_enabled () && !kvm_has_sync_mmu ()) { error_setg(errp,
@@ -1256,17 +1255,17 @@ static void *file_ram_alloc(RAMBlock *block,*/ } - page_size =qemu_fd_getpagesize (fd); - block->mr->align =MAX (page_size,QEMU_VMALLOC_ALIGN ); + block->page_size =qemu_fd_getpagesize (fd); + block->mr->align =MAX (block->page_size,QEMU_VMALLOC_ALIGN ); -if (memory < page_size) { +if (memory < block->page_size) {error_setg (errp,"memory size 0x" RAM_ADDR_FMT " must be equal to " "or larger than page size 0x%" PRIx64, - memory, page_size); + memory, block->page_size); goto error; } - memory =ROUND_UP (memory, page_size); + memory =ROUND_UP (memory, block->page_size);/* * ftruncate is not supported by hugetlbfs in older
@@ -1421,6 +1420,11 @@ void qemu_ram_unset_idstr(RAMBlock *block) } } +size_t qemu_ram_pagesize (RAMBlock *rb) +{ +return rb->page_size; +} +static int memory_try_enable_merging (void *addr,size_t len) {if (!machine_mem_merge (current_machine)) {
@@ -1660,6 +1664,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, new_block->max_length = max_size;assert (max_size >= size); new_block->fd =-1 ; + new_block->page_size =getpagesize (); new_block->host = host;if (host) { new_block->flags |=RAM_PREALLOC ;
include/exec/cpu-common.h +1 -0
@@ -63,6 +63,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,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); +size_t qemu_ram_pagesize (RAMBlock *block);void cpu_physical_memory_rw (hwaddr addr,uint8_t *buf,int len,int is_write);
include/exec/ram_addr.h +1 -0
@@ -36,6 +36,7 @@ struct RAMBlock {/* RCU-enabled, writes protected by the ramlist lock */ QLIST_ENTRY (RAMBlock) next;int fd; +size_t page_size; };static inline bool offset_in_ramblock (RAMBlock *b,ram_addr_t offset)
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/2] migration/postcopy: Explicitly disallow huge pages
In reply to Dr. David Alan Gilbert (git)Quoted 23 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
At the moment postcopy will fail as soon as qemu tries to register userfault on the RAMBlock pages that are backed by hugepages. However, the kernel is going to get userfault support for hugepage at some point, and we've not got the rest of the QEMU code to support it yet, so fail neatly with an error like:
Postcopy doesn't support hugetlbfs yet (/objects/mem1)
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/postcopy-ram.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)migration/postcopy-ram.c +0
-0@@ -85,6 +85,23 @@ static bool ufd_version_check(int ufd) }/*
migration/postcopy-ram.c static bool ufd_version_check(int ufd) · line 97
Quoted 10 lines
migration/postcopy-ram.c +10
-0+* Check for things that postcopy won't support; returns 0 if the block +* is fine. +*/ +static int check_range (const char *block_name,void *host_addr, +ram_addr_t offset,ram_addr_t length,void *opaque) +{ +RAMBlock *rb =qemu_ram_block_by_name (block_name); + +if (qemu_ram_pagesize (rb) >getpagesize ()) { +error_report ("Postcopy doesn't support hugetlbfs yet (%s)" , block_name);
A small nitpick - I'd suggest s/hugetlbfs/large page sizes/ as this error will ultimately bubble up to users, and 'large page sizes' is the conceptual feature
Regards,
Daniel
Signature · 3 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
Re: [Qemu-devel] [PATCH 2/2] migration/postcopy: Explicitly disallow huge pages
Quoted 23 lines · * Daniel P. Berrange ([email protected]) wrote:
Quoted 22 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
At the moment postcopy will fail as soon as qemu tries to register userfault on the RAMBlock pages that are backed by hugepages. However, the kernel is going to get userfault support for hugepage at some point, and we've not got the rest of the QEMU code to support it yet, so fail neatly with an error like:
Postcopy doesn't support hugetlbfs yet (/objects/mem1)
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/postcopy-ram.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)migration/postcopy-ram.c +0
-0@@ -85,6 +85,23 @@ static bool ufd_version_check(int ufd) }
Quoted 15 lines
migration/postcopy-ram.c static bool ufd_version_check(int ufd) · line 97
Quoted 11 lines
migration/postcopy-ram.c +10
-0/* +* Check for things that postcopy won't support; returns 0 if the block +* is fine. +*/ +static int check_range (const char *block_name,void *host_addr, +ram_addr_t offset,ram_addr_t length,void *opaque) +{ +RAMBlock *rb =qemu_ram_block_by_name (block_name); + +if (qemu_ram_pagesize (rb) >getpagesize ()) { +error_report ("Postcopy doesn't support hugetlbfs yet (%s)" , block_name);A small nitpick - I'd suggest s/hugetlbfs/large page sizes/ as this error will ultimately bubble up to users, and 'large page sizes' is the conceptual feature
Interesting, I'd never heard it called 'large' before.
Everytime I just say 'huge page' to someone I then have to explain it's fine on transparent huge page.
Dave
Quoted 8 lines
Regards,
DanielSignature · 3 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Juan Quintela
Reviewed-byRe: [Qemu-devel] [PATCH 2/2] migration/postcopy: Explicitly disallow huge pages
In reply to Daniel P. BerrangeQuoted 23 lines · Daniel P. Berrange
Quoted 22 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
At the moment postcopy will fail as soon as qemu tries to register userfault on the RAMBlock pages that are backed by hugepages. However, the kernel is going to get userfault support for hugepage at some point, and we've not got the rest of the QEMU code to support it yet, so fail neatly with an error like:
Postcopy doesn't support hugetlbfs yet (/objects/mem1)
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- migration/postcopy-ram.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)migration/postcopy-ram.c +0
-0@@ -85,6 +85,23 @@ static bool ufd_version_check(int ufd) }
Quoted 15 lines
migration/postcopy-ram.c static bool ufd_version_check(int ufd) · line 97
Quoted 11 lines
migration/postcopy-ram.c +10
-0/* +* Check for things that postcopy won't support; returns 0 if the block +* is fine. +*/ +static int check_range (const char *block_name,void *host_addr, +ram_addr_t offset,ram_addr_t length,void *opaque) +{ +RAMBlock *rb =qemu_ram_block_by_name (block_name); + +if (qemu_ram_pagesize (rb) >getpagesize ()) { +error_report ("Postcopy doesn't support hugetlbfs yet (%s)" , block_name);A small nitpick - I'd suggest s/hugetlbfs/large page sizes/ as this error will ultimately bubble up to users, and 'large page sizes' is the conceptual feature
I fixed the message my hand