From: Gonglei <arei.gong...@huawei.com> Each RAM memory region has a unique corresponding RAMBlock. In the current realization, the memory region only stored the ram_addr which means the offset of RAM address space, We need to qurey the global ram.list to find the ram block by ram_addr if we want to get the ram block, which is very expensive.
Now, we store the RAMBlock pointer into memory region structure. So, if we know the mr, we can easily get the RAMBlock. Signed-off-by: Gonglei <arei.gong...@huawei.com> Message-Id: <1456130097-4208-2-git-send-email-arei.gong...@huawei.com> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- exec.c | 2 ++ include/exec/memory.h | 2 ++ memory.c | 1 + 3 files changed, 5 insertions(+) diff --git a/exec.c b/exec.c index 1f24500..4c0114a 100644 --- a/exec.c +++ b/exec.c @@ -1717,6 +1717,8 @@ ram_addr_t qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, error_propagate(errp, local_err); return -1; } + + mr->ram_block = new_block; return addr; } diff --git a/include/exec/memory.h b/include/exec/memory.h index c92734a..4025729 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -156,6 +156,7 @@ struct MemoryRegionIOMMUOps { typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; +typedef struct RAMBlock RAMBlock; struct MemoryRegion { Object parent_obj; @@ -172,6 +173,7 @@ struct MemoryRegion { bool global_locking; uint8_t dirty_log_mask; ram_addr_t ram_addr; + RAMBlock *ram_block; Object *owner; const MemoryRegionIOMMUOps *iommu_ops; diff --git a/memory.c b/memory.c index 09041ed..b4451dd 100644 --- a/memory.c +++ b/memory.c @@ -912,6 +912,7 @@ void memory_region_init(MemoryRegion *mr, } mr->name = g_strdup(name); mr->owner = owner; + mr->ram_block = NULL; if (name) { char *escaped_name = memory_region_escape_name(name); -- 2.5.0