[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 06/34] exec: change ramlist from MRU order to a 1-it
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PATCH 06/34] exec: change ramlist from MRU order to a 1-item cache |
Date: |
Wed, 19 Dec 2012 13:33:29 +0100 |
From: Paolo Bonzini <address@hidden>
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: Paolo Bonzini <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
arch_init.c | 1 +
cpu-all.h | 1 +
exec.c | 49 ++++++++++++++++++++++++++++---------------------
3 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/arch_init.c b/arch_init.c
index 0d7844c..b03b1d4 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -48,6 +48,7 @@
#include "qemu/page_cache.h"
#include "qmp-commands.h"
#include "trace.h"
+#include "cpu-all.h"
#ifdef DEBUG_ARCH_INIT
#define DPRINTF(fmt, ...) \
diff --git a/cpu-all.h b/cpu-all.h
index d6b2b19..973b504 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -495,6 +495,7 @@ typedef struct RAMBlock {
typedef struct RAMList {
uint8_t *phys_dirty;
+ RAMBlock *mru_block;
QLIST_HEAD(, RAMBlock) blocks;
} RAMList;
extern RAMList ram_list;
diff --git a/exec.c b/exec.c
index 4c1246a..a3dbe2f 100644
--- a/exec.c
+++ b/exec.c
@@ -42,6 +42,7 @@
#include "xen-mapcache.h"
#include "trace.h"
#endif
+#include "cpu-all.h"
#include "cputlb.h"
#include "translate-all.h"
@@ -1042,6 +1043,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void
*host,
new_block->length = size;
QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next);
+ ram_list.mru_block = NULL;
ram_list.phys_dirty = g_realloc(ram_list.phys_dirty,
last_ram_offset() >> TARGET_PAGE_BITS);
@@ -1070,6 +1072,7 @@ void qemu_ram_free_from_ptr(ram_addr_t addr)
QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr == block->offset) {
QLIST_REMOVE(block, next);
+ ram_list.mru_block = NULL;
g_free(block);
return;
}
@@ -1083,6 +1086,7 @@ void qemu_ram_free(ram_addr_t addr)
QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr == block->offset) {
QLIST_REMOVE(block, next);
+ ram_list.mru_block = NULL;
if (block->flags & RAM_PREALLOC_MASK) {
;
} else if (mem_path) {
@@ -1188,37 +1192,40 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
{
RAMBlock *block;
+ block = ram_list.mru_block;
+ if (block && addr - block->offset < block->length) {
+ goto found;
+ }
QLIST_FOREACH(block, &ram_list.blocks, next) {
if (addr - block->offset < block->length) {
- /* Move this entry to to start of the list. */
- 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);
+ goto found;
}
}
fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr);
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.
- * Same as qemu_get_ram_ptr but avoid reordering ramblocks.
+/* Return a host pointer to ram allocated with qemu_ram_alloc. Same as
+ * 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)
{
--
1.7.11.7
- [Qemu-devel] [PATCH 00/34] migration thread and queue, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 01/34] migration: fix migration_bitmap leak, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 02/34] buffered_file: do not send more than s->bytes_xfer bytes per tick, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 03/34] migration: remove double call to migrate_fd_close, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 04/34] migration: include qemu-file.h, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 05/34] migration-fd: remove duplicate include, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 07/34] exec: change RAM list to a TAILQ, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 06/34] exec: change ramlist from MRU order to a 1-item cache,
Juan Quintela <=
- [Qemu-devel] [PATCH 09/34] add a version number to ram_list, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 08/34] exec: sort the memory from biggest to smallest, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 11/34] buffered_file: Move from using a timer to use a thread, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 10/34] protect the ramlist with a separate mutex, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 13/34] migration: move migration thread init code to migrate_fd_put_ready, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 16/34] migration: just lock migrate_fd_put_ready, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 15/34] migration: remove unfreeze logic, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 14/34] migration: make writes blocking, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 18/34] buffered_file: don't flush on put buffer, Juan Quintela, 2012/12/19
- [Qemu-devel] [PATCH 17/34] buffered_file: Unfold the trick to restart generating migration data, Juan Quintela, 2012/12/19