From patchwork Fri Jan 5 17:01:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 856123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zCrZX2jFRz9s4s for ; Sat, 6 Jan 2018 04:02:42 +1100 (AEDT) Received: from localhost ([::1]:49230 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXVOC-0002vy-6x for incoming@patchwork.ozlabs.org; Fri, 05 Jan 2018 12:02:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXVNN-0002u5-79 for qemu-devel@nongnu.org; Fri, 05 Jan 2018 12:01:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXVNM-0000R3-9o for qemu-devel@nongnu.org; Fri, 05 Jan 2018 12:01:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1571) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXVNL-0000QA-WD for qemu-devel@nongnu.org; Fri, 05 Jan 2018 12:01:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32DE376545 for ; Fri, 5 Jan 2018 17:02:08 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-117-111.ams2.redhat.com [10.36.117.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B54660263; Fri, 5 Jan 2018 17:01:42 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 5 Jan 2018 17:01:37 +0000 Message-Id: <20180105170138.23357-2-dgilbert@redhat.com> In-Reply-To: <20180105170138.23357-1-dgilbert@redhat.com> References: <20180105170138.23357-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 05 Jan 2018 17:02:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" From: "Dr. David Alan Gilbert" Add some comments so I can understand the various nested loops. Add some tracing so I can see what they're doing. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Eric Blake Reviewed-by: Juan Quintela --- exec.c | 17 ++++++++++++++++- trace-events | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 5973c666c8..7966570231 100644 --- a/exec.c +++ b/exec.c @@ -1665,7 +1665,10 @@ static void *file_ram_alloc(RAMBlock *block, } #endif -/* Called with the ramlist lock held. */ +/* Allocate space within the ram_addr_t space that governs the + * dirty bitmaps. + * Called with the ramlist lock held. + */ static ram_addr_t find_ram_offset(ram_addr_t size) { RAMBlock *block, *next_block; @@ -1682,15 +1685,25 @@ static ram_addr_t find_ram_offset(ram_addr_t size) end = block->offset + block->max_length; + /* Search for the closest following block + * and find the gap. + */ RAMBLOCK_FOREACH(next_block) { if (next_block->offset >= end) { next = MIN(next, next_block->offset); } } + + /* If it fits remember our place and remember the size + * of gap, but keep going so that we might find a smaller + * gap to fill so avoiding fragmentation. + */ if (next - end >= size && next - end < mingap) { offset = end; mingap = next - end; } + + trace_find_ram_offset_loop(size, offset, end, next, mingap); } if (offset == RAM_ADDR_MAX) { @@ -1699,6 +1712,8 @@ static ram_addr_t find_ram_offset(ram_addr_t size) abort(); } + trace_find_ram_offset(size, offset); + return offset; } diff --git a/trace-events b/trace-events index a8861bd800..23bc036aa1 100644 --- a/trace-events +++ b/trace-events @@ -56,6 +56,9 @@ dma_blk_cb(void *dbs, int ret) "dbs=%p ret=%d" dma_map_wait(void *dbs) "dbs=%p" # exec.c +find_ram_offset(uint64_t size, uint64_t offset) "size: 0x%"PRIx64 " @ 0x%"PRIx64 +find_ram_offset_loop(uint64_t size, uint64_t offset, uint64_t end, uint64_t next, uint64_t mingap) "size: 0x%"PRIx64 " @ 0x%"PRIx64 " end: 0x%"PRIx64" next: 0x%"PRIx64 " mingap: 0x%"PRIx64 + ram_block_discard_range(const char *rbname, void *hva, bool need_madvise, bool need_fallocate, int ret) "%s@%p: madvise: %d fallocate: %d ret: %d" # memory.c