Re: [Qemu-devel] [PATCH v4 3/6] vhost: Add temporary memory structure

2017-12-15 Thread Dr. David Alan Gilbert
* Igor Mammedov (imamm...@redhat.com) wrote:
> On Wed, 13 Dec 2017 18:08:04 +
> "Dr. David Alan Gilbert (git)"  wrote:
> 
> > From: "Dr. David Alan Gilbert" 
> > 
> > Add a 2nd 'vhost_memory' structure that will be used to build
> > the new version as the listener iterates over the address space.
> I'd suggest to add temporary 'mem_sections' instead and
> create/use/free temporary 'vhost_memory' structure at commit time,
> (1 less duplicated data set to keep in memory)

I don't see how this leads to less duplication;  I still end up with
one set of temporary structures, and the sections use Int128 which
is a pain to work with in the comparison/merging code.

Dave

> > 
> > Signed-off-by: Dr. David Alan Gilbert 
> > ---
> >  hw/virtio/vhost.c | 3 +++
> >  include/hw/virtio/vhost.h | 1 +
> >  2 files changed, 4 insertions(+)
> > 
> > diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> > index c7ce7baf9b..4523f45587 100644
> > --- a/hw/virtio/vhost.c
> > +++ b/hw/virtio/vhost.c
> > @@ -632,6 +632,8 @@ static void vhost_begin(MemoryListener *listener)
> >   memory_listener);
> >  dev->mem_changed_end_addr = 0;
> >  dev->mem_changed_start_addr = -1;
> > +
> > +dev->tmp_mem = g_malloc0(offsetof(struct vhost_memory, regions));
> >  }
> >  
> >  static void vhost_commit(MemoryListener *listener)
> > @@ -641,6 +643,7 @@ static void vhost_commit(MemoryListener *listener)
> >  uint64_t log_size;
> >  int r;
> >  
> > +g_free(dev->tmp_mem);
> >  if (!dev->memory_changed) {
> >  return;
> >  }
> > diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
> > index 467dc7794b..41f9e569be 100644
> > --- a/include/hw/virtio/vhost.h
> > +++ b/include/hw/virtio/vhost.h
> > @@ -70,6 +70,7 @@ struct vhost_dev {
> >  bool memory_changed;
> >  hwaddr mem_changed_start_addr;
> >  hwaddr mem_changed_end_addr;
> > +struct vhost_memory *tmp_mem;
> >  const VhostOps *vhost_ops;
> >  void *opaque;
> >  struct vhost_log *log;
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH v4 3/6] vhost: Add temporary memory structure

2017-12-14 Thread Igor Mammedov
On Wed, 13 Dec 2017 18:08:04 +
"Dr. David Alan Gilbert (git)"  wrote:

> From: "Dr. David Alan Gilbert" 
> 
> Add a 2nd 'vhost_memory' structure that will be used to build
> the new version as the listener iterates over the address space.
I'd suggest to add temporary 'mem_sections' instead and
create/use/free temporary 'vhost_memory' structure at commit time,
(1 less duplicated data set to keep in memory)

> 
> Signed-off-by: Dr. David Alan Gilbert 
> ---
>  hw/virtio/vhost.c | 3 +++
>  include/hw/virtio/vhost.h | 1 +
>  2 files changed, 4 insertions(+)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index c7ce7baf9b..4523f45587 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -632,6 +632,8 @@ static void vhost_begin(MemoryListener *listener)
>   memory_listener);
>  dev->mem_changed_end_addr = 0;
>  dev->mem_changed_start_addr = -1;
> +
> +dev->tmp_mem = g_malloc0(offsetof(struct vhost_memory, regions));
>  }
>  
>  static void vhost_commit(MemoryListener *listener)
> @@ -641,6 +643,7 @@ static void vhost_commit(MemoryListener *listener)
>  uint64_t log_size;
>  int r;
>  
> +g_free(dev->tmp_mem);
>  if (!dev->memory_changed) {
>  return;
>  }
> diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
> index 467dc7794b..41f9e569be 100644
> --- a/include/hw/virtio/vhost.h
> +++ b/include/hw/virtio/vhost.h
> @@ -70,6 +70,7 @@ struct vhost_dev {
>  bool memory_changed;
>  hwaddr mem_changed_start_addr;
>  hwaddr mem_changed_end_addr;
> +struct vhost_memory *tmp_mem;
>  const VhostOps *vhost_ops;
>  void *opaque;
>  struct vhost_log *log;




[Qemu-devel] [PATCH v4 3/6] vhost: Add temporary memory structure

2017-12-13 Thread Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" 

Add a 2nd 'vhost_memory' structure that will be used to build
the new version as the listener iterates over the address space.

Signed-off-by: Dr. David Alan Gilbert 
---
 hw/virtio/vhost.c | 3 +++
 include/hw/virtio/vhost.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index c7ce7baf9b..4523f45587 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -632,6 +632,8 @@ static void vhost_begin(MemoryListener *listener)
  memory_listener);
 dev->mem_changed_end_addr = 0;
 dev->mem_changed_start_addr = -1;
+
+dev->tmp_mem = g_malloc0(offsetof(struct vhost_memory, regions));
 }
 
 static void vhost_commit(MemoryListener *listener)
@@ -641,6 +643,7 @@ static void vhost_commit(MemoryListener *listener)
 uint64_t log_size;
 int r;
 
+g_free(dev->tmp_mem);
 if (!dev->memory_changed) {
 return;
 }
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 467dc7794b..41f9e569be 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -70,6 +70,7 @@ struct vhost_dev {
 bool memory_changed;
 hwaddr mem_changed_start_addr;
 hwaddr mem_changed_end_addr;
+struct vhost_memory *tmp_mem;
 const VhostOps *vhost_ops;
 void *opaque;
 struct vhost_log *log;
-- 
2.14.3