[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 08/22] qcow2: remove qcow2_cache_find_entry_to_replac
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 08/22] qcow2: remove qcow2_cache_find_entry_to_replace() |
Date: |
Fri, 22 May 2015 17:26:26 +0200 |
From: Alberto Garcia <address@hidden>
A cache miss means that the whole array was traversed and the entry
we were looking for was not found, so there's no need to traverse it
again in order to select an entry to replace.
Signed-off-by: Alberto Garcia <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cache.c | 45 ++++++++++++++++-----------------------------
1 file changed, 16 insertions(+), 29 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 3a31895..2035cd8 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -242,51 +242,38 @@ int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c)
return 0;
}
-static int qcow2_cache_find_entry_to_replace(Qcow2Cache *c)
-{
- int i;
- uint64_t min_lru_counter = UINT64_MAX;
- int min_index = -1;
-
-
- for (i = 0; i < c->size; i++) {
- if (c->entries[i].ref) {
- continue;
- }
-
- if (c->entries[i].lru_counter < min_lru_counter) {
- min_index = i;
- min_lru_counter = c->entries[i].lru_counter;
- }
- }
-
- if (min_index == -1) {
- /* This can't happen in current synchronous code, but leave the check
- * here as a reminder for whoever starts using AIO with the cache */
- abort();
- }
- return min_index;
-}
-
static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
uint64_t offset, void **table, bool read_from_disk)
{
BDRVQcowState *s = bs->opaque;
int i;
int ret;
+ uint64_t min_lru_counter = UINT64_MAX;
+ int min_lru_index = -1;
trace_qcow2_cache_get(qemu_coroutine_self(), c == s->l2_table_cache,
offset, read_from_disk);
/* Check if the table is already cached */
for (i = 0; i < c->size; i++) {
- if (c->entries[i].offset == offset) {
+ const Qcow2CachedTable *t = &c->entries[i];
+ if (t->offset == offset) {
goto found;
}
+ if (t->ref == 0 && t->lru_counter < min_lru_counter) {
+ min_lru_counter = t->lru_counter;
+ min_lru_index = i;
+ }
+ }
+
+ if (min_lru_index == -1) {
+ /* This can't happen in current synchronous code, but leave the check
+ * here as a reminder for whoever starts using AIO with the cache */
+ abort();
}
- /* If not, write a table back and replace it */
- i = qcow2_cache_find_entry_to_replace(c);
+ /* Cache miss: write a table back and replace it */
+ i = min_lru_index;
trace_qcow2_cache_get_replace_entry(qemu_coroutine_self(),
c == s->l2_table_cache, i);
if (i < 0) {
--
1.8.3.1
- [Qemu-block] [PULL 00/22] Block layer core and image format patches, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 03/22] vmdk: Fix next_cluster_sector for compressed write, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 02/22] nvme: support NVME_VOLATILE_WRITE_CACHE feature, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 04/22] vmdk: Fix overflow if l1_size is 0x20000000, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 01/22] qcow2: Flush pending discards before allocating cluster, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 05/22] qcow2: use one single memory block for the L2/refcount cache tables, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 06/22] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty(), Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 07/22] qcow2: use an LRU algorithm to replace entries from the L2 cache, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 09/22] qcow2: use a hash to look for entries in the L2 cache, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 08/22] qcow2: remove qcow2_cache_find_entry_to_replace(),
Kevin Wolf <=
- [Qemu-block] [PULL 10/22] qcow2: make qcow2_cache_put() a void function, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 11/22] qcow2: style fixes in qcow2-cache.c, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 13/22] block: Detect multiplication overflow in bdrv_getlength, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 12/22] qemu-io: Use getopt() correctly, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 14/22] qemu-iotests: qemu-img info on afl VMDK image with a huge capacity, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 18/22] util: allow \n to terminate password input, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 16/22] qcow2/qcow: protect against uninitialized encryption key, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 17/22] util: move read_password method out of qemu-img into osdep/oslib, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 20/22] tests: add test case for encrypted qcow2 read/write, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 15/22] qemu-iotests: Make debugging python tests easier, Kevin Wolf, 2015/05/22