From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Igor Mammedov <imammedo@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 4/5] memory: Add 'persistent' parameter to memory_region_init_ram_from_file()
Date: Thu, 22 Jun 2017 13:26:49 +0100 [thread overview]
Message-ID: <20170622122649.GD2624@work-vm> (raw)
In-Reply-To: <20170614203000.19984-5-ehabkost@redhat.com>
* Eduardo Habkost (ehabkost@redhat.com) wrote:
> Make it possible to set the RAM_NONPERSISTENT flag on the RAMBlock when
> mapping a file.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
A little confusing having a persistent flag passed in but setting a
NONPERSISTENT flag.
One thing to watch out for is the other effect, for example I think
doing an MADV_REMOVE will zero the file; if that's a ROM file that
would probably be bad; but your description of persistent=false
might make sense for a ROM file since it wont be changed.
Dave
> ---
> include/exec/memory.h | 4 ++++
> include/exec/ram_addr.h | 4 ++--
> backends/hostmem-file.c | 2 +-
> exec.c | 7 +++++--
> memory.c | 4 +++-
> numa.c | 2 +-
> 6 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 80e605a96a..f47c534179 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -446,6 +446,9 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
> * must be unique within any device
> * @size: size of the region.
> * @share: %true if memory must be mmaped with the MAP_SHARED flag
> + * @persistent: %false if RAM contents can be discarded and don't
> + * need to be flushed to disk when the memory region
> + * is freed.
> * @path: the path in which to allocate the RAM.
> * @errp: pointer to Error*, to store an error if it happens.
> */
> @@ -454,6 +457,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
> const char *name,
> uint64_t size,
> bool share,
> + bool persistent,
> const char *path,
> Error **errp);
> #endif
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 140efa840c..67dc099355 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -63,8 +63,8 @@ static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
> long qemu_getrampagesize(void);
> unsigned long last_ram_page(void);
> RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
> - bool share, const char *mem_path,
> - Error **errp);
> + bool share, bool persistent,
> + const char *mem_path, Error **errp);
> RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
> MemoryRegion *mr, Error **errp);
> RAMBlock *qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp);
> diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> index fc4ef46d11..d078775b4b 100644
> --- a/backends/hostmem-file.c
> +++ b/backends/hostmem-file.c
> @@ -57,7 +57,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,
> + backend->size, fb->share, true,
> fb->mem_path, errp);
> g_free(path);
> }
> diff --git a/exec.c b/exec.c
> index a6e9ed4ece..77734198d0 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1937,8 +1937,8 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
>
> #ifdef __linux__
> RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
> - bool share, const char *mem_path,
> - Error **errp)
> + bool share, bool persistent,
> + const char *mem_path, Error **errp)
> {
> RAMBlock *new_block;
> Error *local_err = NULL;
> @@ -1965,6 +1965,9 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
> new_block->used_length = size;
> new_block->max_length = size;
> new_block->flags = share ? RAM_SHARED : 0;
> + if (!persistent) {
> + new_block->flags |= RAM_NONPERSISTENT;
> + }
> new_block->host = file_ram_alloc(new_block, size,
> mem_path, errp);
> if (!new_block->host) {
> diff --git a/memory.c b/memory.c
> index 0ddc4cc28d..3c0c0ff141 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1387,6 +1387,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
> const char *name,
> uint64_t size,
> bool share,
> + bool persistent,
> const char *path,
> Error **errp)
> {
> @@ -1394,7 +1395,8 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
> mr->ram = true;
> mr->terminates = true;
> mr->destructor = memory_region_destructor_ram;
> - mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp);
> + mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, persistent,
> + path, errp);
> mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
> }
> #endif
> diff --git a/numa.c b/numa.c
> index 65701cb6c8..825d5933ca 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -531,7 +531,7 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
> if (mem_path) {
> #ifdef __linux__
> Error *err = NULL;
> - memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
> + memory_region_init_ram_from_file(mr, owner, name, ram_size, false, true,
> mem_path, &err);
> if (err) {
> error_report_err(err);
> --
> 2.11.0.259.g40922b1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2017-06-22 12:27 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 [this message]
2017-06-22 12:41 ` Eduardo Habkost
2017-06-14 20:30 ` [Qemu-devel] [PATCH 5/5] hostmem-file: Add "persistent" option Eduardo Habkost
2017-06-14 21:50 ` [Qemu-devel] [PATCH 0/5] " 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=20170622122649.GD2624@work-vm \
--to=dgilbert@redhat.com \
--cc=ehabkost@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).