public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Wenchao Xia <wenchaolinuxkvm@gmail.com>
To: kvm-devel <kvm@vger.kernel.org>
Subject: [RFC] provide an API to userspace doing memory snapshot
Date: Mon, 15 Apr 2013 21:03:36 +0800	[thread overview]
Message-ID: <516BFAA8.2030608@gmail.com> (raw)

Hi,
  I'd like to add/export an function which allow userspace program
to take snapshot for a region of memory. Since it is not implemented yet
I will describe it as C APIs, it is quite simple now and if it is worthy
I'll improve the interface later:

Simple prototype:
C API in userspace:
/*
 *   This function will mark a section of memory as COW, and return
 * a new virtual address of it. User space program can dump out the
 * content as a snapshot while other thread continue modify the content
 * in the region.
 *   @addr: the virtual address to be snapshotted.
 *   @length: the length of it.
 *   This function returns a new virtual address which can be used as
 * snapshot. Return NULL on fail.
 */
void *memory_snapshot_create(void *addr, uint64_t length);

/*
 *   This function will free the memory snapshot.
 *   @addr: the virtual snapshot addr to be freed, it should be the
 * returned one in memory_snapshot_create().
 */
void memory_snapshot_delete(void *addr);

In kernel space:
  The pages in those virtual address will be marked as COW. Take a
page with physical addr P0 as example, it will have two virtual addr:
old A0 and new A1. When modified, kernel should create a new page P1
with same contents, and mapping A1 to P1. When NUMA is used, P1 can
be a slower page.
  It is quite like fork(), but only COW part of pages. Maybe add it
as an ioctl() in kvm.ko, and change the input/output as a structure
describe guest memory state.

Why bring it to kernel space:
  Compared with fork():
  1 take less RAM, less halt time by avoid marking unnecessary pages
COW.
  2 take less RAM if API can return a bitmap let qemu consume dirty
page first.
  3 much nicer userspace program model, no need to pipe or memcpy(),
brings better performance.
  4 optimization space in kernel space, since snapshoted pages
can be set into slower memory in NUMA when change comes.


             reply	other threads:[~2013-04-15 13:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-15 13:03 Wenchao Xia [this message]
2013-04-16  5:51 ` [RFC] provide an API to userspace doing memory snapshot Stefan Hajnoczi
2013-04-16  7:54   ` Wenchao Xia
2013-04-17 13:57     ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=516BFAA8.2030608@gmail.com \
    --to=wenchaolinuxkvm@gmail.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox