diff mbox series

[1/6] memory: Do not increase refcount on global system_memory region

Message ID 20210819142039.2825366-2-philmd@redhat.com (mailing list archive)
State New, archived
Headers show
Series memory: Introduce address_space_create(), re-use &address_space_memory | expand

Commit Message

Philippe Mathieu-Daudé Aug. 19, 2021, 2:20 p.m. UTC
system_memory is statically allocated in memory_map_init()
(softmmu/physmem.c) and is never destroyed. No need to
increment its refcount.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 softmmu/memory.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Peter Maydell Aug. 19, 2021, 2:23 p.m. UTC | #1
On Thu, 19 Aug 2021 at 15:20, Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
> system_memory is statically allocated in memory_map_init()
> (softmmu/physmem.c) and is never destroyed. No need to
> increment its refcount.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>  softmmu/memory.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index bfedaf9c4df..185f978c925 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -24,7 +24,7 @@
>  #include "qemu/qemu-print.h"
>  #include "qom/object.h"
>  #include "trace.h"
> -
> +#include "exec/address-spaces.h"
>  #include "exec/memory-internal.h"
>  #include "exec/ram_addr.h"
>  #include "sysemu/kvm.h"
> @@ -2923,7 +2923,9 @@ void address_space_remove_listeners(AddressSpace *as)
>
>  void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
>  {
> -    memory_region_ref(root);
> +    if (root != get_system_memory()) {
> +        memory_region_ref(root);
> +    }

...but there's no need to have an odd special in this code either,
is there? What harm does it do if the system memory MR has a lot of
references ?

-- PMM
diff mbox series

Patch

diff --git a/softmmu/memory.c b/softmmu/memory.c
index bfedaf9c4df..185f978c925 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -24,7 +24,7 @@ 
 #include "qemu/qemu-print.h"
 #include "qom/object.h"
 #include "trace.h"
-
+#include "exec/address-spaces.h"
 #include "exec/memory-internal.h"
 #include "exec/ram_addr.h"
 #include "sysemu/kvm.h"
@@ -2923,7 +2923,9 @@  void address_space_remove_listeners(AddressSpace *as)
 
 void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
 {
-    memory_region_ref(root);
+    if (root != get_system_memory()) {
+        memory_region_ref(root);
+    }
     as->root = root;
     as->current_map = NULL;
     as->ioeventfd_nb = 0;