From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ceZ-0001ws-3r for qemu-devel@nongnu.org; Thu, 17 Dec 2015 12:47:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9ceY-0006zC-4y for qemu-devel@nongnu.org; Thu, 17 Dec 2015 12:47:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57223) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ceX-0006z5-W3 for qemu-devel@nongnu.org; Thu, 17 Dec 2015 12:47:46 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 9751691E9C for ; Thu, 17 Dec 2015 17:47:45 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBHHkfcb014618 for ; Thu, 17 Dec 2015 12:47:44 -0500 From: Paolo Bonzini Date: Thu, 17 Dec 2015 18:46:31 +0100 Message-Id: <1450374401-31352-36-git-send-email-pbonzini@redhat.com> In-Reply-To: <1450374401-31352-1-git-send-email-pbonzini@redhat.com> References: <1450374401-31352-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 35/45] memory: avoid unnecessary object_ref/unref List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org For the common case of DMA into non-hotplugged RAM, it is unnecessary but expensive to do object_ref/unref. Add back an owner field to MemoryRegion, so that these memory regions can skip the reference counting. Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 1 + memory.c | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5b1fd12..24b7cba 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -172,6 +172,7 @@ struct MemoryRegion { bool global_locking; uint8_t dirty_log_mask; ram_addr_t ram_addr; + Object *owner; const MemoryRegionIOMMUOps *iommu_ops; const MemoryRegionOps *ops; diff --git a/memory.c b/memory.c index f666c77..b4d2b52 100644 --- a/memory.c +++ b/memory.c @@ -905,20 +905,22 @@ void memory_region_init(MemoryRegion *mr, const char *name, uint64_t size) { - if (!owner) { - owner = container_get(qdev_get_machine(), "/unattached"); - } - object_initialize(mr, sizeof(*mr), TYPE_MEMORY_REGION); mr->size = int128_make64(size); if (size == UINT64_MAX) { mr->size = int128_2_64(); } mr->name = g_strdup(name); + mr->owner = owner; if (name) { char *escaped_name = memory_region_escape_name(name); char *name_array = g_strdup_printf("%s[*]", escaped_name); + + if (!owner) { + owner = container_get(qdev_get_machine(), "/unattached"); + } + object_property_add_child(owner, name_array, OBJECT(mr), &error_abort); object_unref(OBJECT(mr)); g_free(name_array); @@ -1369,24 +1371,18 @@ void memory_region_ref(MemoryRegion *mr) * The memory region is a child of its owner. As long as the * owner doesn't call unparent itself on the memory region, * ref-ing the owner will also keep the memory region alive. - * Memory regions without an owner are supposed to never go away, - * but we still ref/unref them for debugging purposes. + * Memory regions without an owner are supposed to never go away; + * we do not ref/unref them because it slows down DMA sensibly. */ - Object *obj = OBJECT(mr); - if (obj && obj->parent) { - object_ref(obj->parent); - } else { - object_ref(obj); + if (mr && mr->owner) { + object_ref(mr->owner); } } void memory_region_unref(MemoryRegion *mr) { - Object *obj = OBJECT(mr); - if (obj && obj->parent) { - object_unref(obj->parent); - } else { - object_unref(obj); + if (mr && mr->owner) { + object_unref(mr->owner); } } -- 2.5.0