All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: junyan.he@gmx.com
Cc: qemu-devel@nongnu.org, Haozhong Zhang <haozhong.zhang@intel.com>,
	xiaoguangrong.eric@gmail.com, crosthwaite.peter@gmail.com,
	mst@redhat.com, dgilbert@redhat.com, ehabkost@redhat.com,
	quintela@redhat.com, Junyan He <junyan.he@intel.com>,
	stefanha@redhat.com, pbonzini@redhat.com, rth@twiddle.net
Subject: Re: [Qemu-devel] [PATCH V6 2/7] memory, exec: switch file ram allocation functions to 'flags' parameters
Date: Mon, 11 Jun 2018 17:53:33 +0200	[thread overview]
Message-ID: <20180611175333.65745243@redhat.com> (raw)
In-Reply-To: <1527840629-18648-3-git-send-email-junyan.he@gmx.com>

On Fri,  1 Jun 2018 16:10:24 +0800
junyan.he@gmx.com wrote:

> From: Junyan He <junyan.he@intel.com>
> 
> As more flag parameters besides the existing 'share' are going to be
> added to following functions
>   memory_region_init_ram_from_file
>   qemu_ram_alloc_from_fd
>   qemu_ram_alloc_from_file
> let's switch them to use the 'flags' parameters so as to ease future
> flag additions.
> 
> The existing 'share' flag is converted to the RAM_SHARED bit in ram_flags,
> and other flag bits are ignored by above functions right now.
> 
> Signed-off-by: Junyan He <junyan.he@intel.com>
> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> ---
>  backends/hostmem-file.c |  3 ++-
>  exec.c                  | 10 +++++-----
>  include/exec/memory.h   |  8 ++++++--
>  include/exec/ram_addr.h | 25 +++++++++++++++++++++++--
>  memory.c                |  8 +++++---
>  numa.c                  |  2 +-
>  6 files changed, 42 insertions(+), 14 deletions(-)
> 
> diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> index 134b08d..34c68bb 100644
> --- a/backends/hostmem-file.c
> +++ b/backends/hostmem-file.c
> @@ -58,7 +58,8 @@ 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->align, backend->share,
> +                                 backend->size, fb->align,
> +                                 backend->share ? RAM_SHARED : 0,
>                                   fb->mem_path, errp);
>          g_free(path);
>      }
> diff --git a/exec.c b/exec.c
> index 302c04b..f2082fa 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2054,7 +2054,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
>  
>  #ifdef __linux__
>  RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
> -                                 bool share, int fd,
> +                                 uint64_t ram_flags, int fd,
>                                   Error **errp)
>  {
>      RAMBlock *new_block;
> @@ -2096,14 +2096,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
>      new_block->mr = mr;
>      new_block->used_length = size;
>      new_block->max_length = size;
> -    new_block->flags = share ? RAM_SHARED : 0;
> +    new_block->flags = ram_flags;
>      new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp);
>      if (!new_block->host) {
>          g_free(new_block);
>          return NULL;
>      }
>  
> -    ram_block_add(new_block, &local_err, share);
> +    ram_block_add(new_block, &local_err, ram_flags & RAM_SHARED);
>      if (local_err) {
>          g_free(new_block);
>          error_propagate(errp, local_err);
> @@ -2115,7 +2115,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
>  
>  
>  RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
> -                                   bool share, const char *mem_path,
> +                                   uint64_t ram_flags, const char *mem_path,
>                                     Error **errp)
>  {
>      int fd;
> @@ -2127,7 +2127,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
>          return NULL;
>      }
>  
> -    block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp);
> +    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, errp);
>      if (!block) {
>          if (created) {
>              unlink(mem_path);
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 3da315e..3b68a43 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -596,6 +596,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
>                                                         void *host),
>                                         Error **errp);
>  #ifdef __linux__
> +
>  /**
>   * memory_region_init_ram_from_file:  Initialize RAM memory region with a
>   *                                    mmap-ed backend.
> @@ -607,7 +608,10 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr,
>   * @size: size of the region.
>   * @align: alignment of the region base address; if 0, the default alignment
>   *         (getpagesize()) will be used.
> - * @share: %true if memory must be mmaped with the MAP_SHARED flag
> + * @ram_flags: specify properties of this memory region, which can be one or
> + *             bit-or of following values:
I'd spell it out as:
 @ram_flags: memory region features:
         

> + *             - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag
> + *             Other bits are ignored.
>   * @path: the path in which to allocate the RAM.
>   * @errp: pointer to Error*, to store an error if it happens.
>   *
> @@ -619,7 +623,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
>                                        const char *name,
>                                        uint64_t size,
>                                        uint64_t align,
> -                                      bool share,
> +                                      uint64_t ram_flags,
>                                        const char *path,
>                                        Error **errp);
>  
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index cf2446a..b478455 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -72,12 +72,33 @@ static inline unsigned long int ramblock_recv_bitmap_offset(void *host_addr,
>  
>  long qemu_getrampagesize(void);
>  unsigned long last_ram_page(void);
> +
> +/**
> + * qemu_ram_alloc_from_file,
> + * qemu_ram_alloc_from_fd:  Allocate a ram block from the specified back
> + *                          file or device
s/back file/baking file/
here and in all other places it's added

and maybe s/device/file descriptor/

> + *
> + * Parameters:
> + *  @size: the size in bytes of the ram block
> + *  @mr: the memory region where the ram block is
> + *  @ram_flags: specify the properties of the ram block, which can be one
> + *              or bit-or of following values
> + *              - RAM_SHARED: mmap the back file or device with MAP_SHARED
> + *              Other bits are ignored.
> + *  @mem_path or @fd: specify the back file or device
> + *  @errp: pointer to Error*, to store an error if it happens
> + *
> + * Return:
> + *  On success, return a pointer to the ram block.
> + *  On failure, return NULL.
> + */
>  RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr,
> -                                   bool share, const char *mem_path,
> +                                   uint64_t ram_flags, const char *mem_path,
>                                     Error **errp);
>  RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
> -                                 bool share, int fd,
> +                                 uint64_t ram_flags, int fd,
>                                   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, bool share, MemoryRegion *mr,
> diff --git a/memory.c b/memory.c
> index 10fa2dd..08acae4 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1554,7 +1554,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
>                                        const char *name,
>                                        uint64_t size,
>                                        uint64_t align,
> -                                      bool share,
> +                                      uint64_t ram_flags,
>                                        const char *path,
>                                        Error **errp)
>  {
> @@ -1563,7 +1563,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr,
>      mr->terminates = true;
>      mr->destructor = memory_region_destructor_ram;
>      mr->align = align;
> -    mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp);
> +    mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path, errp);
>      mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
>  }
>  
> @@ -1579,7 +1579,9 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr,
>      mr->ram = true;
>      mr->terminates = true;
>      mr->destructor = memory_region_destructor_ram;
> -    mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp);
> +    mr->ram_block = qemu_ram_alloc_from_fd(size, mr,
> +                                           share ? RAM_SHARED : 0,
> +                                           fd, errp);
>      mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
>  }
>  #endif
> diff --git a/numa.c b/numa.c
> index 33572bf..ba72267 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -479,7 +479,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, 0, false,
> +        memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, 0,
>                                           mem_path, &err);
>          if (err) {
>              error_report_err(err);

  parent reply	other threads:[~2018-06-11 15:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01  8:10 [Qemu-devel] [PATCH V6 0/7] nvdimm: guarantee persistence of QEMU writes to persistent memory junyan.he
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 1/7] memory, exec: Expose all memory block related flags junyan.he
2018-06-05 11:38   ` Stefan Hajnoczi
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 2/7] memory, exec: switch file ram allocation functions to 'flags' parameters junyan.he
2018-06-05 11:40   ` Stefan Hajnoczi
2018-06-11 15:53   ` Igor Mammedov [this message]
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 3/7] hostmem-file: add the 'pmem' option junyan.he
2018-06-05 11:44   ` Stefan Hajnoczi
2018-06-11 16:02   ` Igor Mammedov
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 4/7] configure: add libpmem support junyan.he
2018-06-05 11:41   ` Stefan Hajnoczi
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 5/7] mem/nvdimm: ensure write persistence to PMEM in label emulation junyan.he
2018-06-05 11:44   ` Stefan Hajnoczi
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 6/7] migration/ram: Add check and info message to nvdimm post copy junyan.he
2018-06-05 11:44   ` Stefan Hajnoczi
2018-06-01  8:10 ` [Qemu-devel] [PATCH V6 7/7] migration/ram: ensure write persistence on loading all data to PMEM junyan.he
2018-06-05 11:44   ` Stefan Hajnoczi
2018-06-07 10:42     ` Dr. David Alan Gilbert
2018-06-01  8:27 ` [Qemu-devel] [PATCH V6 0/7] nvdimm: guarantee persistence of QEMU writes to persistent memory no-reply
2018-06-07 13:50   ` Stefan Hajnoczi
2018-06-01  8:33 ` no-reply
2018-06-12 12:06 ` Igor Mammedov
2018-06-12 13:38   ` Junyan He
2018-06-12 14:55     ` Igor Mammedov
2018-06-12 15:27       ` Junyan He
2018-06-12 15:43         ` Junyan He
2018-06-13 15:58           ` Igor Mammedov
2018-06-13 20:05     ` Eduardo Habkost

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=20180611175333.65745243@redhat.com \
    --to=imammedo@redhat.com \
    --cc=crosthwaite.peter@gmail.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=haozhong.zhang@intel.com \
    --cc=junyan.he@gmx.com \
    --cc=junyan.he@intel.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@twiddle.net \
    --cc=stefanha@redhat.com \
    --cc=xiaoguangrong.eric@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.