[PATCH RFC 07/21] ramblock: Cache file offset for file-backed ramblocks

Peter Xu posted 21 patches 3 years ago
Maintainers: David Hildenbrand <david@redhat.com>, Igor Mammedov <imammedo@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Cornelia Huck <cohuck@redhat.com>, Juan Quintela <quintela@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
[PATCH RFC 07/21] ramblock: Cache file offset for file-backed ramblocks
Posted by Peter Xu 3 years ago
This value was only used for mmap() when we want to map at a specific
offset of the file for memory.  To be prepared that we might do another map
upon the same range for whatever reason, cache the offset so we know how to
map again on the same range.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/exec/ramblock.h | 5 +++++
 softmmu/physmem.c       | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
index adc03df59c..76cd0812c8 100644
--- a/include/exec/ramblock.h
+++ b/include/exec/ramblock.h
@@ -41,6 +41,11 @@ struct RAMBlock {
     QLIST_HEAD(, RAMBlockNotifier) ramblock_notifiers;
     int fd;
     size_t page_size;
+    /*
+     * Cache for file offset to map the ramblock.  Only used for
+     * file-backed ramblocks.
+     */
+    off_t file_offset;
     /* dirty bitmap used during migration */
     unsigned long *bmap;
     /* bitmap of already received pages in postcopy */
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index a4fb129d8f..aa1a7466e5 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1543,6 +1543,8 @@ static void *file_ram_alloc(RAMBlock *block,
     uint32_t qemu_map_flags;
     void *area;
 
+    /* Remember the offset just in case we'll need to map the range again */
+    block->file_offset = offset;
     block->page_size = qemu_fd_getpagesize(fd);
     if (block->mr->align % block->page_size) {
         error_setg(errp, "alignment 0x%" PRIx64
-- 
2.37.3
Re: [PATCH RFC 07/21] ramblock: Cache file offset for file-backed ramblocks
Posted by Juan Quintela 3 years ago
Peter Xu <peterx@redhat.com> wrote:
> This value was only used for mmap() when we want to map at a specific
> offset of the file for memory.  To be prepared that we might do another map
> upon the same range for whatever reason, cache the offset so we know how to
> map again on the same range.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>

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

A bit weird that we don't use it (yet) anywhere, but that is life.