From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Leonardo Bras Soares Passos <lsoaresp@redhat.com>,
James Houghton <jthoughton@google.com>,
Juan Quintela <quintela@redhat.com>,
peterx@redhat.com,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: [PATCH RFC 08/21] ramblock: Cache the length to do file mmap() on ramblocks
Date: Tue, 17 Jan 2023 17:09:01 -0500 [thread overview]
Message-ID: <20230117220914.2062125-9-peterx@redhat.com> (raw)
In-Reply-To: <20230117220914.2062125-1-peterx@redhat.com>
We do proper page size alignment for file backed mmap()s for ramblocks.
Even if it's as simple as that, cache the value because it'll be used in
multiple places.
Since at it, drop size for file_ram_alloc() and just use max_length because
that's always true for file-backed ramblocks.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/exec/ramblock.h | 2 ++
softmmu/physmem.c | 14 +++++++-------
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h
index 76cd0812c8..3f31ce1591 100644
--- a/include/exec/ramblock.h
+++ b/include/exec/ramblock.h
@@ -32,6 +32,8 @@ struct RAMBlock {
ram_addr_t offset;
ram_addr_t used_length;
ram_addr_t max_length;
+ /* Only used for file-backed ramblocks */
+ ram_addr_t mmap_length;
void (*resized)(const char*, uint64_t length, void *host);
uint32_t flags;
/* Protected by iothread lock. */
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index aa1a7466e5..b5be02f1cb 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -1533,7 +1533,6 @@ static int file_ram_open(const char *path,
}
static void *file_ram_alloc(RAMBlock *block,
- ram_addr_t memory,
int fd,
bool readonly,
bool truncate,
@@ -1563,14 +1562,14 @@ static void *file_ram_alloc(RAMBlock *block,
}
#endif
- if (memory < block->page_size) {
+ if (block->max_length < block->page_size) {
error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to "
"or larger than page size 0x%zx",
- memory, block->page_size);
+ block->max_length, block->page_size);
return NULL;
}
- memory = ROUND_UP(memory, block->page_size);
+ block->mmap_length = ROUND_UP(block->max_length, block->page_size);
/*
* ftruncate is not supported by hugetlbfs in older
@@ -1586,7 +1585,7 @@ static void *file_ram_alloc(RAMBlock *block,
* those labels. Therefore, extending the non-empty backend file
* is disabled as well.
*/
- if (truncate && ftruncate(fd, memory)) {
+ if (truncate && ftruncate(fd, block->mmap_length)) {
perror("ftruncate");
}
@@ -1594,7 +1593,8 @@ static void *file_ram_alloc(RAMBlock *block,
qemu_map_flags |= (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0;
qemu_map_flags |= (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0;
qemu_map_flags |= (block->flags & RAM_NORESERVE) ? QEMU_MAP_NORESERVE : 0;
- area = qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, offset);
+ area = qemu_ram_mmap(fd, block->mmap_length, block->mr->align,
+ qemu_map_flags, offset);
if (area == MAP_FAILED) {
error_setg_errno(errp, errno,
"unable to map backing store for guest RAM");
@@ -2100,7 +2100,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
new_block->used_length = size;
new_block->max_length = size;
new_block->flags = ram_flags;
- new_block->host = file_ram_alloc(new_block, size, fd, readonly,
+ new_block->host = file_ram_alloc(new_block, fd, readonly,
!file_size, offset, errp);
if (!new_block->host) {
g_free(new_block);
--
2.37.3
next prev parent reply other threads:[~2023-01-17 22:11 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 22:08 [PATCH RFC 00/21] migration: Support hugetlb doublemaps Peter Xu
2023-01-17 22:08 ` [PATCH RFC 01/21] update linux headers Peter Xu
2023-01-17 22:08 ` [PATCH RFC 02/21] util: Include osdep.h first in util/mmap-alloc.c Peter Xu
2023-01-18 12:00 ` Dr. David Alan Gilbert
2023-01-25 0:19 ` Philippe Mathieu-Daudé
2023-01-30 4:57 ` Juan Quintela
2023-01-17 22:08 ` [PATCH RFC 03/21] physmem: Add qemu_ram_is_hugetlb() Peter Xu
2023-01-18 12:02 ` Dr. David Alan Gilbert
2023-01-30 5:00 ` Juan Quintela
2023-01-17 22:08 ` [PATCH RFC 04/21] madvise: Include linux/mman.h under linux-headers/ Peter Xu
2023-01-18 12:08 ` Dr. David Alan Gilbert
2023-01-30 5:01 ` Juan Quintela
2023-01-17 22:08 ` [PATCH RFC 05/21] madvise: Add QEMU_MADV_SPLIT Peter Xu
2023-01-30 5:01 ` Juan Quintela
2023-01-17 22:08 ` [PATCH RFC 06/21] madvise: Add QEMU_MADV_COLLAPSE Peter Xu
2023-01-18 18:51 ` Dr. David Alan Gilbert
2023-01-18 20:21 ` Peter Xu
2023-01-30 5:02 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 07/21] ramblock: Cache file offset for file-backed ramblocks Peter Xu
2023-01-30 5:02 ` Juan Quintela
2023-01-17 22:09 ` Peter Xu [this message]
2023-01-23 18:51 ` [PATCH RFC 08/21] ramblock: Cache the length to do file mmap() on ramblocks Dr. David Alan Gilbert
2023-01-24 20:28 ` Peter Xu
2023-01-30 5:05 ` Juan Quintela
2023-01-30 22:07 ` Peter Xu
2023-01-17 22:09 ` [PATCH RFC 09/21] ramblock: Add RAM_READONLY Peter Xu
2023-01-23 19:42 ` Dr. David Alan Gilbert
2023-01-30 5:06 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 10/21] ramblock: Add ramblock_file_map() Peter Xu
2023-01-24 10:06 ` Dr. David Alan Gilbert
2023-01-24 20:47 ` Peter Xu
2023-01-25 9:24 ` Dr. David Alan Gilbert
2023-01-25 14:46 ` Peter Xu
2023-01-30 5:09 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 11/21] migration: Add hugetlb-doublemap cap Peter Xu
2023-01-24 12:45 ` Dr. David Alan Gilbert
2023-01-24 21:15 ` Peter Xu
2023-01-30 5:13 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 12/21] migration: Introduce page size for-migration-only Peter Xu
2023-01-24 13:20 ` Dr. David Alan Gilbert
2023-01-24 21:36 ` Peter Xu
2023-01-24 22:03 ` Peter Xu
2023-01-30 5:17 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 13/21] migration: Add migration_ram_pagesize_largest() Peter Xu
2023-01-24 17:34 ` Dr. David Alan Gilbert
2023-01-30 5:19 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 14/21] migration: Map hugetlbfs ramblocks twice, and pre-allocate Peter Xu
2023-01-25 14:25 ` Dr. David Alan Gilbert
2023-01-30 5:24 ` Juan Quintela
2023-01-30 22:35 ` Peter Xu
2023-02-01 18:53 ` Juan Quintela
2023-02-06 21:40 ` Peter Xu
2023-01-17 22:09 ` [PATCH RFC 15/21] migration: Teach qemu about minor faults and doublemap Peter Xu
2023-01-30 5:45 ` Juan Quintela
2023-01-30 22:50 ` Peter Xu
2023-02-01 18:55 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 16/21] migration: Enable doublemap with MADV_SPLIT Peter Xu
2023-02-01 18:59 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 17/21] migration: Rework ram discard logic for hugetlb double-map Peter Xu
2023-02-01 19:03 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 18/21] migration: Allow postcopy_register_shared_ufd() to fail Peter Xu
2023-02-01 19:09 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 19/21] migration: Add postcopy_mark_received() Peter Xu
2023-02-01 19:10 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 20/21] migration: Handle page faults using UFFDIO_CONTINUE Peter Xu
2023-02-01 19:24 ` Juan Quintela
2023-02-01 19:52 ` Juan Quintela
2023-01-17 22:09 ` [PATCH RFC 21/21] migration: Collapse huge pages again after postcopy finished Peter Xu
2023-02-01 19:49 ` Juan Quintela
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230117220914.2062125-9-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=dgilbert@redhat.com \
--cc=jthoughton@google.com \
--cc=lsoaresp@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).