Message ID | 536E5495.6080401@kamp.de |
---|---|
State | New |
Headers | show |
Il 10/05/2014 18:32, Peter Lieven ha scritto: > What about XEN? > You're right, Xen wouldn't work. Your original patch would not break it just because Xen doesn't use migration (but the code would be broken). You would have to cache qemu_get_ram_block rather than qemu_get_ram_ptr, move RAMBlock to memory-internal.h, and split the RAMBlock + ram_addr_t => void * conversion out of qemu_get_ram_ptr and into a separate function (to be used by memory_region_get_ram_ptr). I'm not sure of the benefit of your patch though. qemu_get_ram_block already has a 1-item cache, are you seeing a low hit rate there? Or any other profiling that shows qemu_get_ram_ptr as hot? Paolo
Am 12.05.2014 08:09, schrieb Paolo Bonzini: > Il 10/05/2014 18:32, Peter Lieven ha scritto: >> What about XEN? >> > > You're right, Xen wouldn't work. Your original patch would not break it just because Xen doesn't use migration (but the code would be broken). > > You would have to cache qemu_get_ram_block rather than qemu_get_ram_ptr, move RAMBlock to memory-internal.h, and split the RAMBlock + ram_addr_t => void * conversion out of qemu_get_ram_ptr and into a separate function (to be used by memory_region_get_ram_ptr). > > I'm not sure of the benefit of your patch though. qemu_get_ram_block already has a 1-item cache, are you seeing a low hit rate there? Or any other profiling that shows qemu_get_ram_ptr as hot? qemu_get_ram_ptr is hot only during migration. But the hit-rate of the LRU cache seems to be good. I am wondering if this is different if the migration has difficulties to converge, but you might be right it should be neglectible. I ran some basic migration tests with and without the patch. It might be that the results with the cache are slightly better, but the variance of the results is high. I had to run a significant number of tests to get more evidence. Peter > > Paolo
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)