qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Peter Xu
Subject: [PATCH RFC 07/21] ramblock: Cache file offset for file-backed ramblocks
Date: Tue, 17 Jan 2023 17:09:00 -0500

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]