[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cac
From: |
Alberto Garcia |
Subject: |
[Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty() |
Date: |
Thu, 30 Apr 2015 13:11:41 +0300 |
Since all tables are now stored together, it is possible to obtain
the position of a particular table directly from its address, so the
operation becomes O(1).
Signed-off-by: Alberto Garcia <address@hidden>
---
block/qcow2-cache.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 586880b..d3274f4 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -335,16 +335,12 @@ int qcow2_cache_get_empty(BlockDriverState *bs,
Qcow2Cache *c, uint64_t offset,
int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table)
{
- int i;
+ int i = (*table - c->table_array) / c->table_size;
- for (i = 0; i < c->size; i++) {
- if (table_addr(c, i) == *table) {
- goto found;
- }
+ if (c->entries[i].offset == 0) {
+ return -ENOENT;
}
- return -ENOENT;
-found:
c->entries[i].ref--;
*table = NULL;
@@ -354,15 +350,7 @@ found:
void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table)
{
- int i;
-
- for (i = 0; i < c->size; i++) {
- if (table_addr(c, i) == table) {
- goto found;
- }
- }
- abort();
-
-found:
+ int i = (table - c->table_array) / c->table_size;
+ assert(c->entries[i].offset != 0);
c->entries[i].dirty = true;
}
--
2.1.4
- [Qemu-devel] [PATCH 0/6] qcow2 L2/refcount cache improvements, Alberto Garcia, 2015/04/30
- [Qemu-devel] [PATCH 6/6] qcow2: style fixes in qcow2-cache.c, Alberto Garcia, 2015/04/30
- [Qemu-devel] [PATCH 5/6] qcow2: use a hash to look for entries in the L2 cache, Alberto Garcia, 2015/04/30
- [Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty(),
Alberto Garcia <=
- [Qemu-devel] [PATCH 4/6] qcow2: remove qcow2_cache_find_entry_to_replace(), Alberto Garcia, 2015/04/30
- [Qemu-devel] [PATCH 1/6] qcow2: use one single memory block for the L2/refcount cache tables, Alberto Garcia, 2015/04/30
- [Qemu-devel] [PATCH 3/6] qcow2: use an LRU algorithm to replace entries from the L2 cache, Alberto Garcia, 2015/04/30