[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V1 13/26] physmem: ram_block_create
|
From: |
Steve Sistare |
|
Subject: |
[PATCH V1 13/26] physmem: ram_block_create |
|
Date: |
Mon, 29 Apr 2024 08:55:22 -0700 |
Create a common subroutine to allocate a RAMBlock, de-duping the code to
populate its common fields. Add a trace point for good measure.
No functional change.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
system/physmem.c | 47 ++++++++++++++++++++++++++---------------------
system/trace-events | 3 +++
2 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/system/physmem.c b/system/physmem.c
index c3d04ca..6216b14 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -52,6 +52,7 @@
#include "sysemu/hw_accel.h"
#include "sysemu/xen-mapcache.h"
#include "trace/trace-root.h"
+#include "trace.h"
#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
#include <linux/falloc.h>
@@ -1918,11 +1919,29 @@ out_free:
}
}
+static RAMBlock *ram_block_create(MemoryRegion *mr, ram_addr_t size,
+ ram_addr_t max_size, uint32_t ram_flags)
+{
+ RAMBlock *rb = g_malloc0(sizeof(*rb));
+
+ rb->used_length = size;
+ rb->max_length = max_size;
+ rb->fd = -1;
+ rb->flags = ram_flags;
+ rb->page_size = qemu_real_host_page_size();
+ rb->mr = mr;
+ rb->guest_memfd = -1;
+ trace_ram_block_create(rb->idstr, rb->flags, rb->fd, rb->used_length,
+ rb->max_length, mr->align);
+ return rb;
+}
+
#ifdef CONFIG_POSIX
RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
uint32_t ram_flags, int fd, off_t offset,
Error **errp)
{
+ void *host;
RAMBlock *new_block;
Error *local_err = NULL;
int64_t file_size, file_align;
@@ -1962,19 +1981,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size,
MemoryRegion *mr,
return NULL;
}
- new_block = g_malloc0(sizeof(*new_block));
- new_block->mr = mr;
- new_block->used_length = size;
- new_block->max_length = size;
- new_block->flags = ram_flags;
- new_block->guest_memfd = -1;
- new_block->host = file_ram_alloc(new_block, size, fd, !file_size, offset,
- errp);
- if (!new_block->host) {
+ new_block = ram_block_create(mr, size, size, ram_flags);
+ host = file_ram_alloc(new_block, size, fd, !file_size, offset, errp);
+ if (!host) {
g_free(new_block);
return NULL;
}
+ new_block->host = host;
ram_block_add(new_block, &local_err);
if (local_err) {
g_free(new_block);
@@ -1982,7 +1996,6 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size,
MemoryRegion *mr,
return NULL;
}
return new_block;
-
}
@@ -2054,18 +2067,10 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size,
ram_addr_t max_size,
align = MAX(align, TARGET_PAGE_SIZE);
size = ROUND_UP(size, align);
max_size = ROUND_UP(max_size, align);
-
- new_block = g_malloc0(sizeof(*new_block));
- new_block->mr = mr;
- new_block->resized = resized;
- new_block->used_length = size;
- new_block->max_length = max_size;
assert(max_size >= size);
- new_block->fd = -1;
- new_block->guest_memfd = -1;
- new_block->page_size = qemu_real_host_page_size();
- new_block->host = host;
- new_block->flags = ram_flags;
+ new_block = ram_block_create(mr, size, max_size, ram_flags);
+ new_block->resized = resized;
+
ram_block_add(new_block, &local_err);
if (local_err) {
g_free(new_block);
diff --git a/system/trace-events b/system/trace-events
index 69c9044..f0a80ba 100644
--- a/system/trace-events
+++ b/system/trace-events
@@ -38,3 +38,6 @@ dirtylimit_state_finalize(void)
dirtylimit_throttle_pct(int cpu_index, uint64_t pct, int64_t time_us) "CPU[%d]
throttle percent: %" PRIu64 ", throttle adjust time %"PRIi64 " us"
dirtylimit_set_vcpu(int cpu_index, uint64_t quota) "CPU[%d] set dirty page
rate limit %"PRIu64
dirtylimit_vcpu_execute(int cpu_index, int64_t sleep_time_us) "CPU[%d] sleep
%"PRIi64 " us"
+
+# physmem.c
+ram_block_create(const char *name, uint32_t flags, int fd, size_t used_length,
size_t max_length, size_t align) "%s, flags %u, fd %d, len %lu, maxlen %lu,
align %lu"
--
1.8.3.1
- [PATCH V1 09/26] migration: vmstate_register_named, (continued)
- [PATCH V1 09/26] migration: vmstate_register_named, Steve Sistare, 2024/04/29
- [PATCH V1 07/26] migration: VMStateId, Steve Sistare, 2024/04/29
- [PATCH V1 25/26] migration: fix mismatched GPAs during cpr-exec, Steve Sistare, 2024/04/29
- [PATCH V1 17/26] machine: memfd-alloc option, Steve Sistare, 2024/04/29
- [PATCH V1 19/26] physmem: preserve ram blocks for cpr, Steve Sistare, 2024/04/29
- [PATCH V1 26/26] migration: only-migratable-modes, Steve Sistare, 2024/04/29
- [PATCH V1 15/26] physmem: hoist host memory allocation, Steve Sistare, 2024/04/29
- [PATCH V1 14/26] physmem: hoist guest_memfd creation, Steve Sistare, 2024/04/29
- [PATCH V1 18/26] migration: cpr-exec-args parameter, Steve Sistare, 2024/04/29
- [PATCH V1 20/26] migration: cpr-exec mode, Steve Sistare, 2024/04/29
- [PATCH V1 13/26] physmem: ram_block_create,
Steve Sistare <=
- [PATCH V1 08/26] migration: vmstate_info_void_ptr, Steve Sistare, 2024/04/29
- [PATCH V1 23/26] migration: misc cpr-exec blockers, Steve Sistare, 2024/04/29
- [PATCH V1 16/26] physmem: set ram block idstr earlier, Steve Sistare, 2024/04/29
- [PATCH V1 21/26] migration: migrate_add_blocker_mode, Steve Sistare, 2024/04/29