From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, david@redhat.com, cohuck@redhat.com,
dgilbert@redhat.com, borntraeger@de.ibm.com,
qemu-s390x@nongnu.org, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH RFC v2 3/4] memory: make MemoryRegion alias migratable
Date: Fri, 2 Aug 2019 05:38:53 -0400 [thread overview]
Message-ID: <20190802093854.5343-4-imammedo@redhat.com> (raw)
In-Reply-To: <20190802093854.5343-1-imammedo@redhat.com>
use qemu_ram_alloc_from_ptr() to create aliased RAMBlock
to the part of original memory region.
Change is migration safe as we do not migrate every existing RAMBlock
anymore, to make it migratable code has to explicitly call
vmstate_register_ram() on MemoryRegion that owns RAMBlock.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
PS:
tested ping-pong migration between new and old QEMU for x86 pc/q35
and s390 machines.
CC: dgilbert@redhat.com
exec.c | 9 +++++----
memory.c | 6 ++++++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/exec.c b/exec.c
index 3e78de3b8f..f5e9699632 100644
--- a/exec.c
+++ b/exec.c
@@ -2313,7 +2313,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
new_block->used_length,
DIRTY_CLIENTS_ALL);
- if (new_block->host) {
+ if (new_block->host && !new_block->mr->alias) {
qemu_ram_setup_dump(new_block->host, new_block->max_length);
qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_HUGEPAGE);
/* MADV_DONTFORK is also needed by KVM in absence of synchronous MMU */
@@ -2497,7 +2497,7 @@ void qemu_ram_free(RAMBlock *block)
return;
}
- if (block->host) {
+ if (block->host && !block->mr->alias) {
ram_block_notify_remove(block->host, block->max_length);
}
@@ -2671,7 +2671,8 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
rcu_read_lock();
block = atomic_rcu_read(&ram_list.mru_block);
- if (block && block->host && host - block->host < block->max_length) {
+ if (block && !block->mr->alias && block->host &&
+ host - block->host < block->max_length) {
goto found;
}
@@ -2680,7 +2681,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
if (block->host == NULL) {
continue;
}
- if (host - block->host < block->max_length) {
+ if (!block->mr->alias && host - block->host < block->max_length) {
goto found;
}
}
diff --git a/memory.c b/memory.c
index 5d8c9a9234..d7c3609ce3 100644
--- a/memory.c
+++ b/memory.c
@@ -1678,6 +1678,12 @@ void memory_region_init_alias(MemoryRegion *mr,
memory_region_init(mr, owner, name, size);
mr->alias = orig;
mr->alias_offset = offset;
+ if (orig->ram_block && size) {
+ mr->destructor = memory_region_destructor_ram;
+ mr->ram_block = qemu_ram_alloc_from_ptr(size,
+ orig->ram_block->host + offset,
+ mr, &error_fatal);
+ }
}
void memory_region_init_rom_nomigrate(MemoryRegion *mr,
--
2.18.1
next prev parent reply other threads:[~2019-08-02 9:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-02 9:38 [Qemu-devel] [PATCH RFC v2 0/4] s390: stop abusing memory_region_allocate_system_memory() Igor Mammedov
2019-08-02 9:38 ` [Qemu-devel] [PATCH RFC v2 1/4] hw: add compat machines for 4.2 Igor Mammedov
2019-08-02 9:38 ` [Qemu-devel] [PATCH RFC v2 2/4] kvm: s390: split too big memory section on several memslots Igor Mammedov
2019-08-02 9:38 ` Igor Mammedov [this message]
2019-08-02 9:38 ` [Qemu-devel] [PATCH RFC v2 4/4] s390: do not call memory_region_allocate_system_memory() multiple times Igor Mammedov
2019-08-02 10:25 ` David Hildenbrand
2019-08-02 10:27 ` Christian Borntraeger
2019-08-02 11:40 ` Igor Mammedov
2019-08-02 12:13 ` Christian Borntraeger
2019-08-02 9:53 ` [Qemu-devel] [PATCH RFC v2 0/4] s390: stop abusing memory_region_allocate_system_memory() no-reply
2019-08-02 10:09 ` no-reply
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=20190802093854.5343-4-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@redhat.com \
--cc=dgilbert@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=thuth@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).