[Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing

Dr. David Alan Gilbert (git) posted 2 patches 7 years, 9 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing
Posted by Dr. David Alan Gilbert (git) 7 years, 9 months ago
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

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 <dgilbert@redhat.com>
---
 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
-- 
2.14.3


Re: [Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing
Posted by Eric Blake 7 years, 9 months ago
On 01/05/2018 11:01 AM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> 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 <dgilbert@redhat.com>
> ---
>  exec.c       | 17 ++++++++++++++++-
>  trace-events |  3 +++
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 

> +
> +        /* 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.

s/so avoiding/in order to avoid/

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 1/2] find_ram_offset: Add comments and tracing
Posted by Juan Quintela 7 years, 9 months ago
"Dr. David Alan Gilbert (git)" <dgilbert@redhat.com> wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> 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 <dgilbert@redhat.com>


Reviewed-by: Juan Quintela <quintela@redhat.com>