diff mbox series

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

Message ID 20230117220914.2062125-8-peterx@redhat.com
State New
Headers show
Series migration: Support hugetlb doublemaps | expand

Commit Message

Peter Xu Jan. 17, 2023, 10:09 p.m. UTC
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(+)

Comments

Juan Quintela Jan. 30, 2023, 5:02 a.m. UTC | #1
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.
diff mbox series

Patch

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