diff mbox

[06/15] exec: use mmap for subpages

Message ID 1467104499-27517-7-git-send-email-pl@kamp.de (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Lieven June 28, 2016, 9:01 a.m. UTC
a lot of subpages are created and freed at startup, but RCU delays
the freeing so the heap gets fragmented.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 exec.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Paolo Bonzini June 28, 2016, 10:48 a.m. UTC | #1
On 28/06/2016 11:01, Peter Lieven wrote:
> a lot of subpages are created and freed at startup, but RCU delays
> the freeing so the heap gets fragmented.
> 
> Signed-off-by: Peter Lieven <pl@kamp.de>

I agree that subpages are bad for malloc because they are large (>
4KiB).  It is worth doing something special about them.  However, on
32-bit systems mmap-ing them has the same risk of fragmenting the
process address space, as malloc has of fragmenting the brk heap.

Allocation and freeing of subpages always happens under the BQL, so
perhaps a simple freelist is better?  Another interesting (but harder)
possibility could be to build the radix tree lazily.

Paolo
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 0122ef7..1b7be2a 100644
--- a/exec.c
+++ b/exec.c
@@ -49,6 +49,7 @@ 
 #include "exec/cpu-all.h"
 #include "qemu/rcu_queue.h"
 #include "qemu/main-loop.h"
+#include "qemu/mmap-alloc.h"
 #include "translate-all.h"
 #include "sysemu/replay.h"
 
@@ -1150,7 +1151,7 @@  static void phys_section_destroy(MemoryRegion *mr)
     if (have_sub_page) {
         subpage_t *subpage = container_of(mr, subpage_t, iomem);
         object_unref(OBJECT(&subpage->iomem));
-        g_free(subpage);
+        qemu_anon_ram_munmap(subpage, sizeof(subpage_t));
     }
 }
 
@@ -2270,7 +2271,7 @@  static subpage_t *subpage_init(AddressSpace *as, hwaddr base)
 {
     subpage_t *mmio;
 
-    mmio = g_malloc0(sizeof(subpage_t));
+    mmio = qemu_anon_ram_mmap(sizeof(subpage_t));
 
     mmio->as = as;
     mmio->base = base;