diff --git a/include/qemu/lru.h b/include/qemu/lru.h index 2a1b02ed23..cc20a7c551 100644 --- a/include/qemu/lru.h +++ b/include/qemu/lru.h @@ -149,11 +149,7 @@ LruNode *lru_try_evict_one(Lru *lru) static inline LruNode *lru_evict_one(Lru *lru) { - LruNode *found = lru_try_evict_one(lru); - - assert(found != NULL); /* No evictable node! */ - - return found; + return lru_try_evict_one(lru); } static inline @@ -199,9 +195,19 @@ LruNode *lru_lookup(Lru *lru, uint64_t hash, const void *key) } if (found) { - QTAILQ_REMOVE(&lru->bins[bin], found, next_bin); + if (QTAILQ_FIRST(&lru->bins[bin]) != found) { + QTAILQ_REMOVE(&lru->bins[bin], found, next_bin); + QTAILQ_INSERT_HEAD(&lru->bins[bin], found, next_bin); + } + if (QTAILQ_FIRST(&lru->global) != found) { + QTAILQ_REMOVE(&lru->global, found, next_global); + QTAILQ_INSERT_HEAD(&lru->global, found, next_global); + } } else { found = lru_get_one_free(lru); + if (!found) { + return NULL; + } found->hash = hash; if (lru->init_node) { lru->init_node(lru, found, key); @@ -210,11 +216,11 @@ LruNode *lru_lookup(Lru *lru, uint64_t hash, const void *key) lru->num_used += 1; lru->num_free -= 1; - } - QTAILQ_REMOVE(&lru->global, found, next_global); - QTAILQ_INSERT_HEAD(&lru->global, found, next_global); - QTAILQ_INSERT_HEAD(&lru->bins[bin], found, next_bin); + QTAILQ_REMOVE(&lru->global, found, next_global); + QTAILQ_INSERT_HEAD(&lru->global, found, next_global); + QTAILQ_INSERT_HEAD(&lru->bins[bin], found, next_bin); + } return found; } diff --git a/system/vl.c b/system/vl.c index f5505cb8fb..7fdfba29d7 100644 --- a/system/vl.c +++ b/system/vl.c @@ -3086,7 +3086,7 @@ void qemu_init(int argc, char **argv) char *escaped_hdd_path = strdup_double_commas(hdd_path); fake_argv[fake_argc++] = g_strdup_printf("index=0,media=disk,file=%s%s", escaped_hdd_path, - strlen(escaped_hdd_path) > 0 ? ",locked=on" : ""); + strlen(escaped_hdd_path) > 0 ? ",locked=on,cache=writethrough" : ""); free(escaped_hdd_path); } }