qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] hostmem-file: Add "persistent" option
Date: Wed, 14 Jun 2017 17:30:00 -0300	[thread overview]
Message-ID: <20170614203000.19984-6-ehabkost@redhat.com> (raw)
In-Reply-To: <20170614203000.19984-1-ehabkost@redhat.com>

The new option can be used to indicate that the memory block contents
can be safely discarded and don't need to be flushed to the filesystem
when the memory backend is destroyed (including when QEMU exits).

Internally, it will trigger a madvise(MADV_REMOVE) or
fallocate(FALLOC_FL_PUNCH_HOLE) call when the memory backend is
destroyed.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 backends/hostmem-file.c | 35 ++++++++++++++++++++++++++++++++++-
 qemu-options.hx         |  9 ++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index d078775b4b..e6cb232349 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -32,6 +32,7 @@ struct HostMemoryBackendFile {
     HostMemoryBackend parent_obj;
 
     bool share;
+    bool persistent;
     char *mem_path;
 };
 
@@ -57,7 +58,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         path = object_get_canonical_path(OBJECT(backend));
         memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
                                  path,
-                                 backend->size, fb->share, true,
+                                 backend->size, fb->share, fb->persistent,
                                  fb->mem_path, errp);
         g_free(path);
     }
@@ -103,6 +104,26 @@ static void file_memory_backend_set_share(Object *o, bool value, Error **errp)
     fb->share = value;
 }
 
+static bool file_memory_backend_get_persistent(Object *o, Error **errp)
+{
+    HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+    return fb->persistent;
+}
+
+static void file_memory_backend_set_persistent(Object *o, bool value,
+                                               Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(o);
+    HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+    if (host_memory_backend_mr_inited(backend)) {
+        error_setg(errp, "cannot change property value");
+        return;
+    }
+    fb->persistent = value;
+}
+
 static void
 file_backend_class_init(ObjectClass *oc, void *data)
 {
@@ -110,14 +131,25 @@ file_backend_class_init(ObjectClass *oc, void *data)
 
     bc->alloc = file_backend_memory_alloc;
 
+
     object_class_property_add_bool(oc, "share",
         file_memory_backend_get_share, file_memory_backend_set_share,
         &error_abort);
+    object_class_property_add_bool(oc, "persistent",
+        file_memory_backend_get_persistent, file_memory_backend_set_persistent,
+        &error_abort);
     object_class_property_add_str(oc, "mem-path",
         get_mem_path, set_mem_path,
         &error_abort);
 }
 
+static void file_backend_instance_init(Object *o)
+{
+    HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
+
+    fb->persistent = true;
+}
+
 static void file_backend_instance_finalize(Object *o)
 {
     HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o);
@@ -129,6 +161,7 @@ static const TypeInfo file_backend_info = {
     .name = TYPE_MEMORY_BACKEND_FILE,
     .parent = TYPE_MEMORY_BACKEND,
     .class_init = file_backend_class_init,
+    .instance_init = file_backend_instance_init,
     .instance_finalize = file_backend_instance_finalize,
     .instance_size = sizeof(HostMemoryBackendFile),
 };
diff --git a/qemu-options.hx b/qemu-options.hx
index 30c4f9850f..7fb4feec9b 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3961,7 +3961,7 @@ property must be set.  These objects are placed in the
 
 @table @option
 
-@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off}
+@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off},persistent=@var{on|off}
 
 Creates a memory file backend object, which can be used to back
 the guest RAM with huge pages. The @option{id} parameter is a
@@ -3973,6 +3973,13 @@ the path to either a shared memory or huge page filesystem mount.
 The @option{share} boolean option determines whether the memory
 region is marked as private to QEMU, or shared. The latter allows
 a co-operating external process to access the QEMU memory region.
+Setting the @option{persistent} boolean option to @var{off}
+indicates that memory contents can be safely discarded and not
+flushed to disk when the backend object is destroyed or QEMU
+exits.  @option{persistent} is @var{on} by default.  It is valid
+to set @option{persistent} to @var{off} if @option{share} is
+@var{on}. It is redundant to set @option{persistent} to @var{off}
+if @option{share} is @var{off}.
 
 @item -object rng-random,id=@var{id},filename=@var{/dev/random}
 
-- 
2.11.0.259.g40922b1

  parent reply	other threads:[~2017-06-14 20:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14 20:29 [Qemu-devel] [PATCH 0/5] hostmem-file: Add "persistent" option Eduardo Habkost
2017-06-14 20:29 ` [Qemu-devel] [PATCH 1/5] vl: Clean up user-creatable objects when exiting Eduardo Habkost
2017-06-14 20:29 ` [Qemu-devel] [PATCH 2/5] memory: Allow RAM up to block->max_length to be discarded Eduardo Habkost
2017-06-22 11:47   ` Dr. David Alan Gilbert
2017-06-14 20:29 ` [Qemu-devel] [PATCH 3/5] memory: Add RAM_NONPERSISTENT flag Eduardo Habkost
2017-06-22 12:14   ` Dr. David Alan Gilbert
2017-06-22 17:27     ` Eduardo Habkost
2017-06-22 18:56       ` Dr. David Alan Gilbert
2017-06-14 20:29 ` [Qemu-devel] [PATCH 4/5] memory: Add 'persistent' parameter to memory_region_init_ram_from_file() Eduardo Habkost
2017-06-22 12:26   ` Dr. David Alan Gilbert
2017-06-22 12:41     ` Eduardo Habkost
2017-06-14 20:30 ` Eduardo Habkost [this message]
2017-06-14 21:50 ` [Qemu-devel] [PATCH 0/5] hostmem-file: Add "persistent" option no-reply
2017-07-06 18:47 ` Eduardo Habkost
2017-08-11 16:33 ` Eduardo Habkost
2017-08-11 16:44   ` Daniel P. Berrange
2017-08-11 18:15     ` Eduardo Habkost
2017-08-14  9:39       ` Daniel P. Berrange
2017-08-14 11:40         ` Eduardo Habkost
2017-08-14 18:33           ` Zack Cornelius

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=20170614203000.19984-6-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).