From: Antonios Motakis <a.motakis@virtualopensystems.com>
To: qemu-devel@nongnu.org, snabb-devel@googlegroups.com
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
mst@redhat.com, "Juan Quintela" <quintela@redhat.com>,
"Michael Tokarev" <mjt@tls.msk.ru>,
"Alexander Graf" <agraf@suse.de>,
n.nikolaev@virtualopensystems.com,
"Markus Armbruster" <armbru@redhat.com>,
"Anthony Liguori" <aliguori@amazon.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
lukego@gmail.com,
"Antonios Motakis" <a.motakis@virtualopensystems.com>,
tech@virtualopensystems.com, "Andreas Färber" <afaerber@suse.de>,
"Richard Henderson" <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH v8 01/17] Convert -mem-path to QemuOpts and add prealloc and share properties
Date: Thu, 13 Feb 2014 13:03:12 +0100 [thread overview]
Message-ID: <1392293009-13812-2-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1392293009-13812-1-git-send-email-a.motakis@virtualopensystems.com>
Extend -mem-path with additional properties:
- prealloc=on|off - default off, same as -mem-prealloc
- share=on|off - default off, memory is mmapped with MAP_SHARED flag
Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
---
exec.c | 30 ++++++++++++++++++++++++++++--
include/exec/cpu-all.h | 3 ---
qemu-options.hx | 9 +++++++--
vl.c | 37 ++++++++++++++++++++++++++++++++-----
4 files changed, 67 insertions(+), 12 deletions(-)
diff --git a/exec.c b/exec.c
index b69fd29..87d3101 100644
--- a/exec.c
+++ b/exec.c
@@ -1027,7 +1027,10 @@ static void *file_ram_alloc(RAMBlock *block,
char *c;
void *area;
int fd;
+ int flags;
unsigned long hpagesize;
+ QemuOpts *opts;
+ unsigned int mem_prealloc = 0, mem_share = 0;
hpagesize = gethugepagesize(path);
if (!hpagesize) {
@@ -1043,6 +1046,13 @@ static void *file_ram_alloc(RAMBlock *block,
return NULL;
}
+ /* Fill config options */
+ opts = qemu_opts_find(qemu_find_opts("mem-path"), NULL);
+ if (opts) {
+ mem_prealloc = qemu_opt_get_bool(opts, "prealloc", 0);
+ mem_share = qemu_opt_get_bool(opts, "share", 0);
+ }
+
/* Make name safe to use with mkstemp by replacing '/' with '_'. */
sanitized_name = g_strdup(block->mr->name);
for (c = sanitized_name; *c != '\0'; c++) {
@@ -1063,7 +1073,7 @@ static void *file_ram_alloc(RAMBlock *block,
unlink(filename);
g_free(filename);
- memory = (memory+hpagesize-1) & ~(hpagesize-1);
+ memory = (memory + hpagesize - 1) & ~(hpagesize - 1);
/*
* ftruncate is not supported by hugetlbfs in older
@@ -1074,7 +1084,8 @@ static void *file_ram_alloc(RAMBlock *block,
if (ftruncate(fd, memory))
perror("ftruncate");
- area = mmap(0, memory, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ flags = mem_share ? MAP_SHARED : MAP_PRIVATE;
+ area = mmap(0, memory, PROT_READ | PROT_WRITE, flags, fd, 0);
if (area == MAP_FAILED) {
perror("file_ram_alloc: can't mmap RAM pages");
close(fd);
@@ -1244,6 +1255,8 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
MemoryRegion *mr)
{
RAMBlock *block, *new_block;
+ QemuOpts *opts;
+ const char *mem_path = 0;
ram_addr_t old_ram_size, new_ram_size;
old_ram_size = last_ram_offset() >> TARGET_PAGE_BITS;
@@ -1252,6 +1265,11 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
new_block = g_malloc0(sizeof(*new_block));
new_block->fd = -1;
+ opts = qemu_opts_find(qemu_find_opts("mem-path"), NULL);
+ if (opts) {
+ mem_path = qemu_opt_get(opts, "path");
+ }
+
/* This assumes the iothread lock is taken here too. */
qemu_mutex_lock_ramlist();
new_block->mr = mr;
@@ -1390,6 +1408,14 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
ram_addr_t offset;
int flags;
void *area, *vaddr;
+ QemuOpts *opts;
+ unsigned int mem_prealloc = 0;
+
+ /* Fill config options */
+ opts = qemu_opts_find(qemu_find_opts("mem-path"), NULL);
+ if (opts) {
+ mem_prealloc = qemu_opt_get_bool(opts, "prealloc", 0);
+ }
QTAILQ_FOREACH(block, &ram_list.blocks, next) {
offset = addr - block->offset;
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 4cb4b4a..b46055d 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -468,9 +468,6 @@ typedef struct RAMList {
} RAMList;
extern RAMList ram_list;
-extern const char *mem_path;
-extern int mem_prealloc;
-
/* Flags stored in the low bits of the TLB virtual address. These are
defined so that fast path ram access is all zeros. */
/* Zero if TLB entry is valid. */
diff --git a/qemu-options.hx b/qemu-options.hx
index 56e5fdf..60ecc95 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -221,9 +221,14 @@ gigabytes respectively.
ETEXI
DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
- "-mem-path FILE provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
+ "-mem-path [path=]path[,prealloc=on|off][,share=on|off]\n"
+ " provide backing storage for guest RAM\n"
+ " path= a directory path for the backing store\n"
+ " prealloc= preallocate guest memory [default disabled]\n"
+ " share= enable mmap share flag [default disabled]\n",
+ QEMU_ARCH_ALL)
STEXI
-@item -mem-path @var{path}
+@item -mem-path [path=]@var{path}[,prealloc=on|off][,share=on|off]
@findex -mem-path
Allocate guest RAM from a temporarily created file in @var{path}.
ETEXI
diff --git a/vl.c b/vl.c
index 383be1b..9bd9272 100644
--- a/vl.c
+++ b/vl.c
@@ -188,8 +188,6 @@ DisplayType display_type = DT_DEFAULT;
static int display_remote;
const char* keyboard_layout = NULL;
ram_addr_t ram_size;
-const char *mem_path = NULL;
-int mem_prealloc = 0; /* force preallocation of physical target memory */
int nb_nics;
NICInfo nd_table[MAX_NICS];
int autostart;
@@ -532,6 +530,27 @@ static QemuOptsList qemu_msg_opts = {
},
};
+static QemuOptsList qemu_mem_path_opts = {
+ .name = "mem-path",
+ .implied_opt_name = "path",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_path_opts.head),
+ .desc = {
+ {
+ .name = "path",
+ .type = QEMU_OPT_STRING,
+ },
+ {
+ .name = "prealloc",
+ .type = QEMU_OPT_BOOL,
+ },
+ {
+ .name = "share",
+ .type = QEMU_OPT_BOOL,
+ },
+ { /* end of list */ }
+ },
+};
+
/**
* Get machine options
*
@@ -2915,6 +2934,7 @@ int main(int argc, char **argv, char **envp)
qemu_add_opts(&qemu_tpmdev_opts);
qemu_add_opts(&qemu_realtime_opts);
qemu_add_opts(&qemu_msg_opts);
+ qemu_add_opts(&qemu_mem_path_opts);
runstate_init();
@@ -3232,11 +3252,18 @@ int main(int argc, char **argv, char **envp)
break;
#endif
case QEMU_OPTION_mempath:
- mem_path = optarg;
+ if (!qemu_opts_parse(qemu_find_opts("mem-path"), optarg, 1)) {
+ exit(1);
+ }
break;
- case QEMU_OPTION_mem_prealloc:
- mem_prealloc = 1;
+ case QEMU_OPTION_mem_prealloc: {
+ QemuOpts *mem_opts = qemu_opts_find(qemu_find_opts("mem-path"),
+ NULL);
+ if (mem_opts) {
+ qemu_opt_set(mem_opts, "prealloc", "on");
+ }
break;
+ }
case QEMU_OPTION_d:
log_mask = optarg;
break;
--
1.8.3.2
next prev parent reply other threads:[~2014-02-13 12:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-13 12:03 [Qemu-devel] [PATCH v8 00/17] Vhost and vhost-net support for userspace based backends Antonios Motakis
2014-02-13 12:03 ` Antonios Motakis [this message]
2014-02-15 18:10 ` [Qemu-devel] [PATCH v8 01/17] Convert -mem-path to QemuOpts and add prealloc and share properties Michael Tokarev
2014-02-16 23:42 ` Paolo Bonzini
2014-02-17 7:56 ` Michael S. Tsirkin
2014-02-17 13:04 ` Antonios Motakis
2014-02-17 17:27 ` Paolo Bonzini
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 02/17] Add chardev API qemu_chr_fe_read_all Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 03/17] Add chardev API qemu_chr_fe_set_msgfds Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 04/17] Add chardev API qemu_chr_fe_get_msgfds Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 05/17] Add G_IO_HUP handler for socket chardev Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 06/17] vhost_net should call the poll callback only when it is set Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 07/17] Refactor virtio-net to use generic get_vhost_net Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 08/17] vhost_net_init will use VhostNetOptions to get all its arguments Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 09/17] Add vhost_ops to vhost_dev struct and replace all relevant ioctls Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 10/17] Add mandatory_features to vhost_dev Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 11/17] Add vhost-backend and VhostBackendType Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 12/17] Add vhost-user as a vhost backend Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 13/17] Add new vhost-user netdev backend Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 14/17] Add the vhost-user netdev backend to the command line Antonios Motakis
2014-02-17 17:17 ` Eric Blake
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 15/17] Add vhost-user protocol documentation Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 16/17] libqemustub: add stubs to be able to use qemu-char.c Antonios Motakis
2014-02-13 12:03 ` [Qemu-devel] [PATCH v8 17/17] Add qtest for vhost-user Antonios Motakis
2014-02-26 16:44 ` [Qemu-devel] [PATCH v8 00/17] Vhost and vhost-net support for userspace based backends Michael S. Tsirkin
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=1392293009-13812-2-git-send-email-a.motakis@virtualopensystems.com \
--to=a.motakis@virtualopensystems.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=lukego@gmail.com \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=n.nikolaev@virtualopensystems.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@twiddle.net \
--cc=snabb-devel@googlegroups.com \
--cc=stefanha@redhat.com \
--cc=tech@virtualopensystems.com \
/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;
as well as URLs for NNTP newsgroup(s).