From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxdF-0008L1-0i for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:15:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aYxd9-0002zq-9H for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:15:08 -0500 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:37976) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aYxd9-0002zd-2R for qemu-devel@nongnu.org; Thu, 25 Feb 2016 10:15:03 -0500 Received: by mail-wm0-x230.google.com with SMTP id a4so31991635wme.1 for ; Thu, 25 Feb 2016 07:15:03 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 25 Feb 2016 16:14:57 +0100 Message-Id: <1456413297-14675-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1456413297-14675-1-git-send-email-pbonzini@redhat.com> References: <1456413297-14675-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 15/19] exec: store RAMBlock pointer into memory region List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gonglei From: Gonglei 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 Message-Id: <1456130097-4208-2-git-send-email-arei.gonglei@huawei.com> Signed-off-by: Paolo Bonzini --- 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..683be46 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qom/object.h" #include "qemu/rcu.h" +#include "qemu/typedefs.h" #define MAX_PHYS_ADDR_SPACE_BITS 62 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) @@ -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