Lines Matching +full:l2 +full:- +full:cache
2 * QEMU Enhanced Disk Format L2 Cache
10 * See the COPYING.LIB file in the top-level directory.
15 * L2 table cache usage is as follows:
17 * An open image has one L2 table cache that is used to avoid accessing the
18 * image file for recently referenced L2 tables.
22 * the L1 and L2 tables which store cluster offsets. It is here where the L2
23 * table cache serves up recently referenced L2 tables.
25 * If there is a cache miss, that L2 table is read from the image file and
26 * committed to the cache. Subsequent accesses to that L2 table will be served
27 * from the cache until the table is evicted from the cache.
29 * L2 tables are also committed to the cache when new L2 tables are allocated
30 * in the image file. Since the L2 table cache is write-through, the new L2
32 * cache.
34 * Multiple I/O requests may be using an L2 table cache entry at any given
37 * particular, an entry evicted from the cache will only be freed once all
40 * An in-flight I/O request will hold a reference to a L2 table cache entry for
41 * the period during which it needs to access the L2 table. This includes
42 * cluster offset lookup, L2 table allocation, and L2 table update when a new
45 * An interesting case occurs when two requests need to access an L2 table that
46 * is not in the cache. Since the operation to read the table from the image
47 * file takes some time to complete, both requests may see a cache miss and
48 * start reading the L2 table from the image file. The first to finish will
49 * commit its L2 table into the cache. When the second tries to commit its
50 * table will be deleted in favor of the existing cache entry.
58 /* Each L2 holds 2GB so this let's us fully cache a 100GB disk */
62 * Initialize the L2 cache
66 QTAILQ_INIT(&l2_cache->entries); in qed_init_l2_cache()
67 l2_cache->n_entries = 0; in qed_init_l2_cache()
71 * Free the L2 cache
77 QTAILQ_FOREACH_SAFE(entry, &l2_cache->entries, node, next_entry) { in qed_free_l2_cache()
78 qemu_vfree(entry->table); in qed_free_l2_cache()
84 * Allocate an uninitialized entry from the cache
95 entry->ref++; in qed_alloc_l2_cache_entry()
114 entry->ref--; in qed_unref_l2_cache_entry()
115 trace_qed_unref_l2_cache_entry(entry, entry->ref); in qed_unref_l2_cache_entry()
116 if (entry->ref == 0) { in qed_unref_l2_cache_entry()
117 qemu_vfree(entry->table); in qed_unref_l2_cache_entry()
123 * Find an entry in the L2 cache. This may return NULL and it's up to the
124 * caller to satisfy the cache miss.
135 QTAILQ_FOREACH(entry, &l2_cache->entries, node) { in qed_find_l2_cache_entry()
136 if (entry->offset == offset) { in qed_find_l2_cache_entry()
137 trace_qed_find_l2_cache_entry(l2_cache, entry, offset, entry->ref); in qed_find_l2_cache_entry()
138 entry->ref++; in qed_find_l2_cache_entry()
146 * Commit an L2 cache entry into the cache. This is meant to be used as part of
147 * the process to satisfy a cache miss. A caller would allocate an entry which
148 * is not actually in the L2 cache and then once the entry was valid and
149 * present on disk, the entry can be committed into the cache.
151 * Since the cache is write-through, it's important that this function is not
165 entry = qed_find_l2_cache_entry(l2_cache, l2_table->offset); in qed_commit_l2_cache_entry()
172 /* Evict an unused cache entry so we have space. If all entries are in use in qed_commit_l2_cache_entry()
173 * we can grow the cache temporarily and we try to shrink back down later. in qed_commit_l2_cache_entry()
175 if (l2_cache->n_entries >= MAX_L2_CACHE_SIZE) { in qed_commit_l2_cache_entry()
177 QTAILQ_FOREACH_SAFE(entry, &l2_cache->entries, node, next) { in qed_commit_l2_cache_entry()
178 if (entry->ref > 1) { in qed_commit_l2_cache_entry()
182 QTAILQ_REMOVE(&l2_cache->entries, entry, node); in qed_commit_l2_cache_entry()
183 l2_cache->n_entries--; in qed_commit_l2_cache_entry()
187 if (l2_cache->n_entries < MAX_L2_CACHE_SIZE) { in qed_commit_l2_cache_entry()
193 l2_cache->n_entries++; in qed_commit_l2_cache_entry()
194 QTAILQ_INSERT_TAIL(&l2_cache->entries, l2_table, node); in qed_commit_l2_cache_entry()