From: Peter Lieven <pl@kamp.de>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: dgilbert@redhat.com, quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH] migration: cache memory region ram ptr
Date: Sat, 10 May 2014 18:44:19 +0200 [thread overview]
Message-ID: <536E5763.6070006@kamp.de> (raw)
In-Reply-To: <536E5495.6080401@kamp.de>
or even this:
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 1d55ad9..3003875 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -161,6 +161,7 @@ struct MemoryRegion {
unsigned ioeventfd_nb;
MemoryRegionIoeventfd *ioeventfds;
NotifierList iommu_notify;
+ void *ram_ptr;
};
/**
diff --git a/memory.c b/memory.c
index 3f1df23..6c1e413 100644
--- a/memory.c
+++ b/memory.c
@@ -862,6 +862,7 @@ void memory_region_init(MemoryRegion *mr,
mr->ioeventfd_nb = 0;
mr->ioeventfds = NULL;
mr->flush_coalesced_mmio = false;
+ mr->ram_ptr = NULL;
}
static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
@@ -1241,17 +1242,23 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,
cpu_physical_memory_reset_dirty(mr->ram_addr + addr, size, client);
}
-void *memory_region_get_ram_ptr(MemoryRegion *mr)
+static void *memory_region_get_ram_ptr2(MemoryRegion *mr)
{
if (mr->alias) {
return memory_region_get_ram_ptr(mr->alias) + mr->alias_offset;
}
-
assert(mr->terminates);
-
return qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK);
}
+inline void *memory_region_get_ram_ptr(MemoryRegion *mr)
+{
+ if (!mr->ram_ptr) {
+ mr->ram_ptr = memory_region_get_ram_ptr2(mr);
+ }
+ return mr->ram_ptr;
+}
+
static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
{
FlatView *view;
Am 10.05.2014 18:32, schrieb Peter Lieven:
> Am 10.05.2014 17:33, schrieb Paolo Bonzini:
>> Il 10/05/2014 12:51, Peter Lieven ha scritto:
>>> we currently look up the ram ptr for each single page. Cache
>>> the pointer while we operate on the same block.
>> Why don't you instead cache the result in the MemoryRegion, so that memory_region_get_ram_ptr becomes a simple, inline field access?
> This seems to work. Wondering if it has other side implications. Basic tests like booting vServers and migration work. What about XEN?
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 1d55ad9..3003875 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -161,6 +161,7 @@ struct MemoryRegion {
> unsigned ioeventfd_nb;
> MemoryRegionIoeventfd *ioeventfds;
> NotifierList iommu_notify;
> + void *ram_ptr;
> };
>
> /**
> diff --git a/memory.c b/memory.c
> index 3f1df23..78d4032 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -862,6 +862,7 @@ void memory_region_init(MemoryRegion *mr,
> mr->ioeventfd_nb = 0;
> mr->ioeventfds = NULL;
> mr->flush_coalesced_mmio = false;
> + mr->ram_ptr = NULL;
> }
>
> static uint64_t unassigned_mem_read(void *opaque, hwaddr addr,
> @@ -1249,7 +1250,12 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr)
>
> assert(mr->terminates);
>
> - return qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK);
> + if (mr->ram_ptr) {
> + return mr->ram_ptr;
> + }
> +
> + mr->ram_ptr = qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK);
> + return mr->ram_ptr;
> }
>
> static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
>
>
> Peter
>
>> Paolo
>>
>>> Signed-off-by: Peter Lieven <pl@kamp.de>
>>> ---
>>> arch_init.c | 23 ++++++++++++++++-------
>>> 1 file changed, 16 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/arch_init.c b/arch_init.c
>>> index 582b716..ce338aa 100644
>>> --- a/arch_init.c
>>> +++ b/arch_init.c
>>> @@ -594,13 +594,19 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
>>> ram_bulk_stage = false;
>>> }
>>> } else {
>>> + static uint8_t *ram_ptr;
>>> int ret;
>>> uint8_t *p;
>>> bool send_async = true;
>>> - int cont = (block == last_sent_block) ?
>>> - RAM_SAVE_FLAG_CONTINUE : 0;
>>> + int cont = 0;
>>>
>>> - p = memory_region_get_ram_ptr(mr) + offset;
>>> + if (block != last_sent_block) {
>>> + ram_ptr = memory_region_get_ram_ptr(mr);
>>> + } else {
>>> + cont = RAM_SAVE_FLAG_CONTINUE;
>>> + }
>>> +
>>> + p = ram_ptr + offset;
>>>
>>> /* In doubt sent page as normal */
>>> bytes_sent = -1;
>>> @@ -990,16 +996,17 @@ static inline void *host_from_stream_offset(QEMUFile *f,
>>> int flags)
>>> {
>>> static RAMBlock *block = NULL;
>>> + static uint8_t *ram_ptr;
>>> char id[256];
>>> uint8_t len;
>>>
>>> if (flags & RAM_SAVE_FLAG_CONTINUE) {
>>> - if (!block) {
>>> + if (!block || !ram_ptr) {
>>> fprintf(stderr, "Ack, bad migration stream!\n");
>>> return NULL;
>>> }
>>>
>>> - return memory_region_get_ram_ptr(block->mr) + offset;
>>> + return ram_ptr + offset;
>>> }
>>>
>>> len = qemu_get_byte(f);
>>> @@ -1007,8 +1014,10 @@ static inline void *host_from_stream_offset(QEMUFile *f,
>>> id[len] = 0;
>>>
>>> QTAILQ_FOREACH(block, &ram_list.blocks, next) {
>>> - if (!strncmp(id, block->idstr, sizeof(id)))
>>> - return memory_region_get_ram_ptr(block->mr) + offset;
>>> + if (!strncmp(id, block->idstr, sizeof(id))) {
>>> + ram_ptr = memory_region_get_ram_ptr(block->mr);
>>> + return ram_ptr + offset;
>>> + }
>>> }
>>>
>>> fprintf(stderr, "Can't find block %s!\n", id);
>>>
next prev parent reply other threads:[~2014-05-10 16:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-10 10:51 [Qemu-devel] [PATCH] migration: cache memory region ram ptr Peter Lieven
2014-05-10 11:38 ` 陈梁
2014-05-10 13:13 ` Peter Lieven
2014-05-10 15:33 ` Paolo Bonzini
2014-05-10 16:07 ` Peter Lieven
2014-05-10 16:32 ` Peter Lieven
2014-05-10 16:44 ` Peter Lieven [this message]
2014-05-12 6:09 ` Paolo Bonzini
2014-05-12 8:16 ` Peter Lieven
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=536E5763.6070006@kamp.de \
--to=pl@kamp.de \
--cc=dgilbert@redhat.com \
--cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.