diff mbox

Memory: use memory address space for cpu-memory

Message ID 1494972923-31756-1-git-send-email-anthony.xu@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xu, Anthony May 16, 2017, 10:15 p.m. UTC
If cpu-memory address space is same as memory address space,
use memory address space for cpu-memory address space.

any memory region change causeaddress space to rebuild PhysPageMap,
rebuilding PhysPageMap is very expensive.

removing cpu-memory address space reduces the guest boot time and
memory usage.

Signed-off-by: Anthony Xu <anthony.xu@intel.com>
---
 cpus.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Igor Mammedov May 17, 2017, 9:27 a.m. UTC | #1
On Tue, 16 May 2017 15:15:23 -0700
Anthony Xu <anthony.xu@intel.com> wrote:

> If cpu-memory address space is same as memory address space,
> use memory address space for cpu-memory address space.
> 
> any memory region change causeaddress space to rebuild PhysPageMap,
> rebuilding PhysPageMap is very expensive.
> 
> removing cpu-memory address space reduces the guest boot time and
> memory usage.
> 
> Signed-off-by: Anthony Xu <anthony.xu@intel.com>
> ---
>  cpus.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/cpus.c b/cpus.c
> index 740b8dc..15c7a6a 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1748,8 +1748,13 @@ void qemu_init_vcpu(CPUState *cpu)
>          /* If the target cpu hasn't set up any address spaces itself,
>           * give it the default one.
>           */
> -        AddressSpace *as = address_space_init_shareable(cpu->memory,
> -                                                        "cpu-memory");
> +        AddressSpace *as;
> +        if (cpu->memory == address_space_memory.root) {
> +            address_space_memory.ref_count++;
probably this would cause reference leak when vcpu is destroyed

> +            as = &address_space_memory;
> +        } else {
> +            as = address_space_init_shareable(cpu->memory, "cpu-memory");
> +        }
>          cpu->num_ases = 1;
>          cpu_address_space_init(cpu, as, 0);
>      }
Xu, Anthony May 17, 2017, 5:01 p.m. UTC | #2
> > If cpu-memory address space is same as memory address space,
> > use memory address space for cpu-memory address space.
> >
> > any memory region change causeaddress space to rebuild PhysPageMap,
> > rebuilding PhysPageMap is very expensive.
> >
> > removing cpu-memory address space reduces the guest boot time and
> > memory usage.
> >
> > Signed-off-by: Anthony Xu <anthony.xu@intel.com>
> > ---
> >  cpus.c | 9 +++++++--
> >  1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/cpus.c b/cpus.c
> > index 740b8dc..15c7a6a 100644
> > --- a/cpus.c
> > +++ b/cpus.c
> > @@ -1748,8 +1748,13 @@ void qemu_init_vcpu(CPUState *cpu)
> >          /* If the target cpu hasn't set up any address spaces itself,
> >           * give it the default one.
> >           */
> > -        AddressSpace *as = address_space_init_shareable(cpu->memory,
> > -                                                        "cpu-memory");
> > +        AddressSpace *as;
> > +        if (cpu->memory == address_space_memory.root) {
> > +            address_space_memory.ref_count++;
> probably this would cause reference leak when vcpu is destroyed

I thought address_space_destroy is called when vcpu is unplugged,
seems that's not the case, then ref_count++ is not needed.

Any other comments?


Thanks,
Anthony
diff mbox

Patch

diff --git a/cpus.c b/cpus.c
index 740b8dc..15c7a6a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1748,8 +1748,13 @@  void qemu_init_vcpu(CPUState *cpu)
         /* If the target cpu hasn't set up any address spaces itself,
          * give it the default one.
          */
-        AddressSpace *as = address_space_init_shareable(cpu->memory,
-                                                        "cpu-memory");
+        AddressSpace *as;
+        if (cpu->memory == address_space_memory.root) {
+            address_space_memory.ref_count++;
+            as = &address_space_memory;
+        } else {
+            as = address_space_init_shareable(cpu->memory, "cpu-memory");
+        }
         cpu->num_ases = 1;
         cpu_address_space_init(cpu, as, 0);
     }