From patchwork Mon Aug 8 16:58:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 108992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 28E8DB6F70 for ; Tue, 9 Aug 2011 02:59:05 +1000 (EST) Received: from localhost ([::1]:49287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QqTAM-00029n-AD for incoming@patchwork.ozlabs.org; Mon, 08 Aug 2011 12:59:02 -0400 Received: from eggs.gnu.org ([140.186.70.92]:55747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QqTAG-00029X-Sy for qemu-devel@nongnu.org; Mon, 08 Aug 2011 12:58:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QqTAF-0000UR-NO for qemu-devel@nongnu.org; Mon, 08 Aug 2011 12:58:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QqTAF-0000UB-Df for qemu-devel@nongnu.org; Mon, 08 Aug 2011 12:58:55 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p78GwsbS032353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 8 Aug 2011 12:58:54 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p78GwrAl027199; Mon, 8 Aug 2011 12:58:53 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 8AA39250B43; Mon, 8 Aug 2011 19:58:52 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Mon, 8 Aug 2011 19:58:48 +0300 Message-Id: <1312822730-9577-2-git-send-email-avi@redhat.com> In-Reply-To: <1312822730-9577-1-git-send-email-avi@redhat.com> References: <1312822730-9577-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 1/3] memory: reclaim resources when a memory region is destroyed for good X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Avi Kivity --- memory.c | 24 ++++++++++++++++++++++++ memory.h | 1 + 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/memory.c b/memory.c index be891c6..5e3d966 100644 --- a/memory.c +++ b/memory.c @@ -661,6 +661,25 @@ void memory_region_transaction_commit(void) memory_region_update_topology(); } +static void memory_region_destructor_none(MemoryRegion *mr) +{ +} + +static void memory_region_destructor_ram(MemoryRegion *mr) +{ + qemu_ram_free(mr->ram_addr); +} + +static void memory_region_destructor_ram_from_ptr(MemoryRegion *mr) +{ + qemu_ram_free_from_ptr(mr->ram_addr); +} + +static void memory_region_destructor_iomem(MemoryRegion *mr) +{ + cpu_unregister_io_memory(mr->ram_addr); +} + void memory_region_init(MemoryRegion *mr, const char *name, uint64_t size) @@ -671,6 +690,7 @@ void memory_region_init(MemoryRegion *mr, mr->addr = 0; mr->offset = 0; mr->terminates = false; + mr->destructor = memory_region_destructor_none; mr->priority = 0; mr->may_overlap = false; mr->alias = NULL; @@ -833,6 +853,7 @@ static void memory_region_prepare_ram_addr(MemoryRegion *mr) return; } + mr->destructor = memory_region_destructor_iomem; mr->ram_addr = cpu_register_io_memory(memory_region_read_thunk, memory_region_write_thunk, mr, @@ -860,6 +881,7 @@ void memory_region_init_ram(MemoryRegion *mr, { memory_region_init(mr, name, size); mr->terminates = true; + mr->destructor = memory_region_destructor_ram; mr->ram_addr = qemu_ram_alloc(dev, name, size); mr->backend_registered = true; } @@ -872,6 +894,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, { memory_region_init(mr, name, size); mr->terminates = true; + mr->destructor = memory_region_destructor_ram_from_ptr; mr->ram_addr = qemu_ram_alloc_from_ptr(dev, name, size, ptr); mr->backend_registered = true; } @@ -890,6 +913,7 @@ void memory_region_init_alias(MemoryRegion *mr, void memory_region_destroy(MemoryRegion *mr) { assert(QTAILQ_EMPTY(&mr->subregions)); + mr->destructor(mr); memory_region_clear_coalescing(mr); qemu_free((char *)mr->name); qemu_free(mr->ioeventfds); diff --git a/memory.h b/memory.h index da00a3b..c9252a2 100644 --- a/memory.h +++ b/memory.h @@ -109,6 +109,7 @@ struct MemoryRegion { target_phys_addr_t addr; target_phys_addr_t offset; bool backend_registered; + void (*destructor)(MemoryRegion *mr); ram_addr_t ram_addr; IORange iorange; bool terminates;