postcopy migration: Linux char device for postcopy
Subsystems (5)
cover postcopy migration: Linux char device for postcopy
This is Linux kernel driver for qemu/kvm postcopy live migration. This is used by qemu/kvm postcopy live migration patch.
TODO:
- Consider FUSE/CUSE option
So far several mmap patches for FUSE/CUSE are floating around. (their purpose isn't different from our purpose, though). They haven't merged into the upstream yet.
The driver specific part in qemu patches is modularized. So I expect it wouldn't be difficult to switch kernel driver to CUSE based driver.
ioctl commands:
UMEM_DEV_CRATE_UMEM: create umem device for qemuUMEM_DEV_LIST: list created umem devicesUMEM_DEV_REATTACH: re-attach the created umem device
UMEM_DEV_LIST and UMEM_DEV_REATTACH are used when the process that services page fault disappears or get stack. Then, administrator can list the umem devices and unblock the process which is waiting for page.
UMEM_GET_PAGE_REQUEST: retrieve page fault of qemu processUMEM_MARK_PAGE_CACHED: mark the specified pages pulled from the source
for daemon
UMEM_MAKE_VMA_ANONYMOUS: make the specified vma in the qemu process
This is _NOT_ implemented yet.
anonymous I'm not sure whether this can be implemented or not.
---
Changes version 1 -> 2:
- make ioctl structures padded to align
- un-KVM
KVM_VMEM -> UMEM
- dropped some ioctl commands as Avi requested
Isaku Yamahata (2):
export necessary symbols
umem: chardevice for kvm postcopy
drivers/char/Kconfig | 9 + drivers/char/Makefile | 1 + drivers/char/umem.c | 898 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/umem.h | 83 +++++ mm/memcontrol.c | 1 + mm/shmem.c | 1 + 6 files changed, 993 insertions(+), 0 deletions(-) create mode 100644 drivers/char/umem.c create mode 100644 include/linux/umem.h
PATCH 1/2 export necessary symbols
--- mm/memcontrol.c | 1 + mm/shmem.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
mm/memcontrol.c +1 -0
@@ -2807,6 +2807,7 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,return ret; } +EXPORT_SYMBOL_GPL (mem_cgroup_cache_charge);/* * While swap-in, try_charge -> commit or cancel, the page is locked.
mm/shmem.c +1 -0
@@ -2546,6 +2546,7 @@ int shmem_zero_setup(struct vm_area_struct *vma) vma->vm_flags |=VM_CAN_NONLINEAR ;return 0 ; } +EXPORT_SYMBOL_GPL (shmem_zero_setup);/** * shmem_read_mapping_page_gfp - read into page cache, using specified page allocation flags.
Signature · 1 line
1.7.1.1
PATCH 2/2 umem: chardevice for kvm postcopy
In reply to Isaku YamahataThis is a character device to hook page access.
The page fault in the area is reported to another user process by this chardriver. Then, the process fills the page contents and resolves the page fault.
--- drivers/char/Kconfig | 9 + drivers/char/Makefile | 1 + drivers/char/umem.c | 898 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/umem.h | 83 +++++ 4 files changed, 991 insertions(+), 0 deletions(-) create mode 100644 drivers/char/umem.c create mode 100644 include/linux/umem.h
drivers/char/Kconfig +9 -0
@@ -15,6 +15,15 @@ config DEVKMEM kind of kernel debugging operations. When in doubt, say "N". +config UMEM + tristate "/dev/umem user process backed memory support" + default n + help + User process backed memory driver provides /dev/umem device. + The /dev/umem device is designed for some sort of distributed + shared memory. Especially post-copy live migration with KVM. + When in doubt, say "N". + config STALDRV bool "Stallion multiport serial support" depends on SERIAL_NONSTANDARD
drivers/char/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-y += mem.o random.o +obj-$(CONFIG_UMEM) += umem.o obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o obj-y += misc.o obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
drivers/char/umem.c new file +898 -0
898 lines not on this page · raw message
include/linux/umem.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
1.7.1.1
Quoted 6 lines · Isaku Yamahata
UMEM_DEV_LIST: list created umem devicesUMEM_DEV_REATTACH: re-attach the created umem device
UMEM_DEV_LISTandUMEM_DEV_REATTACHare used when the process that services page fault disappears or get stack. Then, administrator can list the umem devices and unblock the process which is waiting for page.
Here is a simple utility which cleans up umem devices.
---------------------------------------------------------------------------
/*
* simple clean up utility of for umem devices
*
* Copyright (c) 2011,
* National Institute of Advanced Industrial Science and Technology *
* https://sites.google.com/site/grivonhome/quick-kvm-migration
* Author: Isaku Yamahata <yamahata at valinux co jp>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <err.h>
#include <errno.h>
#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/umem.h>
void mark_all_pages_cached(int umem_dev_fd, const char *id, const char *name)
{
struct umem_create create;
memset(&create, 0, sizeof(create));
strncpy(create.name.id, id, sizeof(create.name.id));
strncpy(create.name.name, name, sizeof(create.name.name));
if (ioctl(umem_dev_fd, UMEM_DEV_REATTACH, &create) < 0) {
err(EXIT_FAILURE, "UMEM_DEV_REATTACH");
}
close(create.shmem_fd);
long page_size = sysconf(_SC_PAGESIZE);
int page_shift = ffs(page_size) - 1;
int umem_fd = create.umem_fd;
printf("umem_fd %d size %"PRId64"\n", umem_fd, (uint64_t)create.size);
__u64 i;
__u64 e_pgoff = (create.size + page_size - 1) >> page_shift;
#define UMEM_CACHED_MAX 512
__u64 pgoffs[UMEM_CACHED_MAX];
struct umem_page_cached page_cached = {
.nr = 0,
.pgoffs = pgoffs,
};
for (i = 0; i < e_pgoff; i++) {
page_cached.pgoffs[page_cached.nr] = i;
page_cached.nr++;
if (page_cached.nr == UMEM_CACHED_MAX) {
if (ioctl(umem_fd, UMEM_MARK_PAGE_CACHED,
&page_cached) < 0) {
err(EXIT_FAILURE, "UMEM_MARK_PAGE_CACHED");
}
page_cached.nr = 0;
}
}
if (page_cached.nr > 0) {
if (ioctl(umem_fd, UMEM_MARK_PAGE_CACHED, &page_cached) < 0) {
err(EXIT_FAILURE, "UMEM_MARK_PAGE_CACHED");
}
}
close(umem_fd);
}#define DEV_UMEM "/dev/umem"
int main(int argc, char **argv)
{
const char *id = NULL;
const char *name = NULL;
if (argc >= 2) {
id = argv[1];
}
if (argc >= 3) {
name = argv[2];
}
int umem_dev_fd = open(DEV_UMEM, O_RDWR);
if (umem_dev_fd < 0) {
perror("can't open "DEV_UMEM);
exit(EXIT_FAILURE);
}
struct umem_list tmp_ulist = {
.nr = 0,
};
if (ioctl(umem_dev_fd, UMEM_DEV_LIST, &tmp_ulist) < 0) {
err(EXIT_FAILURE, "UMEM_DEV_LIST");
}
if (tmp_ulist.nr == 0) {
printf("no umem files\n");
exit(EXIT_SUCCESS);
}
struct umem_list *ulist = malloc(
sizeof(*ulist) + sizeof(ulist->names[0]) * tmp_ulist.nr);
ulist->nr = tmp_ulist.nr;
if (ioctl(umem_dev_fd, UMEM_DEV_LIST, ulist) < 0) {
err(EXIT_FAILURE, "UMEM_DEV_LIST");
}
uint32_t i;
for (i = 0; i < ulist->nr; ++i) {
char *u_id = ulist->names[i].id;
char *u_name = ulist->names[i].name;
char tmp_id_c = u_id[UMEM_ID_MAX - 1];
char tmp_name_c = u_name[UMEM_NAME_MAX - 1];
u_id[UMEM_ID_MAX - 1] = '\0';
u_name[UMEM_NAME_MAX - 1] = '\0';
printf("%d: id: %s name: %s\n", i, u_id, u_name);
if ((id != NULL || name != NULL) &&
(id == NULL || strncmp(id, u_id, UMEM_ID_MAX) == 0) &&
(name == NULL ||
strncmp(name, u_name, UMEM_NAME_MAX) == 0)) {
printf("marking cached: %d: id: %s name: %s\n",
i, u_id, u_name);
u_id[UMEM_ID_MAX - 1] = tmp_id_c;
u_name[UMEM_NAME_MAX - 1] = tmp_name_c;
mark_all_pages_cached(umem_dev_fd, u_id, u_name);
}
}
close(umem_dev_fd);
return 0;
}Re: [PATCH 2/2] umem: chardevice for kvm postcopy
In reply to Isaku Yamahatadrivers/char/Kconfig config DEVKMEM · line 19
Quoted 8 lines · Isaku Yamahata
This is a character device to hook page access.
The page fault in the area is reported to another user process by this chardriver. Then, the process fills the page contents and resolves the page fault.drivers/char/Kconfig +2
-0+config UMEM + tristate "/dev/umem user process backed memory support"
tab
drivers/char/Kconfig config DEVKMEM · line 26
Quoted 7 lines
drivers/char/Kconfig +7
-0+ default n + help + User process backed memory driver provides /dev/umem device. + The /dev/umem device is designed for some sort of distributed + shared memory. Especially post-copy live migration with KVM. + When in doubt, say "N". +
Need documentation of the protocol between the kernel and userspace; not just the ioctls, but also how faults are propagated.
Quoted 29 lines
drivers/char/umem.c new file +28
-0+ +struct umem_page_req_list { +struct list_head list; +pgoff_t pgoff; +}; + + + +static int umem_mark_page_cached (struct umem *umem, +struct umem_page_cached *page_cached) +{ +int ret =0 ; +#define PG_MAX ((__u32)32) +__u64 pgoffs[PG_MAX ]; +__u32 nr; +unsigned long bit; +bool wake_up_list = false; + + nr =0 ; +while (nr < page_cached->nr) { +__u32 todo =min (PG_MAX , (page_cached->nr - nr)); +int i; + +if (copy_from_user (pgoffs, page_cached->pgoffs + nr, +sizeof (*pgoffs) * todo)) { + ret = -EFAULT ; + goto out; + }
drivers/char/umem.c line 457
Quoted 10 lines
drivers/char/umem.c new file +10
-0+for (i =0 ; i < todo; ++i) { +if (pgoffs[i] >= umem->pgoff_end) { + ret = -EINVAL ; + goto out; + } +set_bit (pgoffs[i], umem->cached); + } + nr += todo; + } +
Probably need an smp_wmb() where.
drivers/char/umem.c line 466
Quoted 9 lines
drivers/char/umem.c new file +9
-0+spin_lock (&umem->lock); + bit =0 ; +for (;;) { + bit =find_next_bit (umem->sync_wait_bitmap, umem->sync_req_max, + bit); +if (bit >= umem->sync_req_max) +break ; +if (test_bit (umem->sync_req[bit], umem->cached)) +wake_up (&umem->page_wait[bit]);
Why not do this test in the loop above?
Quoted 15 lines
drivers/char/umem.c new file +15
-0+ bit++; + } + +if (umem->req_list_nr >0 ) + wake_up_list = true; +spin_unlock (&umem->lock); + +if (wake_up_list) +wake_up_all (&umem->req_list_wait); + +out: +return ret; +} + +
drivers/char/umem.c line 591
Quoted 10 lines
drivers/char/umem.c new file +10
-0+ +static void umem_put (struct umem *umem) +{ +int ret; + +mutex_lock (&umem_list_mutex); + ret =kref_put (&umem->kref, umem_free); +if (ret ==0 ) { +mutex_unlock (&umem_list_mutex); + }
This looks wrong.
Quoted 67 lines
drivers/char/umem.c new file +67
-0+} + + +static int umem_create_umem (struct umem_create *create) +{ +int error =0 ; +struct umem *umem =NULL ; +struct vm_area_struct *vma; +int shmem_fd; +unsigned long bitmap_bytes; +unsigned long sync_bitmap_bytes; +int i; + + umem =kzalloc (sizeof (*umem),GFP_KERNEL ); + umem->name = create->name; +kref_init (&umem->kref); +INIT_LIST_HEAD (&umem->list); + +mutex_lock (&umem_list_mutex); + error =umem_add_list (umem); +if (error) { + goto out; + } + + umem->task =NULL ; + umem->mmapped = false; +spin_lock_init (&umem->lock); + umem->size =roundup (create->size,PAGE_SIZE ); + umem->pgoff_end = umem->size >>PAGE_SHIFT ; +init_waitqueue_head (&umem->req_wait); + + vma = &umem->vma; + vma->vm_start =0 ; + vma->vm_end = umem->size; +/* this shmem file is used for temporal buffer for pages +so it's unlikely that so many pages exists in this shmem file */ + vma->vm_flags =VM_READ |VM_SHARED |VM_NOHUGEPAGE |VM_DONTCOPY | +VM_DONTEXPAND ; + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_pgoff =0 ; +INIT_LIST_HEAD (&vma->anon_vma_chain); + + shmem_fd =get_unused_fd (); +if (shmem_fd <0 ) { + error = shmem_fd; + goto out; + } + error =shmem_zero_setup (vma); +if (error <0 ) { +put_unused_fd (shmem_fd); + goto out; + } + umem->shmem_filp = vma->vm_file; +get_file (umem->shmem_filp); +fd_install (shmem_fd, vma->vm_file); + create->shmem_fd = shmem_fd; + + create->umem_fd =anon_inode_getfd ("umem" , + &umem_fops, umem,O_RDWR ); +if (create->umem_fd <0 ) { + error = create->umem_fd; + goto out; + } + + bitmap_bytes =umem_bitmap_bytes (umem); +if (bitmap_bytes >PAGE_SIZE ) { + umem->cached =vzalloc (bitmap_bytes);
drivers/char/umem.c line 709
Quoted 10 lines
drivers/char/umem.c new file +10
-0+ umem->faulted =vzalloc (bitmap_bytes); + }else { + umem->cached =kzalloc (bitmap_bytes,GFP_KERNEL ); + umem->faulted =kzalloc (bitmap_bytes,GFP_KERNEL ); + } + +/* those constants are not exported. +They are just used for default value */ +#define KVM_MAX_VCPUS 256 +#define ASYNC_PF_PER_VCPU 64
Best to avoid defaults and require userspace choose.
Quoted 63 lines
drivers/char/umem.c new file +63
-0+ +#define ASYNC_REQ_MAX (ASYNC_PF_PER_VCPU * KVM_MAX_VCPUS) +if (create->async_req_max ==0 ) + create->async_req_max =ASYNC_REQ_MAX ; + umem->async_req_max = create->async_req_max; + umem->async_req_nr =0 ; + umem->async_req =kzalloc ( +sizeof (*umem->async_req) * umem->async_req_max, +GFP_KERNEL ); + +#define SYNC_REQ_MAX (KVM_MAX_VCPUS) +if (create->sync_req_max ==0 ) + create->sync_req_max =SYNC_REQ_MAX ; + umem->sync_req_max =round_up (create->sync_req_max,BITS_PER_LONG ); + sync_bitmap_bytes =sizeof (unsigned long ) * + (umem->sync_req_max /BITS_PER_LONG ); + umem->sync_req_bitmap =kzalloc (sync_bitmap_bytes,GFP_KERNEL ); + umem->sync_wait_bitmap =kzalloc (sync_bitmap_bytes,GFP_KERNEL ); + umem->page_wait =kzalloc (sizeof (*umem->page_wait) * + umem->sync_req_max,GFP_KERNEL ); +for (i =0 ; i < umem->sync_req_max; ++i) +init_waitqueue_head (&umem->page_wait[i]); + umem->sync_req =kzalloc (sizeof (*umem->sync_req) * + umem->sync_req_max,GFP_KERNEL ); + + umem->req_list_nr =0 ; +INIT_LIST_HEAD (&umem->req_list); +init_waitqueue_head (&umem->req_list_wait); + +mutex_unlock (&umem_list_mutex); +return 0 ; + + out: +umem_free (&umem->kref); +return error; +} + + +static int umem_reattach_umem (struct umem_create *create) +{ +struct umem *entry; + +mutex_lock (&umem_list_mutex); +list_for_each_entry (entry, &umem_list, list) { +if (umem_name_eq (&entry->name, &create->name)) { +kref_get (&entry->kref); +mutex_unlock (&umem_list_mutex); + + create->shmem_fd =get_unused_fd (); +if (create->shmem_fd <0 ) { +umem_put (entry); +return create->shmem_fd; + } + create->umem_fd =anon_inode_getfd ( +"umem" , &umem_fops, entry,O_RDWR ); +if (create->umem_fd <0 ) { +put_unused_fd (create->shmem_fd); +umem_put (entry); +return create->umem_fd; + } +get_file (entry->shmem_filp); +fd_install (create->shmem_fd, entry->shmem_filp); +
drivers/char/umem.c line 814
Quoted 10 lines
drivers/char/umem.c new file +10
-0+ create->size = entry->size; + create->sync_req_max = entry->sync_req_max; + create->async_req_max = entry->async_req_max; +return 0 ; + } + } +mutex_unlock (&umem_list_mutex); + +return -ENOENT ; +}
Can you explain how reattach is used?
Quoted 12 lines
drivers/char/umem.c new file +12
-0+ +static long umem_dev_ioctl (struct file *filp,unsigned int ioctl, +unsigned long arg) +{ +void __user *argp = (void __user *) arg; +long ret; +struct umem_create *create =NULL ; + + +switch (ioctl) { +case UMEM_DEV_CREATE_UMEM : + create =kmalloc (sizeof (*create),GFP_KERNEL );
drivers/char/umem.c line 836
Quoted 10 lines
drivers/char/umem.c new file +10
-0+if (copy_from_user (create, argp,sizeof (*create))) { + ret = -EFAULT ; +break ; + } + ret =umem_create_umem (create); +if (copy_to_user (argp, create,sizeof (*create))) { + ret = -EFAULT ; +break ; + } +break ;
A simpler approach is the open("/dev/umem") returns an mmap()able fd. You need to call an ioctl() to set the size, etc. but only you only operate on that fd.
Quoted 20 lines
drivers/char/umem.c new file +20
-0+case UMEM_DEV_LIST : + ret =umem_list_umem (argp); +break ; +case UMEM_DEV_REATTACH : + create =kmalloc (sizeof (*create),GFP_KERNEL ); +if (copy_from_user (create, argp,sizeof (*create))) { + ret = -EFAULT ; +break ; + } + ret =umem_reattach_umem (create); +if (copy_to_user (argp, create,sizeof (*create))) { + ret = -EFAULT ; +break ; + } +break ; +default : + ret = -EINVAL ; +break ; + } +
drivers/char/umem.c
Quoted 10 lines
drivers/char/umem.c new file +10
-0+kfree (create); +return ret; +} + + +#ifdef __KERNEL__ +#include <linux/compiler.h> +#else +#define __user +#endif
I think a #include <linux/compiler.h> is sufficient, the export process (see include/linux/Kbuild, add an entry there) takes care of __user.
include/linux/umem.h line 42
Quoted 8 lines
include/linux/umem.h new file +8
-0+ +#define UMEM_ID_MAX 256 +#define UMEM_NAME_MAX 256 + +struct umem_name { +char id[UMEM_ID_MAX ];/* non-zero terminated */ +char name[UMEM_NAME_MAX ];/* non-zero terminated */ +};
IMO, it would be better to avoid names, and use opaque __u64 identifiers assigned by userspace, or perhaps file descriptors generated by the kernel. With names come the complications of namespaces, etc. One user can DoS another by grabbing a name that it knows the other user wants to use.
include/linux/umem.h line 60
Quoted 12 lines
include/linux/umem.h new file +12
-0+ +struct umem_create { +__u64 size;/* in bytes */ +__s32 umem_fd; +__s32 shmem_fd; +__u32 async_req_max; +__u32 sync_req_max; +struct umem_name name; +}; + +struct umem_page_request { +__u64 __user *pgoffs;
Pointers change their size in 32-bit and 64-bit userspace, best to avoid them.
Quoted 5 lines
include/linux/umem.h new file +5
-0+__u32 nr; +__u32 padding; +}; + +struct umem_page_cached {
include/linux/umem.h line 75
Quoted 10 lines
include/linux/umem.h new file +10
-0+__u64 __user *pgoffs; +__u32 nr; +__u32 padding; +}; + +#define UMEMIO 0x1E + +/* ioctl for umem_dev fd */ +#define UMEM_DEV_CREATE_UMEM _IOWR(UMEMIO, 0x0, struct umem_create) +#define UMEM_DEV_LIST _IOWR(UMEMIO, 0x1, struct umem_list)
Why is _LIST needed?
include/linux/umem.h line 80
Quoted 5 lines
include/linux/umem.h new file +5
-0+#define UMEM_DEV_REATTACH _IOWR(UMEMIO, 0x2, struct umem_create) + +/* ioctl for umem fd */ +#define UMEM_GET_PAGE_REQUEST _IOWR(UMEMIO, 0x10, struct umem_page_request) +#define UMEM_MARK_PAGE_CACHED _IOW (UMEMIO, 0x11, struct umem_page_cached)
You could make the GET_PAGE_REQUEST / MARK_PAGE_CACHED protocol run over file descriptors, instead of an ioctl. It allows you to implement the other side in either the kernel or userspace. This is similar to how kvm uses an eventfd for communication with vhost-net in the kernel, or an implementation in userspace.
Quoted 3 lines
include/linux/umem.h new file +3
-0+#define UMEM_MAKE_VMA_ANONYMOUS _IO (UMEMIO, 0x12) + +#endif /* __LINUX_UMEM_H */
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · Isaku Yamahata
This is Linux kernel driver for qemu/kvm postcopy live migration. This is used by qemu/kvm postcopy live migration patch.
TODO:
- Consider FUSE/CUSE option
So far several mmap patches for FUSE/CUSE are floating around. (their purpose isn't different from our purpose, though). They haven't merged into the upstream yet.
The driver specific part in qemu patches is modularized. So I expect it wouldn't be difficult to switch kernel driver to CUSE based driver.
It would be good to get more input about this, please involve lkml and the FUSE/CUSE people.
Quoted 9 lines
ioctl commands:
UMEM_DEV_CRATE_UMEM: create umem device for qemuUMEM_DEV_LIST: list created umem devicesUMEM_DEV_REATTACH: re-attach the created umem device
UMEM_DEV_LISTandUMEM_DEV_REATTACHare used when the process that services page fault disappears or get stack. Then, administrator can list the umem devices and unblock the process which is waiting for page.
Ah, I asked about this in my patch comments. I think this is done better by using SCM_RIGHTS to pass fds along, or asking qemu to launch a new process.
Introducing a global namespace has a lot of complications attached.
Quoted 9 lines
UMEM_GET_PAGE_REQUEST: retrieve page fault of qemu processUMEM_MARK_PAGE_CACHED: mark the specified pages pulled from the source
for daemon
UMEM_MAKE_VMA_ANONYMOUS: make the specified vma in the qemu process
This is _NOT_ implemented yet.
anonymous I'm not sure whether this can be implemented or not.
How do we find out? This is fairly important, stuff like transparent hugepages and ksm only works on anonymous memory.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 2/2] umem: chardevice for kvm postcopy
In reply to Avi KivityThank you for review.
Quoted 10 lines · Avi Kivity
drivers/char/Kconfig config DEVKMEM · line 26
Quoted 7 lines
drivers/char/Kconfig +7
-0+ default n + help + User process backed memory driver provides /dev/umem device. + The /dev/umem device is designed for some sort of distributed + shared memory. Especially post-copy live migration with KVM. + When in doubt, say "N". +Need documentation of the protocol between the kernel and userspace; not just the ioctls, but also how faults are propagated.
Will do.
Quoted 154 lines
Quoted 30 lines
drivers/char/umem.c new file +28
-0+ +struct umem_page_req_list { +struct list_head list; +pgoff_t pgoff; +}; + + + +static int umem_mark_page_cached (struct umem *umem, +struct umem_page_cached *page_cached) +{ +int ret =0 ; +#define PG_MAX ((__u32)32) +__u64 pgoffs[PG_MAX ]; +__u32 nr; +unsigned long bit; +bool wake_up_list = false; + + nr =0 ; +while (nr < page_cached->nr) { +__u32 todo =min (PG_MAX , (page_cached->nr - nr)); +int i; + +if (copy_from_user (pgoffs, page_cached->pgoffs + nr, +sizeof (*pgoffs) * todo)) { + ret = -EFAULT ; + goto out; + }drivers/char/umem.c line 457
Quoted 10 lines
drivers/char/umem.c new file +10
-0+for (i =0 ; i < todo; ++i) { +if (pgoffs[i] >= umem->pgoff_end) { + ret = -EINVAL ; + goto out; + } +set_bit (pgoffs[i], umem->cached); + } + nr += todo; + } +Probably need an
smp_wmb()where.drivers/char/umem.c line 466
Quoted 9 lines
drivers/char/umem.c new file +9
-0+spin_lock (&umem->lock); + bit =0 ; +for (;;) { + bit =find_next_bit (umem->sync_wait_bitmap, umem->sync_req_max, + bit); +if (bit >= umem->sync_req_max) +break ; +if (test_bit (umem->sync_req[bit], umem->cached)) +wake_up (&umem->page_wait[bit]);Why not do this test in the loop above?
Quoted 15 lines
drivers/char/umem.c new file +15
-0+ bit++; + } + +if (umem->req_list_nr >0 ) + wake_up_list = true; +spin_unlock (&umem->lock); + +if (wake_up_list) +wake_up_all (&umem->req_list_wait); + +out: +return ret; +} + +drivers/char/umem.c line 591
Quoted 10 lines
drivers/char/umem.c new file +10
-0+ +static void umem_put (struct umem *umem) +{ +int ret; + +mutex_lock (&umem_list_mutex); + ret =kref_put (&umem->kref, umem_free); +if (ret ==0 ) { +mutex_unlock (&umem_list_mutex); + }This looks wrong.
Quoted 71 lines
drivers/char/umem.c new file +71
-0+} + + +static int umem_create_umem (struct umem_create *create) +{ +int error =0 ; +struct umem *umem =NULL ; +struct vm_area_struct *vma; +int shmem_fd; +unsigned long bitmap_bytes; +unsigned long sync_bitmap_bytes; +int i; + + umem =kzalloc (sizeof (*umem),GFP_KERNEL ); + umem->name = create->name; +kref_init (&umem->kref); +INIT_LIST_HEAD (&umem->list); + +mutex_lock (&umem_list_mutex); + error =umem_add_list (umem); +if (error) { + goto out; + } + + umem->task =NULL ; + umem->mmapped = false; +spin_lock_init (&umem->lock); + umem->size =roundup (create->size,PAGE_SIZE ); + umem->pgoff_end = umem->size >>PAGE_SHIFT ; +init_waitqueue_head (&umem->req_wait); + + vma = &umem->vma; + vma->vm_start =0 ; + vma->vm_end = umem->size; +/* this shmem file is used for temporal buffer for pages +so it's unlikely that so many pages exists in this shmem file */ + vma->vm_flags =VM_READ |VM_SHARED |VM_NOHUGEPAGE |VM_DONTCOPY | +VM_DONTEXPAND ; + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_pgoff =0 ; +INIT_LIST_HEAD (&vma->anon_vma_chain); + + shmem_fd =get_unused_fd (); +if (shmem_fd <0 ) { + error = shmem_fd; + goto out; + } + error =shmem_zero_setup (vma); +if (error <0 ) { +put_unused_fd (shmem_fd); + goto out; + } + umem->shmem_filp = vma->vm_file; +get_file (umem->shmem_filp); +fd_install (shmem_fd, vma->vm_file); + create->shmem_fd = shmem_fd; + + create->umem_fd =anon_inode_getfd ("umem" , + &umem_fops, umem,O_RDWR ); +if (create->umem_fd <0 ) { + error = create->umem_fd; + goto out; + } + + bitmap_bytes =umem_bitmap_bytes (umem); +if (bitmap_bytes >PAGE_SIZE ) { + umem->cached =vzalloc (bitmap_bytes); + umem->faulted =vzalloc (bitmap_bytes); + }else { + umem->cached =kzalloc (bitmap_bytes,GFP_KERNEL ); + umem->faulted =kzalloc (bitmap_bytes,GFP_KERNEL );
Quoted 8 lines
drivers/char/umem.c line 709
Quoted 6 lines
drivers/char/umem.c new file +6
-0+ } + +/* those constants are not exported. +They are just used for default value */ +#define KVM_MAX_VCPUS 256 +#define ASYNC_PF_PER_VCPU 64Best to avoid defaults and require userspace choose.
Okay.
Quoted 94 lines
Quoted 63 lines
drivers/char/umem.c new file +63
-0+ +#define ASYNC_REQ_MAX (ASYNC_PF_PER_VCPU * KVM_MAX_VCPUS) +if (create->async_req_max ==0 ) + create->async_req_max =ASYNC_REQ_MAX ; + umem->async_req_max = create->async_req_max; + umem->async_req_nr =0 ; + umem->async_req =kzalloc ( +sizeof (*umem->async_req) * umem->async_req_max, +GFP_KERNEL ); + +#define SYNC_REQ_MAX (KVM_MAX_VCPUS) +if (create->sync_req_max ==0 ) + create->sync_req_max =SYNC_REQ_MAX ; + umem->sync_req_max =round_up (create->sync_req_max,BITS_PER_LONG ); + sync_bitmap_bytes =sizeof (unsigned long ) * + (umem->sync_req_max /BITS_PER_LONG ); + umem->sync_req_bitmap =kzalloc (sync_bitmap_bytes,GFP_KERNEL ); + umem->sync_wait_bitmap =kzalloc (sync_bitmap_bytes,GFP_KERNEL ); + umem->page_wait =kzalloc (sizeof (*umem->page_wait) * + umem->sync_req_max,GFP_KERNEL ); +for (i =0 ; i < umem->sync_req_max; ++i) +init_waitqueue_head (&umem->page_wait[i]); + umem->sync_req =kzalloc (sizeof (*umem->sync_req) * + umem->sync_req_max,GFP_KERNEL ); + + umem->req_list_nr =0 ; +INIT_LIST_HEAD (&umem->req_list); +init_waitqueue_head (&umem->req_list_wait); + +mutex_unlock (&umem_list_mutex); +return 0 ; + + out: +umem_free (&umem->kref); +return error; +} + + +static int umem_reattach_umem (struct umem_create *create) +{ +struct umem *entry; + +mutex_lock (&umem_list_mutex); +list_for_each_entry (entry, &umem_list, list) { +if (umem_name_eq (&entry->name, &create->name)) { +kref_get (&entry->kref); +mutex_unlock (&umem_list_mutex); + + create->shmem_fd =get_unused_fd (); +if (create->shmem_fd <0 ) { +umem_put (entry); +return create->shmem_fd; + } + create->umem_fd =anon_inode_getfd ( +"umem" , &umem_fops, entry,O_RDWR ); +if (create->umem_fd <0 ) { +put_unused_fd (create->shmem_fd); +umem_put (entry); +return create->umem_fd; + } +get_file (entry->shmem_filp); +fd_install (create->shmem_fd, entry->shmem_filp); +drivers/char/umem.c line 814
Quoted 10 lines
drivers/char/umem.c new file +10
-0+ create->size = entry->size; + create->sync_req_max = entry->sync_req_max; + create->async_req_max = entry->async_req_max; +return 0 ; + } + } +mutex_unlock (&umem_list_mutex); + +return -ENOENT ; +}Can you explain how reattach is used?
Quoted 18 lines
drivers/char/umem.c new file +18
-0+ +static long umem_dev_ioctl (struct file *filp,unsigned int ioctl, +unsigned long arg) +{ +void __user *argp = (void __user *) arg; +long ret; +struct umem_create *create =NULL ; + + +switch (ioctl) { +case UMEM_DEV_CREATE_UMEM : + create =kmalloc (sizeof (*create),GFP_KERNEL ); +if (copy_from_user (create, argp,sizeof (*create))) { + ret = -EFAULT ; +break ; + } + ret =umem_create_umem (create); +if (copy_to_user (argp, create,sizeof (*create))) {
Quoted 8 lines
drivers/char/umem.c line 554
Quoted 4 lines
drivers/char/umem.c new file +4
-0+ ret = -EFAULT ; +break ; + } +break ;A simpler approach is the
open("/dev/umem")returns an mmap()able fd. You need to call anioctl()to set the size, etc. but only you only operate on that fd.
So you are suggesting that /dev/umem and /dev/umemctl should be introduced and split the functionality.
Quoted 34 lines
Quoted 20 lines
drivers/char/umem.c new file +20
-0+case UMEM_DEV_LIST : + ret =umem_list_umem (argp); +break ; +case UMEM_DEV_REATTACH : + create =kmalloc (sizeof (*create),GFP_KERNEL ); +if (copy_from_user (create, argp,sizeof (*create))) { + ret = -EFAULT ; +break ; + } + ret =umem_reattach_umem (create); +if (copy_to_user (argp, create,sizeof (*create))) { + ret = -EFAULT ; +break ; + } +break ; +default : + ret = -EINVAL ; +break ; + } +drivers/char/umem.c
Quoted 10 lines
drivers/char/umem.c new file +10
-0+kfree (create); +return ret; +} + + +#ifdef __KERNEL__ +#include <linux/compiler.h> +#else +#define __user +#endif I think a #include <
linux/compiler.h> is sufficient, the export process (seeinclude/linux/Kbuild, add an entry there) takes care of__user.
Quoted 14 lines
include/linux/umem.h line 42
Quoted 8 lines
include/linux/umem.h new file +8
-0+ +#define UMEM_ID_MAX 256 +#define UMEM_NAME_MAX 256 + +struct umem_name { +char id[UMEM_ID_MAX ];/* non-zero terminated */ +char name[UMEM_NAME_MAX ];/* non-zero terminated */ +};IMO, it would be better to avoid names, and use opaque
__u64identifiers assigned by userspace, or perhaps file descriptors generated by the kernel. With names come the complications of namespaces, etc. One user can DoS another by grabbing a name that it knows the other user wants to use.
So how about the kernel assigning identifiers which is system global?
Quoted 7 lines
Quoted 7 lines
include/linux/umem.h new file +7
-0+ +struct umem_create { +__u64 size;/* in bytes */ +__s32 umem_fd; +__s32 shmem_fd; +__u32 async_req_max; +__u32 sync_req_max;
Quoted 8 lines
include/linux/umem.h line 60
Quoted 5 lines
include/linux/umem.h new file +5
-0+struct umem_name name; +}; + +struct umem_page_request { +__u64 __user *pgoffs;Pointers change their size in 32-bit and 64-bit userspace, best to avoid them.
Ah yes, right. How about following?
struct {
__u32 nr;
__u32 padding;
__u64 pgoffs[0];
}Quoted 18 lines
Quoted 5 lines
include/linux/umem.h new file +5
-0+__u32 nr; +__u32 padding; +}; + +struct umem_page_cached {include/linux/umem.h line 75
Quoted 10 lines
include/linux/umem.h new file +10
-0+__u64 __user *pgoffs; +__u32 nr; +__u32 padding; +}; + +#define UMEMIO 0x1E + +/* ioctl for umem_dev fd */ +#define UMEM_DEV_CREATE_UMEM _IOWR(UMEMIO, 0x0, struct umem_create) +#define UMEM_DEV_LIST _IOWR(UMEMIO, 0x1, struct umem_list)Why is
_LISTneeded?
Quoted 11 lines
include/linux/umem.h line 80
Quoted 5 lines
include/linux/umem.h new file +5
-0+#define UMEM_DEV_REATTACH _IOWR(UMEMIO, 0x2, struct umem_create) + +/* ioctl for umem fd */ +#define UMEM_GET_PAGE_REQUEST _IOWR(UMEMIO, 0x10, struct umem_page_request) +#define UMEM_MARK_PAGE_CACHED _IOW (UMEMIO, 0x11, struct umem_page_cached)You could make the
GET_PAGE_REQUEST/MARK_PAGE_CACHEDprotocol run over file descriptors, instead of an ioctl. It allows you to implement the other side in either the kernel or userspace. This is similar to how kvm uses an eventfd for communication with vhost-net in the kernel, or an implementation in userspace.
Do you mean that read/write on file descriptors is better than ioctl? Okay, it would be easy to convert ioctl into read/write.
Quoted 8 lines
Quoted 3 lines
include/linux/umem.h new file +3
-0+#define UMEM_MAKE_VMA_ANONYMOUS _IO (UMEMIO, 0x12) + +#endif /* __LINUX_UMEM_H */ Signature · 1 line
error compiling committee.c: too many arguments to function
Signature · 1 line
yamahata
Quoted 12 lines · Avi Kivity
Quoted 10 lines · Isaku Yamahata
This is Linux kernel driver for qemu/kvm postcopy live migration. This is used by qemu/kvm postcopy live migration patch.
TODO:
- Consider FUSE/CUSE option
So far several mmap patches for FUSE/CUSE are floating around. (their purpose isn't different from our purpose, though). They haven't merged into the upstream yet.
The driver specific part in qemu patches is modularized. So I expect it wouldn't be difficult to switch kernel driver to CUSE based driver.
Quoted 2 lines
It would be good to get more input about this, please involve lkml and the FUSE/CUSE people.
Okay.
Quoted 10 lines
Quoted 9 lines
ioctl commands:
UMEM_DEV_CRATE_UMEM: create umem device for qemuUMEM_DEV_LIST: list created umem devicesUMEM_DEV_REATTACH: re-attach the created umem device
UMEM_DEV_LISTandUMEM_DEV_REATTACHare used when the process that services page fault disappears or get stack. Then, administrator can list the umem devices and unblock the process which is waiting for page.
Quoted 3 lines
Ah, I asked about this in my patch comments. I think this is done better by using
SCM_RIGHTSto pass fds along, or asking qemu to launch a new process.
Can you please elaborate? I think those ways you are suggesting doesn't solve the issue. Let me clarify the problem.
process A (typically incoming qemu)
|
| mmap("/dev/umem") and access those pages triggering page faults
| (the file descriptor might be closed after mmap() before page faults)
|
V
/dev/umem
^
|
|daemon X resolving page faults triggered by process A (typically this daemon forked from incoming qemu:process A)
If daemon X disappears accidentally, there is no one that resolves page faults of process A. At this moment process A is blocked due to page fault. There is no file descriptor available corresponding to the VMA. Here there is no way to kill process A, but system reboot.
Quoted 7 lines
Introducing a global namespace has a lot of complications attached.
Quoted 5 lines
UMEM_GET_PAGE_REQUEST: retrieve page fault of qemu processUMEM_MARK_PAGE_CACHED: mark the specified pages pulled from the source
for daemon
Quoted 7 lines
Quoted 4 lines
UMEM_MAKE_VMA_ANONYMOUS: make the specified vma in the qemu process
This is _NOT_ implemented yet.
anonymous I'm not sure whether this can be implemented or not.How do we find out? This is fairly important, stuff like transparent hugepages and ksm only works on anonymous memory.
I agree that this is important.
At KVM-forum 2011, Andrea said THP and KSM works with non-anonymous VMA. (Or at lease he'll look into those stuff. My memory is vague, though.
Please correct me if I'm wrong)
Signature · 1 line
yamahata
Re: [PATCH 2/2] umem: chardevice for kvm postcopy
In reply to Isaku YamahataQuoted 7 lines · Isaku Yamahata
Quoted 4 lines
A simpler approach is the
open("/dev/umem")returns an mmap()able fd. You need to call anioctl()to set the size, etc. but only you only operate on that fd.So you are suggesting that
/dev/umemand/dev/umemctlshould be introduced and split the functionality.
No; perhaps I'm missing some functionality, but I'm suggesting
fd = open("/dev/umem");
ftruncate(fd, size);
struct umem_config config = { ... };
ioctl(fd, UMEM_CONFIG, &config);
mmap(..., fd, size);Quoted 8 lines
Quoted 6 lines
IMO, it would be better to avoid names, and use opaque
__u64identifiers assigned by userspace, or perhaps file descriptors generated by the kernel. With names come the complications of namespaces, etc. One user can DoS another by grabbing a name that it knows the other user wants to use.So how about the kernel assigning identifiers which is system global?
Depends on what you do with the identifiers. Something like reattach needs security, you can't just reattach to any random umem segment.
It's really best to stick with file descriptors, which already have a security model.
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
include/linux/umem.h new file +2
-0+ +struct umem_create {include/linux/umem.h line 60
Quoted 10 lines
include/linux/umem.h new file +10
-0+__u64 size;/* in bytes */ +__s32 umem_fd; +__s32 shmem_fd; +__u32 async_req_max; +__u32 sync_req_max; +struct umem_name name; +}; + +struct umem_page_request { +__u64 __user *pgoffs;Pointers change their size in 32-bit and 64-bit userspace, best to avoid them.
Quoted 6 lines
Ah yes, right. How about following?
struct { __u32 nr; __u32 padding; __u64 pgoffs[0]; }
Sure.
If we use a pipe to transport requests, you can just send them as a sequence of __u64 addresses.
Quoted 11 lines
Quoted 10 lines
include/linux/umem.h line 80
Quoted 4 lines
include/linux/umem.h new file +4
-0+ +/* ioctl for umem fd */ +#define UMEM_GET_PAGE_REQUEST _IOWR(UMEMIO, 0x10, struct umem_page_request) +#define UMEM_MARK_PAGE_CACHED _IOW (UMEMIO, 0x11, struct umem_page_cached)You could make the
GET_PAGE_REQUEST/MARK_PAGE_CACHEDprotocol run over file descriptors, instead of an ioctl. It allows you to implement the other side in either the kernel or userspace. This is similar to how kvm uses an eventfd for communication with vhost-net in the kernel, or an implementation in userspace.
Quoted 2 lines
Do you mean that read/write on file descriptors is better than ioctl? Okay, it would be easy to convert ioctl into read/write.
Yes, they already provide synchronization. And if you want to implement a umem provider over RDMA in the kernel, then it's easy to add it; it's not trivial for the kernel to issue ioctls but reads/writes are easy.
It's also easy to pass file descriptors among processes.
How do FUSE/CUSE pass requests?
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 27 lines · Isaku Yamahata
Quoted 10 lines
Quoted 9 lines
ioctl commands:
UMEM_DEV_CRATE_UMEM: create umem device for qemuUMEM_DEV_LIST: list created umem devicesUMEM_DEV_REATTACH: re-attach the created umem device
UMEM_DEV_LISTandUMEM_DEV_REATTACHare used when the process that services page fault disappears or get stack. Then, administrator can list the umem devices and unblock the process which is waiting for page.Quoted 3 lines
Ah, I asked about this in my patch comments. I think this is done better by using
SCM_RIGHTSto pass fds along, or asking qemu to launch a new process.Can you please elaborate? I think those ways you are suggesting doesn't solve the issue. Let me clarify the problem.
process A (typically incoming qemu)
| | mmap("/dev/umem") and access those pages triggering page faults | (the file descriptor might be closed after mmap() before page faults) | V /dev/umem ^ | |
Quoted 7 lines
daemon X resolving page faults triggered by process A (typically this daemon forked from incoming qemu:process A)
If daemon X disappears accidentally, there is no one that resolves page faults of process A. At this moment process A is blocked due to page fault. There is no file descriptor available corresponding to the VMA. Here there is no way to kill process A, but system reboot.
qemu can have an extra thread that wait4()s the daemon, and relaunch it. This extra thread would not be blocked by the page fault. It can keep the fd so it isn't lost.
The unkillability of process A is a security issue; it could be done on purpose. Is it possible to change umem to sleep with TASK_INTERRUPTIBLE, so it can be killed?
Quoted 12 lines
Quoted 12 lines
Introducing a global namespace has a lot of complications attached.
Quoted 9 lines
UMEM_GET_PAGE_REQUEST: retrieve page fault of qemu processUMEM_MARK_PAGE_CACHED: mark the specified pages pulled from the source
for daemon
UMEM_MAKE_VMA_ANONYMOUS: make the specified vma in the qemu process
This is _NOT_ implemented yet.
anonymous I'm not sure whether this can be implemented or not.
Quoted 7 lines
Quoted 2 lines
How do we find out? This is fairly important, stuff like transparent hugepages and ksm only works on anonymous memory.
I agree that this is important.
At KVM-forum 2011, Andrea said THP and KSM works with non-anonymous VMA. (Or at lease he'll look into those stuff. My memory is vague, though.
Please correct me if I'm wrong)
+= Andrea (who can also provide feedback on umem in general)
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 36 lines · Avi Kivity
Quoted 27 lines · Isaku Yamahata
Quoted 10 lines
Quoted 9 lines
ioctl commands:
UMEM_DEV_CRATE_UMEM: create umem device for qemuUMEM_DEV_LIST: list created umem devicesUMEM_DEV_REATTACH: re-attach the created umem device
UMEM_DEV_LISTandUMEM_DEV_REATTACHare used when the process that services page fault disappears or get stack. Then, administrator can list the umem devices and unblock the process which is waiting for page.Quoted 3 lines
Ah, I asked about this in my patch comments. I think this is done better by using
SCM_RIGHTSto pass fds along, or asking qemu to launch a new process.Can you please elaborate? I think those ways you are suggesting doesn't solve the issue. Let me clarify the problem.
process A (typically incoming qemu)
| | mmap("/dev/umem") and access those pages triggering page faults | (the file descriptor might be closed after mmap() before page faults) | V /dev/umem ^ | |Quoted 7 lines
daemon X resolving page faults triggered by process A (typically this daemon forked from incoming qemu:process A)
If daemon X disappears accidentally, there is no one that resolves page faults of process A. At this moment process A is blocked due to page fault. There is no file descriptor available corresponding to the VMA. Here there is no way to kill process A, but system reboot.
Quoted 7 lines
qemu can have an extra thread that wait4()s the daemon, and relaunch it. This extra thread would not be blocked by the page fault. It can keep the fd so it isn't lost.
The unkillability of process A is a security issue; it could be done on purpose. Is it possible to change umem to sleep with
TASK_INTERRUPTIBLE, so it can be killed?
The issue is how to solve the page fault, not whether TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE.
I can think of several options.
- When daemon X is dead, all page faults are served by zero pages.
- When daemon X is dead, all page faults are resovled as VM_FAULT_SIGBUS
- list/reattach: complications. You don't like it
- other?
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
Introducing a global namespace has a lot of complications attached.
Quoted 9 lines
UMEM_GET_PAGE_REQUEST: retrieve page fault of qemu processUMEM_MARK_PAGE_CACHED: mark the specified pages pulled from the source
for daemon
UMEM_MAKE_VMA_ANONYMOUS: make the specified vma in the qemu process
This is _NOT_ implemented yet.
anonymous I'm not sure whether this can be implemented or not.Quoted 7 lines
Quoted 2 lines
How do we find out? This is fairly important, stuff like transparent hugepages and ksm only works on anonymous memory.
I agree that this is important.
At KVM-forum 2011, Andrea said THP and KSM works with non-anonymous VMA. (Or at lease he'll look into those stuff. My memory is vague, though.
Please correct me if I'm wrong)+= Andrea (who can also provide feedback on umem in general)
Signature · 1 line
error compiling committee.c: too many arguments to function
Signature · 1 line
yamahata
Quoted 9 lines · Isaku Yamahata
Quoted 8 lines
qemu can have an extra thread that wait4()s the daemon, and relaunch it. This extra thread would not be blocked by the page fault. It can keep the fd so it isn't lost.
The unkillability of process A is a security issue; it could be done on purpose. Is it possible to change umem to sleep with
TASK_INTERRUPTIBLE, so it can be killed?
Quoted 7 lines
The issue is how to solve the page fault, not whether
TASK_INTERRUPTIBLEorTASK_UNINTERRUPTIBLE.
I can think of several options.
- When daemon X is dead, all page faults are served by zero pages.
- When daemon X is dead, all page faults are resovled asVM_FAULT_SIGBUS
- list/reattach: complications. You don't like it
- other?
Don't resolve the page fault. It's up to the user/system to make sure it happens. qemu can easily do it by watching for the daemon's death and respawning it.
When the new daemon is started, it can ask the kernel for a list of pending requests, and service them.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 18 lines · Avi Kivity
Quoted 9 lines · Isaku Yamahata
Quoted 8 lines
qemu can have an extra thread that wait4()s the daemon, and relaunch it. This extra thread would not be blocked by the page fault. It can keep the fd so it isn't lost.
The unkillability of process A is a security issue; it could be done on purpose. Is it possible to change umem to sleep with
TASK_INTERRUPTIBLE, so it can be killed?Quoted 7 lines
The issue is how to solve the page fault, not whether
TASK_INTERRUPTIBLEorTASK_UNINTERRUPTIBLE.
I can think of several options.
- When daemon X is dead, all page faults are served by zero pages.
- When daemon X is dead, all page faults are resovled asVM_FAULT_SIGBUS
- list/reattach: complications. You don't like it
- other?
Quoted 6 lines
Don't resolve the page fault. It's up to the user/system to make sure it happens. qemu can easily do it by watching for the daemon's death and respawning it.
When the new daemon is started, it can ask the kernel for a list of pending requests, and service them.
Great, then we agreed with list/reattach basically. (Maybe identity scheme needs reconsideration.)
Signature · 1 line
yamahata
Quoted 13 lines · Isaku Yamahata
Quoted 13 lines
Quoted 8 lines
The issue is how to solve the page fault, not whether
TASK_INTERRUPTIBLEorTASK_UNINTERRUPTIBLE.
I can think of several options.
- When daemon X is dead, all page faults are served by zero pages.
- When daemon X is dead, all page faults are resovled asVM_FAULT_SIGBUS
- list/reattach: complications. You don't like it
- other?Don't resolve the page fault. It's up to the user/system to make sure it happens. qemu can easily do it by watching for the daemon's death and respawning it.
Quoted 5 lines
Quoted 2 lines
When the new daemon is started, it can ask the kernel for a list of pending requests, and service them.
Great, then we agreed with list/reattach basically. (Maybe identity scheme needs reconsideration.)
I guess we miscommunicated. Why is reattach needed? If you have the fd, nothing else is needed.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Isaku Yamahata
Quoted 13 lines
Quoted 8 lines
The issue is how to solve the page fault, not whether
TASK_INTERRUPTIBLEorTASK_UNINTERRUPTIBLE.
I can think of several options.
- When daemon X is dead, all page faults are served by zero pages.
- When daemon X is dead, all page faults are resovled asVM_FAULT_SIGBUS
- list/reattach: complications. You don't like it
- other?Don't resolve the page fault. It's up to the user/system to make sure it happens. qemu can easily do it by watching for the daemon's death and respawning it.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
When the new daemon is started, it can ask the kernel for a list of pending requests, and service them.
Great, then we agreed with list/reattach basically. (Maybe identity scheme needs reconsideration.)
I guess we miscommunicated. Why is reattach needed? If you have the fd, nothing else is needed.
What if malicious process close the fd and does page fault intentionally? Unkillable process issue remains.
I think we are talking not only qemu case but also general case.
Signature · 1 line
yamahata
Quoted 9 lines · Isaku Yamahata
Quoted 5 lines
Quoted 2 lines
Great, then we agreed with list/reattach basically. (Maybe identity scheme needs reconsideration.)
I guess we miscommunicated. Why is reattach needed? If you have the fd, nothing else is needed.
What if malicious process close the fd and does page fault intentionally? Unkillable process issue remains.
I think we are talking not only qemu case but also general case.
It's not unkillable. If you sleep with TASK_INTERRUPTIBLE then you can process signals. This includes SIGKILL.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Isaku Yamahata
Quoted 5 lines
Quoted 2 lines
Great, then we agreed with list/reattach basically. (Maybe identity scheme needs reconsideration.)
I guess we miscommunicated. Why is reattach needed? If you have the fd, nothing else is needed.
Quoted 6 lines
Quoted 3 lines
What if malicious process close the fd and does page fault intentionally? Unkillable process issue remains.
I think we are talking not only qemu case but also general case.It's not unkillable. If you sleep with
TASK_INTERRUPTIBLEthen you can process signals. This includes SIGKILL.
Hmm, you said that the fault handler doesn't resolve the page fault.
Quoted 3 lines
Quoted 3 lines
Don't resolve the page fault. It's up to the user/system to make sure it happens. qemu can easily do it by watching for the daemon's death and respawning it.
To kill the process, the fault handler must return resolving the fault. It must return something. What do you expect? VM_FAULT_SIGBUS? zero page?
Signature · 1 line
yamahata
Quoted 15 lines · Isaku Yamahata
Quoted 7 lines · Avi Kivity
Quoted 6 lines · Isaku Yamahata
Quoted 5 lines
Quoted 2 lines
Great, then we agreed with list/reattach basically. (Maybe identity scheme needs reconsideration.)
I guess we miscommunicated. Why is reattach needed? If you have the fd, nothing else is needed.
Quoted 6 lines
Quoted 3 lines
What if malicious process close the fd and does page fault intentionally? Unkillable process issue remains.
I think we are talking not only qemu case but also general case.It's not unkillable. If you sleep with
TASK_INTERRUPTIBLEthen you can process signals. This includes SIGKILL.
Quoted 8 lines
Hmm, you said that the fault handler doesn't resolve the page fault.
Quoted 3 lines
Quoted 3 lines
Don't resolve the page fault. It's up to the user/system to make sure it happens. qemu can easily do it by watching for the daemon's death and respawning it.
To kill the process, the fault handler must return resolving the fault. It must return something. What do you expect?
VM_FAULT_SIGBUS? zero page?
if (signal_pending(current))
return VM_FAULT_RETRY;
for SIGKILL, the process dies immediately. For other unblocked signals, the process starts executing the signal handler, which isn't dependent on the faulting page (of course the signal handler may itself fault).
The NFS client has exactly the same issue, if you mount it with the intr option. In fact you could use the NFS client as a trivial umem/cuse prototype.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 3 lines · Avi Kivity
The NFS client has exactly the same issue, if you mount it with the intr option. In fact you could use the NFS client as a trivial umem/cuse prototype.
Actually, NFS can return SIGBUS, it doesn't care about restarting daemons.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Avi Kivity
The NFS client has exactly the same issue, if you mount it with the intr option. In fact you could use the NFS client as a trivial umem/cuse prototype.
Actually, NFS can return SIGBUS, it doesn't care about restarting daemons.
During KVMForum I suggested to a few people that it could be done entirely in userland with PROT_NONE. So the problem is if we do it in userland with the current functionality you'll run out of VMAs and slowdown performance too much.
But all you need is the ability to map single pages in the address space. The only special requirement is that a new vma must not be created during the map operation. It'd be very similar to remap_file_pages for MAP_SHARED, it also was created to avoid having to create new vmas on a large MAP_SHARED mapping and no other reason at all. In our case we deal with a large MAP_ANONYMOUS mapping and we must alter the pte without creating new vmas but the problem is very similar to remap_file_pages.
Qemu in the dst node can do:
mmap(MAP_ANONYMOUS....) fault_area_prepare(start, end, signalnr)
prepare_fault_area will map the range with the magic pte.
Then when the signalnr fires, you do:
send(givemepageX)
recv(&tmpaddr_aligned, PAGE_SIZE,...); fault_area_map(final_dest_aligned, tmpaddr_aligned, size)
map_fault_area will check the pgprot of the two vmas mapping final_dest_aligned and tmpaddr_aligned have the same vma->vm_pgprot and various other vma bits, and if all ok, it'll just copy the pte from tmpaddr_aligned, to final_dest_aligned and it'll update the page->index. It can fail if the page is shared to avoid dealing with the non-linearity of the page mapped in multiple vmas.
You basically need a bypass to avoid altering the pgprot of the vma, and enter into the pte a "magic" thing that fires signal handlers if accessed, without having to create new vmas. gup/gup_fast and stuff should just always fallback into handle_mm_fault when encountering such a thing, so returning failure as if gup_fast was run on a address beyond the end of the i_size in the MAP_SHARED case.
THP already works on /dev/zero mmaps as long as it's a MAP_PRIVATE, KSM should work too but I doubt anybody tested it on MAP_PRIVATE of /dev/zero.
The device driver provides an advantage in being self contained but I doubt it's simpler. I suppose after migration is complete you'll still switch the vma back to regular anonymous vma so leading to the same result?
The patch 2/2 is small and self contained so it's quite attractive, I didn't see patch 1/2, was it posted?
Thanks,
Andrea
Paolo Bonzini
maintainerQuoted 10 lines · Andrea Arcangeli
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Avi Kivity
The NFS client has exactly the same issue, if you mount it with the intr option. In fact you could use the NFS client as a trivial umem/cuse prototype.
Actually, NFS can return SIGBUS, it doesn't care about restarting daemons.
During KVMForum I suggested to a few people that it could be done entirely in userland with
PROT_NONE.
Or MAP_NORESERVE.
Anything you do that is CUSE-based should be doable in a separate QEMU thread (rather than a different process that talks to CUSE). If a userspace CUSE-based solution could be done with acceptable performance, the same thing would have the same or better performance if done entirely within QEMU.
Quoted 6 lines
So the problem is if we do it in
userland with the current functionality you'll run out of VMAs and slowdown performance too much.But all you need is the ability to map single pages in the address space.
Would this also let you set different pgprots for different pages in the same VMA? It would be useful for write barriers in garbage collectors (such as boehm-gc). These do not have _that_ many VMAs, because every GC cycles could merge all of them back to a single VMA with PROT_READ permissions; however, they still put some strain on the VM subsystem.
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · Andrea Arcangeli
Quoted 5 lines · Avi Kivity
Quoted 3 lines · Avi Kivity
The NFS client has exactly the same issue, if you mount it with the intr option. In fact you could use the NFS client as a trivial umem/cuse prototype.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Actually, NFS can return SIGBUS, it doesn't care about restarting daemons.
During KVMForum I suggested to a few people that it could be done entirely in userland with
PROT_NONE.Or
MAP_NORESERVE.
MAP_NORESERVE has no effect with the default /proc/sys/vm/overcommit_memory == 0, and in general has no effect until you run out of memory. It's an accounting on/off switch only, mostly a noop.
Quoted 5 lines
Anything you do that is CUSE-based should be doable in a separate QEMU thread (rather than a different process that talks to CUSE). If a userspace CUSE-based solution could be done with acceptable performance, the same thing would have the same or better performance if done entirely within QEMU.
It should be somehow doable within qemu and the source node could handle one connection per vcpu thread for the async network pageins.
Quoted 4 lines
Quoted 4 lines
So the problem is if we do it in
userland with the current functionality you'll run out of VMAs and slowdown performance too much.
Quoted 8 lines
Quoted 2 lines
But all you need is the ability to map single pages in the address space.
Would this also let you set different pgprots for different pages in the same VMA? It would be useful for write barriers in garbage collectors (such as boehm-gc). These do not have _that_ many VMAs, because every GC cycles could merge all of them back to a single VMA with
PROT_READpermissions; however, they still put some strain on the VM subsystem.
Changing permission sounds more tricky as more code may make assumptions on the vma before checking the pte.
Adding a magic unmapped pte entry sounds fairly safe because there's the migration pte already used by migrate which halts page faults and wait, that creates a precedent. So I guess we could reuse the same code that already exists for the migration entry and we'd need to fire a signal and returns to userland instead of waiting. The signal should be invoked before the page fault will trigger again. Of course if the signal returns and does nothing it'll loop at 100% cpu load but that's ok. Maybe it's possible to tweak the permissions but it will need a lot more thoughts. Specifically for anon pages marking them readonly sounds possible if they are supposed to behave like regular COWs (not segfaulting or anything), as you already can have a mixture of readonly and read-write ptes (not to tell readonly KSM pages), but for any other case it's non trivial. Last but not the least the API here would be like a vma-less-mremap, moving a page from one address to another without modifying the vmas, the permission tweak sounds more like an mprotect, so I'm unsure if it could do both or if it should be an optimization to consider independently.
In theory I suspect we could also teach mremap to do a not-vma-mangling mremap if we move pages that aren't shared and so we can adjust the page->index of the pages, instead of creating new vmas at the dst address with an adjusted vma->vm_pgoff, but I suspect a syscall that only works on top of fault-unmapped areas is simpler and safer. mremap semantics requires nuking the dst region before the move starts. If we would teach mremap how to handle the fault-unmapped areas we could just add one syscall prepare_fault_area (or whatever name you choose).
The locking of doing a vma-less-mremap still sounds tricky but I doubt you can avoid that locking complexity by using the chardevice as long as the chardevice backed-memory still allows THP, migration and swap, if you want to do it atomic-zerocopy and I think zerocopy would be better especially if the network card is fast and all vcpus are faulting into unmapped pages simultaneously so triggering heavy amount of copying from all physical cpus.
I don't mean the current device driver doing a copy_user won't work or is bad idea, it's more self contained and maybe easier to merge upstream. I'm just presenting another option more VM integrated zerocopy with just 2 syscalls.
vmas must not be involved in the mremap for reliability, or too much memory could get pinned in vmas even if we temporary lift the /proc/sys/vm/max_map_count for the process. Plus sending another signal (not sigsegv or sigbus) should be more reliable in case the migration crashes for real.
Quoted 42 lines · Andrea Arcangeli
Quoted 6 lines · Avi Kivity
Quoted 3 lines · Avi Kivity
The NFS client has exactly the same issue, if you mount it with the intr option. In fact you could use the NFS client as a trivial umem/cuse prototype.
Actually, NFS can return SIGBUS, it doesn't care about restarting daemons.
During KVMForum I suggested to a few people that it could be done entirely in userland with
PROT_NONE. So the problem is if we do it in userland with the current functionality you'll run out of VMAs and slowdown performance too much.But all you need is the ability to map single pages in the address space. The only special requirement is that a new vma must not be created during the map operation. It'd be very similar to
remap_file_pagesforMAP_SHARED, it also was created to avoid having to create new vmas on a largeMAP_SHAREDmapping and no other reason at all. In our case we deal with a largeMAP_ANONYMOUSmapping and we must alter the pte without creating new vmas but the problem is very similar toremap_file_pages.Qemu in the dst node can do:
mmap(MAP_ANONYMOUS....) fault_area_prepare(start, end, signalnr)
prepare_fault_areawill map the range with the magic pte.Then when the signalnr fires, you do:
send(givemepageX)
recv(&tmpaddr_aligned, PAGE_SIZE,...);fault_area_map(final_dest_aligned, tmpaddr_aligned, size)
map_fault_areawill check the pgprot of the two vmas mappingfinal_dest_alignedandtmpaddr_alignedhave the samevma->vm_pgprotand various other vma bits, and if all ok, it'll just copy the pte fromtmpaddr_aligned, tofinal_dest_alignedand it'll update thepage->index. It can fail if the page is shared to avoid dealing with the non-linearity of the page mapped in multiple vmas.
Quoted 6 lines
You basically need a bypass to avoid altering the pgprot of the vma, and enter into the pte a "magic" thing that fires signal handlers if accessed, without having to create new vmas. gup/gup_fast and stuff should just always fallback into
handle_mm_faultwhen encountering such a thing, so returning failure as ifgup_fastwas run on a address beyond the end of thei_sizein theMAP_SHAREDcase.
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
Some people want to investigate guest ram on host (qemu stopped or lively). For example, enhance crash utility and it will attach qemu process and debug guest kernel.
- core dump
qemu process may core-dump.
As postmortem analysis, people want to investigate guest RAM. Again enhance crash utility and it will read the core file and analyze guest kernel.
When creating core, the qemu process is already dead.
It precludes the above possibilities to handle fault in qemu process.
Quoted 3 lines
THP already works on
/dev/zerommaps as long as it's aMAP_PRIVATE, KSM should work too but I doubt anybody tested it onMAP_PRIVATEof/dev/zero.
Oh great. It seems to work with anonymous page generally of non-anonymous VMA. Is that right?
If correct, THP/KSM work with mmap(MAP_PRIVATE, /dev/umem...), do they?
Quoted 4 lines
The device driver provides an advantage in being self contained but I doubt it's simpler. I suppose after migration is complete you'll still switch the vma back to regular anonymous vma so leading to the same result?
Yes, it was my original intention.
The page is anonymous, but the vma isn't anonymous. I concerned that KSM/THP doesn't work with such pages.
If they work, it isn't necessary to switch the VMA into anonymous.
Quoted 2 lines
The patch 2/2 is small and self contained so it's quite attractive, I didn't see patch 1/2, was it posted?
Posted. It's quite short and trivial which just do EXPORT_SYMBOL_GPL of mem_cgroup_cache_chage and shmem_zero_setup.
I include it here for convenience.
Quoted 1 line
From
e8bfda16a845eef4381872a331c6f0f200c3f7d7Mon Sep 17 00:00:00 2001
Message-Id: <e8bfda16a845eef4381872a331c6f0f200c3f7d7.1325055066.git.yamahata@valinux.co.jp>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Isaku Yamahata <[email protected]>
Date: Thu, 11 Aug 2011 20:05:28 +0900
Subject: [PATCH 1/2] export necessary symbols
--- mm/memcontrol.c | 1 + mm/shmem.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
mm/memcontrol.c +1 -0
@@ -2807,6 +2807,7 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,return ret; } +EXPORT_SYMBOL_GPL (mem_cgroup_cache_charge);/* * While swap-in, try_charge -> commit or cancel, the page is locked.
mm/shmem.c +1 -0
@@ -2546,6 +2546,7 @@ int shmem_zero_setup(struct vm_area_struct *vma) vma->vm_flags |=VM_CAN_NONLINEAR ;return 0 ; } +EXPORT_SYMBOL_GPL (shmem_zero_setup);/** * shmem_read_mapping_page_gfp - read into page cache, using specified page allocation flags.
Signature · 4 lines
1.7.1.1 -- yamahata
回复: [PATCH 2/2] umem: chardevice for kvm postcopy
In reply to Isaku Yamahatahi,
I've tried to use this patch,
but it doesn't work for compiling error on
page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?
I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
From: Isaku Yamahata
Date: 2011-12-29 09:26
To: kvm; qemu-devel
CC: yamahata; t.hirofuchi; satoshi.itoh
Subject: [Qemu-devel] [PATCH 2/2] umem: chardevice for kvm postcopy This is a character device to hook page access.
The page fault in the area is reported to another user process by this chardriver. Then, the process fills the page contents and resolves the page fault.
--- drivers/char/Kconfig | 9 + drivers/char/Makefile | 1 + drivers/char/umem.c | 898 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/umem.h | 83 +++++ 4 files changed, 991 insertions(+), 0 deletions(-) create mode 100644 drivers/char/umem.c create mode 100644 include/linux/umem.h
drivers/char/Kconfig +9 -0
@@ -15,6 +15,15 @@ config DEVKMEM kind of kernel debugging operations. When in doubt, say "N". +config UMEM + tristate "/dev/umem user process backed memory support" + default n + help + User process backed memory driver provides /dev/umem device. + The /dev/umem device is designed for some sort of distributed + shared memory. Especially post-copy live migration with KVM. + When in doubt, say "N". + config STALDRV bool "Stallion multiport serial support" depends on SERIAL_NONSTANDARD
drivers/char/Makefile +1 -0
@@ -3,6 +3,7 @@ # obj-y += mem.o random.o +obj-$(CONFIG_UMEM) += umem.o obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o obj-y += misc.o obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
drivers/char/umem.c new file +898 -0
898 lines not on this page · raw message
include/linux/umem.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
1.7.1.1
Re: 回??: [PATCH 2/2] umem: chardevice for kvm postcopy
Quoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,
Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.
drivers/char/umem.c +1 -1
@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {
Signature · 1 line
yamahata
Re: 回??: [PATCH 2/2] umem: chardevice for kvm postcopy
After I use this series of patches, but the migration failed. 2, I start migrate -d -p -n tcp:xxx:4444 on the outgoing node 2, on the incoming part, the qemu get stuck and migration failed the destnation can not typing any more
today I found it's just at qemu_loadvm_state, just after the while loop ,maybe in cpu_synchronize_all_post_init I think there is some problems with qemu side for it doesn't get to the umem part
I'm not sure about the problem
do you have some suggestion?
Tommy
From: Isaku Yamahata
Date: 2012-01-05 18:48
To: thfbjyddx
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel]回??: [PATCH 2/2] umem: chardevice for kvm postcopy
Quoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,
Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.
drivers/char/umem.c +1 -1
@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {
Signature · 1 line
yamahata
Re: 回??: [PATCH 2/2] umem: chardevice for kvm postcopy
Hmm, this sounds like you haven't specified -postcopy option at the incoming qemu.
How did you start incoming qemu?
Quoted 58 lines · Tommy
After I use this series of patches, but the migration failed. 2, I start migrate -d -p -n tcp:xxx:4444 on the outgoing node 2, on the incoming part, the qemu get stuck and migration failed the destnation can not typing any more
today I found it's just at
qemu_loadvm_state, just after the while loop ,maybe incpu_synchronize_all_post_init
I think there is some problems with qemu side for it doesn't get to the umem part
I'm not sure about the problem
do you have some suggestion? ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TommyFrom: Isaku Yamahata
Date: 2012-01-05 18:48
To: thfbjyddx
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel] ??: [PATCH 2/2] umem: chardevice for kvm postcopyQuoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.drivers/char/umem.c +1
-1@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {Signature · 2 lines
-- yamahata
Signature · 1 line
yamahata
Re: 回??: [PATCH 2/2] umem: chardevice for kvm postcopy
qemu -m 256 -hda xxx -monitor stdio -enable-kvm -postcopy -incoming tcp:xxx:4444 -vnc :1
I think it doesn't go wrong
Quoted 64 lines · Isaku Yamahata
Hmm, this sounds like you haven't specified -postcopy option at the incoming qemu.
How did you start incoming qemu?Quoted 58 lines · Tommy
After I use this series of patches, but the migration failed. 2, I start migrate -d -p -n tcp:xxx:4444 on the outgoing node 2, on the incoming part, the qemu get stuck and migration failed the destnation can not typing any more
today I found it's just at
qemu_loadvm_state, just after the while loop ,maybe incpu_synchronize_all_post_init
I think there is some problems with qemu side for it doesn't get to the umem part
I'm not sure about the problem
do you have some suggestion? ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TommyFrom: Isaku Yamahata
Date: 2012-01-05 18:48
To: thfbjyddx
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel] ??: [PATCH 2/2] umem: chardevice for kvm postcopyQuoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.drivers/char/umem.c +1
-1@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {Signature · 2 lines
-- yamahata
Re: 回??: [PATCH 2/2] umem: chardevice for kvm postcopy
In reply to a message not in the archivesorry, it's:
qemu -m 256 -hda xxx -monitor stdio -enable-kvm -postcopy -incoming tcp:0:4444 -vnc :1
anything wrong?
Quoted 69 lines · Tommy Tang
qemu -m 256 -hda xxx -monitor stdio -enable-kvm -postcopy -incoming tcp:xxx:4444 -vnc :1
I think it doesn't go wrongQuoted 64 lines · Isaku Yamahata
Hmm, this sounds like you haven't specified -postcopy option at the incoming qemu.
How did you start incoming qemu?Quoted 58 lines · Tommy
After I use this series of patches, but the migration failed. 2, I start migrate -d -p -n tcp:xxx:4444 on the outgoing node 2, on the incoming part, the qemu get stuck and migration failed the destnation can not typing any more
today I found it's just at
qemu_loadvm_state, just after the while loop ,maybe incpu_synchronize_all_post_init
I think there is some problems with qemu side for it doesn't get to the umem part
I'm not sure about the problem
do you have some suggestion? ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TommyFrom: Isaku Yamahata
Date: 2012-01-05 18:48
To: thfbjyddx
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel] ??: [PATCH 2/2] umem: chardevice for kvm postcopyQuoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.drivers/char/umem.c +1
-1@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {Signature · 2 lines
-- yamahata
Re: 回??: [PATCH 2/2] umem: chardevice for kvm postcopy
In reply to Isaku YamahataHi,
Can you tell me the base version of the qemu?
the postcopy patches make some conflicts on the qemu which I clone from the git Thanks!
Tommy
From: Isaku Yamahata
Date: 2012-01-05 20:18
To: Tommy
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel]回??: [PATCH 2/2] umem: chardevice for kvm postcopy Hmm, this sounds like you haven't specified -postcopy option at the incoming qemu.
How did you start incoming qemu?
Quoted 58 lines · Tommy
After I use this series of patches, but the migration failed. 2, I start migrate -d -p -n tcp:xxx:4444 on the outgoing node 2, on the incoming part, the qemu get stuck and migration failed the destnation can not typing any more
today I found it's just at
qemu_loadvm_state, just after the while loop ,maybe incpu_synchronize_all_post_init
I think there is some problems with qemu side for it doesn't get to the umem part
I'm not sure about the problem
do you have some suggestion? ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TommyFrom: Isaku Yamahata
Date: 2012-01-05 18:48
To: thfbjyddx
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel] ??: [PATCH 2/2] umem: chardevice for kvm postcopyQuoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.drivers/char/umem.c +1
-1@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {Signature · 2 lines
-- yamahata
Signature · 1 line
yamahata
Re: 回??: [PATCH 2/2] umem: chardevice for kvm?postcopy
Quoted 3 lines · thfbjyddx
Hi,
Can you tell me the base version of the qemu?
the postcopy patches make some conflicts on the qemu which I clone from the git
03ecd2c80a64d030a22fe67cc7a60f24e17ff211
Quoted 80 lines
Thanks!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
TommyFrom: Isaku Yamahata
Date: 2012-01-05 20:18
To: Tommy
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel]回??: [PATCH 2/2] umem: chardevice for kvm postcopy Hmm, this sounds like you haven't specified -postcopy option at the incoming qemu.
How did you start incoming qemu?Quoted 6 lines · Tommy
After I use this series of patches, but the migration failed. 2, I start migrate -d -p -n tcp:xxx:4444 on the outgoing node 2, on the incoming part, the qemu get stuck and migration failed the destnation can not typing any more
today I found it's just at
qemu_loadvm_state, just after the while loop ,maybeQuoted 6 lines
in
cpu_synchronize_all_post_init
I think there is some problems with qemu side for it doesn't get to the umem part
I'm not sure about the problem
do you have some suggestion? ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Quoted 46 lines
Tommy
From: Isaku Yamahata
Date: 2012-01-05 18:48
To: thfbjyddx
CC: t.hirofuchi; qemu-devel; kvm; satoshi.itoh
Subject: Re: [Qemu-devel] ??: [PATCH 2/2] umem: chardevice for kvm postcopyQuoted 2 lines · thfbjyddx
hi,
I've tried to use this patch,Oh great! Can we share your results?
Quoted 8 lines
but it doesn't work for compiling error on
page =
alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, vmf->address);//vmf->virtual_address?I guess it's for the wrong kernel version? can you give me some detail about this or any clue? 3x
Thank you for report. The following should fix.
It depends on kernel configuration. My config didn't catch it.drivers/char/umem.c +1
-1@@ -129,7 +129,7 @@ static int umem_minor_fault(struct umem *umem,* vmf->page = fake_vmf->page; */ - page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->address); + page =alloc_page_vma (GFP_HIGHUSER_MOVABLE , vma, vmf->virtual_address);if (!page)return VM_FAULT_OOM ;if (mem_cgroup_cache_charge (page, vma->vm_mm,GFP_KERNEL )) {Signature · 2 lines
-- yamahataSignature · 1 line
yamahata
Signature · 1 line
yamahata
Quoted 17 lines · Andrea Arcangeli
Quoted 5 lines
Quoted 5 lines
So the problem is if we do it in
userland with the current functionality you'll run out of VMAs and slowdown performance too much.Quoted 8 lines
Quoted 2 lines
But all you need is the ability to map single pages in the address space.
Would this also let you set different pgprots for different pages in the same VMA? It would be useful for write barriers in garbage collectors (such as boehm-gc). These do not have _that_ many VMAs, because every GC cycles could merge all of them back to a single VMA with
PROT_READpermissions; however, they still put some strain on the VM subsystem.Changing permission sounds more tricky as more code may make assumptions on the vma before checking the pte.
Quoted 6 lines
Adding a magic unmapped pte entry sounds fairly safe because there's the migration pte already used by migrate which halts page faults and wait, that creates a precedent. So I guess we could reuse the same code that already exists for the migration entry and we'd need to fire a signal and returns to userland instead of waiting. The signal should be invoked before the page fault will trigger again.
Delivering signals is slow, and you can't use signalfd for it, because that can be routed to a different task. I would like an fd based protocol with an explicit ack so the other end can be implemented by the kernel, to use with RDMA. Kind of like how vhost-net talks to a guest via a kvm ioeventfd/irqfd.
Quoted 4 lines
Of course if the
signal returns and does nothing it'll loop at 100% cpu load but that's ok. Maybe it's possible to tweak the permissions but it will need a lot more thoughts. Specifically for anon pages marking them readonly
Quoted 8 lines
sounds possible if they are supposed to behave like regular COWs (not segfaulting or anything), as you already can have a mixture of readonly and read-write ptes (not to tell readonly KSM pages), but for any other case it's non trivial. Last but not the least the API here would be like a vma-less-mremap, moving a page from one address to another without modifying the vmas, the permission tweak sounds more like an mprotect, so I'm unsure if it could do both or if it should be an optimization to consider independently.
Doesn't this stuff require tlb flushes across all threads?
Quoted 19 lines
In theory I suspect we could also teach mremap to do a not-vma-mangling mremap if we move pages that aren't shared and so we can adjust the
page->indexof the pages, instead of creating new vmas at the dst address with an adjustedvma->vm_pgoff, but I suspect a syscall that only works on top of fault-unmapped areas is simpler and safer. mremap semantics requires nuking the dst region before the move starts. If we would teach mremap how to handle the fault-unmapped areas we could just add one syscallprepare_fault_area(or whatever name you choose).The locking of doing a vma-less-mremap still sounds tricky but I doubt you can avoid that locking complexity by using the chardevice as long as the chardevice backed-memory still allows THP, migration and swap, if you want to do it atomic-zerocopy and I think zerocopy would be better especially if the network card is fast and all vcpus are faulting into unmapped pages simultaneously so triggering heavy amount of copying from all physical cpus.
Quoted 4 lines
I don't mean the current device driver doing a
copy_userwon't work or is bad idea, it's more self contained and maybe easier to merge upstream. I'm just presenting another option more VM integrated zerocopy with just 2 syscalls.
Zerocopy is really interesting here, esp. w/ RDMA. But while adding ptes is cheap, removing them is not. I wonder if we can make a write-only page? Of course it's unmapped for cpu access, but we can allow DMA write access from the NIC. Probably too wierd.
Quoted 6 lines
vmas must not be involved in the mremap for reliability, or too much memory could get pinned in vmas even if we temporary lift the
/proc/sys/vm/max_map_countfor the process. Plus sending another signal (not sigsegv or sigbus) should be more reliable in case the migration crashes for real.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 4 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
Quoted 8 lines
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
Some people want to investigate guest ram on host (qemu stopped or lively). For example, enhance crash utility and it will attach qemu process and debug guest kernel.
To debug the guest kernel you don't need to stop qemu itself. I agree
it's a problem for qemu debugging though.
Quoted 7 lines
- core dump
qemu process may core-dump.
As postmortem analysis, people want to investigate guest RAM. Again enhance crash utility and it will read the core file and analyze guest kernel.
When creating core, the qemu process is already dead.
Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
Signature · 1 line
error compiling committee.c: too many arguments to function
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) available
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transfer
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)
Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Regards
Benoit
Regards
Benoit
Quoted 39 lines · Avi Kivity
Quoted 4 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
Quoted 8 lines
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
Some people want to investigate guest ram on host (qemu stopped or lively). For example, enhance crash utility and it will attach qemu process and debug guest kernel.To debug the guest kernel you don't need to stop qemu itself. I agree it's a problem for qemu debugging though.
Quoted 7 lines
- core dump
qemu process may core-dump.
As postmortem analysis, people want to investigate guest RAM. Again enhance crash utility and it will read the core file and analyze guest kernel.
When creating core, the qemu process is already dead.Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
--
error compilingcommittee.c: too many arguments to function--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
" The production of too many useful things results in too many useless people"
Quoted 25 lines · Benoit Hudzia
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) available
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transfer
Quoted 8 lines
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Do you have any plan to send the patch series of your implementation?
Takuya
Very interesting. We can cooperate for better (postcopy) live migration. The code doesn't seem available yet, I'm eager for it.
Quoted 7 lines · Benoit Hudzia
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Quoted 5 lines
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
Do you mean infiniband subsystem?
Quoted 6 lines
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) available
Ah, I've been also planing this.
After pre-copy phase, is the dirty bitmap sent?
So far I've thought naively that pre-copy phase would be finished by the number of iterations. On the other hand your choice is timeout of pre-copy phase. Do you have rationale? or it was just natural for you?
Quoted 5 lines
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transfer
Where do you plan to implement? in qemu or in your kernel module? This algo could be shared.
thanks in advance.
Quoted 68 lines
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Regards
BenoitRegards
BenoitQuoted 39 lines · Avi Kivity
Quoted 4 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
Quoted 8 lines
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
?? Some people want to investigate guest ram on host (qemu stopped or lively). ?? For example, enhance crash utility and it will attach qemu process and ?? debug guest kernel.To debug the guest kernel you don't need to stop qemu itself. ?? I agree it's a problem for qemu debugging though.
Quoted 7 lines
- core dump
?? qemu process may core-dump.
?? As postmortem analysis, people want to investigate guest RAM. ?? Again enhance crash utility and it will read the core file and analyze ?? guest kernel.
?? When creating core, the qemu process is already dead.Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
--
error compilingcommittee.c: too many arguments to function--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at ??http://vger.kernel.org/majordomo-info.htmlSignature · 1 line
" The production of too many useful things results in too many useless people"
Signature · 1 line
yamahata
Quoted 25 lines · Avi Kivity
Quoted 17 lines · Andrea Arcangeli
Quoted 5 lines
Quoted 5 lines
So the problem is if we do it in
userland with the current functionality you'll run out of VMAs and slowdown performance too much.Quoted 8 lines
Quoted 2 lines
But all you need is the ability to map single pages in the address space.
Would this also let you set different pgprots for different pages in the same VMA? It would be useful for write barriers in garbage collectors (such as boehm-gc). These do not have _that_ many VMAs, because every GC cycles could merge all of them back to a single VMA with
PROT_READpermissions; however, they still put some strain on the VM subsystem.Changing permission sounds more tricky as more code may make assumptions on the vma before checking the pte.
Quoted 6 lines
Adding a magic unmapped pte entry sounds fairly safe because there's the migration pte already used by migrate which halts page faults and wait, that creates a precedent. So I guess we could reuse the same code that already exists for the migration entry and we'd need to fire a signal and returns to userland instead of waiting. The signal should be invoked before the page fault will trigger again.
Quoted 5 lines
Delivering signals is slow, and you can't use signalfd for it, because that can be routed to a different task. I would like an fd based protocol with an explicit ack so the other end can be implemented by the kernel, to use with RDMA. Kind of like how vhost-net talks to a guest via a kvm ioeventfd/irqfd.
As long as we tell qemu to run some per-vcpu handler (or io-thread handler in case of access through the I/O thread) before accessing the same memory address again, I don't see a problem in using a faster mechanism than signals. In theory we could even implement this functionality in kvm itself and just add two ioctl to the kvm fd, instead of a syscall in fact but it'd be mangling over VM things like page->index.
Quoted 13 lines
Quoted 4 lines
Of course if the
signal returns and does nothing it'll loop at 100% cpu load but that's ok. Maybe it's possible to tweak the permissions but it will need a lot more thoughts. Specifically for anon pages marking them readonlyQuoted 8 lines
sounds possible if they are supposed to behave like regular COWs (not segfaulting or anything), as you already can have a mixture of readonly and read-write ptes (not to tell readonly KSM pages), but for any other case it's non trivial. Last but not the least the API here would be like a vma-less-mremap, moving a page from one address to another without modifying the vmas, the permission tweak sounds more like an mprotect, so I'm unsure if it could do both or if it should be an optimization to consider independently.
Quoted 1 line
Doesn't this stuff require tlb flushes across all threads?
It does, to do it zerocopy and atomic we must move the pte.
Quoted 23 lines
Quoted 18 lines
In theory I suspect we could also teach mremap to do a not-vma-mangling mremap if we move pages that aren't shared and so we can adjust the
page->indexof the pages, instead of creating new vmas at the dst address with an adjustedvma->vm_pgoff, but I suspect a syscall that only works on top of fault-unmapped areas is simpler and safer. mremap semantics requires nuking the dst region before the move starts. If we would teach mremap how to handle the fault-unmapped areas we could just add one syscallprepare_fault_area(or whatever name you choose).The locking of doing a vma-less-mremap still sounds tricky but I doubt you can avoid that locking complexity by using the chardevice as long as the chardevice backed-memory still allows THP, migration and swap, if you want to do it atomic-zerocopy and I think zerocopy would be better especially if the network card is fast and all vcpus are faulting into unmapped pages simultaneously so triggering heavy amount of copying from all physical cpus.
Quoted 4 lines
I don't mean the current device driver doing a
copy_userwon't work or is bad idea, it's more self contained and maybe easier to merge upstream. I'm just presenting another option more VM integrated zerocopy with just 2 syscalls.
Quoted 4 lines
Zerocopy is really interesting here, esp. w/ RDMA. But while adding ptes is cheap, removing them is not. I wonder if we can make a write-only page? Of course it's unmapped for cpu access, but we can allow DMA write access from the NIC. Probably too wierd.
Keeping it mapped in two places gives problem with the non-linearity of the page->index. We've 1 page->index and two different vma->vm_pgoff, so it's just not a problem of readonly. We could even it let it read-write as long as it is nuked when we swap. Problem is we can't leave it there, we must update page->index, if we don't the rmap walk breaks and swap/migrate with it... we would allow any thread to see random memory through that window, even if read-only (post-swapout) and it wouldn't be secure in multiuser system.
Maybe we can find a way to have qemu call a "recv" directly on the guest physical address final destination and never expose the page received to userland during the receive. Without having to pass through a buffer mapped in userland would solve the tlb flushes. That however would prevent lzo compression or any other trick that we might do and it'd force zerocopy behavior all the way through the kernel recv syscall and after recv we would just return from the "post-copy handler" and return to guest mode (or return accessing the data in the io-thread case). Maybe splice or sendfile or some other trick allows that. Problem is we can't have the pte and sptes established until the full receive is complete or other vcpu threads will see partial receive. I suspect the post-migrate faults will be network I/O dominated anyway.
About doing a copy, that doesn't require the TLB flush, the problem is doing it atomic and not expose partial data to the vcpus and io-thread. I can imagine various ways to achieve that, but I don't see how that can be done "free", plus you pay the copy too.
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
Quoted 7 lines
Quoted 4 lines
- ptrace (and its variant)
Some people want to investigate guest ram on host (qemu stopped or lively). For example, enhance crash utility and it will attach qemu process and debug guest kernel.To debug the guest kernel you don't need to stop qemu itself. I agree
it's a problem for qemu debugging though.
But you need to debug postcopy migration too with gdb or not? I don't see a big benefit in trying to prevent gdb to see really what is going on in the qemu image.
Quoted 7 lines
Quoted 6 lines
- core dump
qemu process may core-dump.
As postmortem analysis, people want to investigate guest RAM. Again enhance crash utility and it will read the core file and analyze guest kernel.
When creating core, the qemu process is already dead.
Quoted 5 lines
Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
In the receiving node if the memory is not there yet (and it isn't), not sure how you plan to get a clean core dump (like if live migration wasn't running) by preventing the kernel from dumping zeroes if qemu crashes during post copy migration. Surely it won't be the kernel crash handler completing the post migration, it won't even know where to write the data in memory.
One more question.
Does your architecture/implementation (in theory) allow KVM memory features like swap, KSM, THP?
Quoted 119 lines · Isaku Yamahata
Very interesting. We can cooperate for better (postcopy) live migration. The code doesn't seem available yet, I'm eager for it.
Quoted 7 lines · Benoit Hudzia
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Quoted 5 lines
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
Do you mean infiniband subsystem?
Quoted 6 lines
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) availableAh, I've been also planing this.
After pre-copy phase, is the dirty bitmap sent?So far I've thought naively that pre-copy phase would be finished by the number of iterations. On the other hand your choice is timeout of pre-copy phase. Do you have rationale? or it was just natural for you?
Quoted 5 lines
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transferWhere do you plan to implement? in qemu or in your kernel module? This algo could be shared.
thanks in advance.
Quoted 68 lines
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Regards
BenoitRegards
BenoitQuoted 39 lines · Avi Kivity
Quoted 4 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
Quoted 8 lines
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
?? Some people want to investigate guest ram on host (qemu stopped or lively). ?? For example, enhance crash utility and it will attach qemu process and ?? debug guest kernel.To debug the guest kernel you don't need to stop qemu itself. ?? I agree it's a problem for qemu debugging though.
Quoted 7 lines
- core dump
?? qemu process may core-dump.
?? As postmortem analysis, people want to investigate guest RAM. ?? Again enhance crash utility and it will read the core file and analyze ?? guest kernel.
?? When creating core, the qemu process is already dead.Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
--
error compilingcommittee.c: too many arguments to function--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at ??http://vger.kernel.org/majordomo-info.htmlSignature · 1 line
" The production of too many useful things results in too many useless people"Signature · 1 line
yamahata
Signature · 1 line
yamahata
Yes we plan to release patch as soon as we cleaned up the code and we get the green light from our company ( and sadly it can take month on that point..)
Quoted 40 lines · Takuya Yoshikawa
Quoted 26 lines · Benoit Hudzia
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) available
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transferQuoted 8 lines
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Do you have any plan to send the patch series of your implementation?
Takuya
Signature · 1 line
" The production of too many useful things results in too many useless people"
Quoted 12 lines · Isaku Yamahata
Very interesting. We can cooperate for better (postcopy) live migration. The code doesn't seem available yet, I'm eager for it.
Quoted 7 lines · Benoit Hudzia
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Quoted 7 lines
Quoted 5 lines
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
Do you mean infiniband subsystem?
Yes, basically any software or hardware implementation that support the standard RDMA / OFED vverbs stack in kernel.
Quoted 11 lines
Quoted 8 lines
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) availableAh, I've been also planing this.
After pre-copy phase, is the dirty bitmap sent?
We sent over the dirty bitmap yes. In order to identify what is left to be transferred . And combined with the priority algo we will then prioritise the page for the background transfer.
Quoted 4 lines
So far I've thought naively that pre-copy phase would be finished by the number of iterations. On the other hand your choice is timeout of pre-copy phase. Do you have rationale? or it was just natural for you?
The main rational behind that is any normal sys admin tend to to be human and live migration iteration cycle has no meaning for him. As a result we preferred to provide a time constraint rather than an iteration constraint. Also it is hard to estimate how much time bandwidth would be use per iteration cycle which led to poor determinism.
Quoted 10 lines
Quoted 7 lines
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transferWhere do you plan to implement? in qemu or in your kernel module? This algo could be shared.
Yes we plan to actually release the algo first before the RDMA post copy. The algo can be use for standard optimisation of the normal pre-copy process (as demosntrated in my talk at KVM-forum). And if the priority is reverse for the post copy page pull. My colleague Aidan shribman is done with the implentation and we are now in testing phase in order to quantify the improvement.
Quoted 74 lines
thanks in advance.
Quoted 65 lines
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Regards
BenoitRegards
BenoitQuoted 32 lines · Avi Kivity
Quoted 4 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
Quoted 8 lines
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
?? Some people want to investigate guest ram on host (qemu stopped or lively). ?? For example, enhance crash utility and it will attach qemu process and ?? debug guest kernel.To debug the guest kernel you don't need to stop qemu itself. ?? I agree it's a problem for qemu debugging though.
Quoted 7 lines
- core dump
?? qemu process may core-dump.
?? As postmortem analysis, people want to investigate guest RAM. ?? Again enhance crash utility and it will read the core file and analyze ?? guest kernel.
?? When creating core, the qemu process is already dead.Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
Quoted 7 lines
--
error compilingcommittee.c: too many arguments to function--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at ??http://vger.kernel.org/majordomo-info.htmlQuoted 3 lines
--
" The production of too many useful things results in too many useless people"--
yamahata
Signature · 1 line
" The production of too many useful things results in too many useless people"
Quoted 3 lines · Isaku Yamahata
One more question.
Does your architecture/implementation (in theory) allow KVM memory features like swap, KSM, THP?
* Swap: Yes we support swap to disk ( the page is pulled from swap before being send over), swap process do its job on the other side.
* KSM : same , we support KSM, the KSMed page is broken down and split and they are send individually ( yes sub optimal but make the protocol less messy) and we let the KSM daemon do its job on the other side.
* THP : more sticky here. Due to time constraint we decided that we will be partially supporting it. What does it means: if we encounter THP we break them down in standard page granularity as it is our current memory unit we are manipulating. As a result you can have THP on the source but you won't have THP on the other side.
_ Note , we didn't explore fully the ramification of THP
with RDMA, i don't know if THP play well with the MMU of HW RDMA NIC, One thing i would like to explore is if it is possible to break down the THP in standard page and then reassemble them on the other side ( do any one fo you know if it is possible to aggregate page to for a THP in kernel ? )
* cgroup : should be transparently working, but we need to do more testing to confirm that .
Quoted 125 lines · Isaku Yamahata
Quoted 112 lines
Very interesting. We can cooperate for better (postcopy) live migration. The code doesn't seem available yet, I'm eager for it.
Quoted 7 lines · Benoit Hudzia
Hi,
Sorry to jump to hijack the thread like that , however i would like to just to inform you that we recently achieve a milestone out of the research project I'm leading. We enhanced KVM in order to deliver post copy live migration using RDMA at kernel level.
Quoted 5 lines
Few point on the architecture of the system :
* RDMA communication engine in kernel ( you can use soft iwarp or soft ROCE if you don't have hardware acceleration, however we also support standard RDMA enabled NIC) .
Do you mean infiniband subsystem?
Quoted 6 lines
* Naturally Page are transferred with Zerop copy protocol
* Leverage the async page fault system.
* Pre paging / faulting
* No context switch as everything is handled within kernel and using the page fault system.
* Hybrid migration ( pre + post copy) availableAh, I've been also planing this.
After pre-copy phase, is the dirty bitmap sent?So far I've thought naively that pre-copy phase would be finished by the number of iterations. On the other hand your choice is timeout of pre-copy phase. Do you have rationale? or it was just natural for you?
Quoted 5 lines
* Rely on an independent Kernel Module
* No modification to the KVM kernel Module
* Minimal Modification to the Qemu-Kvm code
* We plan to add the page prioritization algo in order to optimise the pre paging algo and background transferWhere do you plan to implement? in qemu or in your kernel module? This algo could be shared.
thanks in advance.
Quoted 65 lines
You can learn a little bit more and see a demo here:
http://tinyurl.com/8xa2bgl
I hope to be able to provide more detail on the design soon. As well as more concrete demo of the system ( live migration of VM running large enterprise apps such as ERP or In memory DB)Note: this is just a step stone as the post copy live migration mainly enable us to validate the architecture design and code.
Regards
BenoitRegards
BenoitQuoted 39 lines · Avi Kivity
Quoted 4 lines · Isaku Yamahata
Yes, it's quite doable in user space(qemu) with a kernel-enhancement. And it would be easy to convert a separated daemon process into a thread in qemu.
Quoted 8 lines
I think it should be done out side of qemu process for some reasons. (I just repeat same discussion at the KVM-forum because no one remembers it)
- ptrace (and its variant)
?? Some people want to investigate guest ram on host (qemu stopped or lively). ?? For example, enhance crash utility and it will attach qemu process and ?? debug guest kernel.To debug the guest kernel you don't need to stop qemu itself. ?? I agree it's a problem for qemu debugging though.
Quoted 7 lines
- core dump
?? qemu process may core-dump.
?? As postmortem analysis, people want to investigate guest RAM. ?? Again enhance crash utility and it will read the core file and analyze ?? guest kernel.
?? When creating core, the qemu process is already dead.Yes, strong point.
Quoted 1 line
It precludes the above possibilities to handle fault in qemu process.
I agree.
--
error compilingcommittee.c: too many arguments to function--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at ??http://vger.kernel.org/majordomo-info.htmlQuoted 7 lines
Quoted 3 lines
--
" The production of too many useful things results in too many useless people"--
yamahata--
yamahata
Signature · 1 line
" The production of too many useful things results in too many useless people"