提交 0d6d3c87 编写于 作者: P Paolo Bonzini 提交者: Juan Quintela

exec: change ramlist from MRU order to a 1-item cache

Most of the time, only 2 items will be active (from/to for a string operation,
or code/data).  But TCG guests likely won't have gigabytes of memory, so
this actually goes down to 1 item.
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NJuan Quintela <quintela@redhat.com>
上级 803ef032
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "qemu/config-file.h" #include "qemu/config-file.h"
#include "qmp-commands.h" #include "qmp-commands.h"
#include "trace.h" #include "trace.h"
#include "exec/cpu-all.h"
#ifdef DEBUG_ARCH_INIT #ifdef DEBUG_ARCH_INIT
#define DPRINTF(fmt, ...) \ #define DPRINTF(fmt, ...) \
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "sysemu/xen-mapcache.h" #include "sysemu/xen-mapcache.h"
#include "trace.h" #include "trace.h"
#endif #endif
#include "exec/cpu-all.h"
#include "exec/cputlb.h" #include "exec/cputlb.h"
#include "translate-all.h" #include "translate-all.h"
...@@ -1043,6 +1044,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, ...@@ -1043,6 +1044,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
new_block->length = size; new_block->length = size;
QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next); QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
ram_list.mru_block = NULL;
ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
last_ram_offset() >> TARGET_PAGE_BITS); last_ram_offset() >> TARGET_PAGE_BITS);
...@@ -1071,6 +1073,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr) ...@@ -1071,6 +1073,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr)
QLIST_FOREACH(block, &ram_list.blocks, next) { QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr == block->offset) { if (addr == block->offset) {
QLIST_REMOVE(block, next); QLIST_REMOVE(block, next);
ram_list.mru_block = NULL;
g_free(block); g_free(block);
return; return;
} }
...@@ -1084,6 +1087,7 @@ void qemu_ram_free(ram_addr_t addr) ...@@ -1084,6 +1087,7 @@ void qemu_ram_free(ram_addr_t addr)
QLIST_FOREACH(block, &ram_list.blocks, next) { QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr == block->offset) { if (addr == block->offset) {
QLIST_REMOVE(block, next); QLIST_REMOVE(block, next);
ram_list.mru_block = NULL;
if (block->flags & RAM_PREALLOC_MASK) { if (block->flags & RAM_PREALLOC_MASK) {
; ;
} else if (mem_path) { } else if (mem_path) {
...@@ -1189,37 +1193,40 @@ void *qemu_get_ram_ptr(ram_addr_t addr) ...@@ -1189,37 +1193,40 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
{ {
RAMBlock *block; RAMBlock *block;
block = ram_list.mru_block;
if (block && addr - block->offset < block->length) {
goto found;
}
QLIST_FOREACH(block, &ram_list.blocks, next) { QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr - block->offset < block->length) { if (addr - block->offset < block->length) {
/* Move this entry to to start of the list. */ goto found;
if (block != QLIST_FIRST(&ram_list.blocks)) {
QLIST_REMOVE(block, next);
QLIST_INSERT_HEAD(&ram_list.blocks, block, next);
}
if (xen_enabled()) {
/* We need to check if the requested address is in the RAM
* because we don't want to map the entire memory in QEMU.
* In that case just map until the end of the page.
*/
if (block->offset == 0) {
return xen_map_cache(addr, 0, 0);
} else if (block->host == NULL) {
block->host =
xen_map_cache(block->offset, block->length, 1);
}
}
return block->host + (addr - block->offset);
} }
} }
fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr); fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr);
abort(); abort();
return NULL; found:
ram_list.mru_block = block;
if (xen_enabled()) {
/* We need to check if the requested address is in the RAM
* because we don't want to map the entire memory in QEMU.
* In that case just map until the end of the page.
*/
if (block->offset == 0) {
return xen_map_cache(addr, 0, 0);
} else if (block->host == NULL) {
block->host =
xen_map_cache(block->offset, block->length, 1);
}
}
return block->host + (addr - block->offset);
} }
/* Return a host pointer to ram allocated with qemu_ram_alloc. /* Return a host pointer to ram allocated with qemu_ram_alloc. Same as
* Same as qemu_get_ram_ptr but avoid reordering ramblocks. * qemu_get_ram_ptr but do not touch ram_list.mru_block.
*
* ??? Is this still necessary?
*/ */
static void *qemu_safe_ram_ptr(ram_addr_t addr) static void *qemu_safe_ram_ptr(ram_addr_t addr)
{ {
......
...@@ -495,6 +495,7 @@ typedef struct RAMBlock { ...@@ -495,6 +495,7 @@ typedef struct RAMBlock {
typedef struct RAMList { typedef struct RAMList {
uint8_t *phys_dirty; uint8_t *phys_dirty;
RAMBlock *mru_block;
QLIST_HEAD(, RAMBlock) blocks; QLIST_HEAD(, RAMBlock) blocks;
} RAMList; } RAMList;
extern RAMList ram_list; extern RAMList ram_list;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册