[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH RFC 22/22] block/pcache: drop used pcache node
From: |
Pavel Butsykin |
Subject: |
[Qemu-block] [PATCH RFC 22/22] block/pcache: drop used pcache node |
Date: |
Thu, 25 Aug 2016 16:44:21 +0300 |
The pcache is directed to certain situations to sequential reads.
This concept allows to drop parts of the cache that were already used, which
will reduce the size of cache and the number of displaced nodes.
Signed-off-by: Pavel Butsykin <address@hidden>
---
block/pcache.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/block/pcache.c b/block/pcache.c
index 2b2edf5..3fad4ca 100644
--- a/block/pcache.c
+++ b/block/pcache.c
@@ -88,6 +88,7 @@ typedef struct PCNode {
uint32_t status;
uint32_t ref;
uint8_t *data;
+ uint32_t rdcnt;
CoMutex lock;
} PCNode;
@@ -342,6 +343,7 @@ static inline void *pcache_node_alloc(RbNodeKey* key)
node->cm.nb_sectors = key->size;
node->ref = 0;
node->status = NODE_WAIT_STATUS;
+ node->rdcnt = 0;
qemu_co_mutex_init(&node->lock);
node->data = g_malloc(node->cm.nb_sectors << BDRV_SECTOR_BITS);
node->wait.cnt = 0;
@@ -560,11 +562,23 @@ static void pcache_node_rw_buf(PrefCacheAIOCB *acb,
PCNode* node, uint32_t type)
node->cm.sector_num, node->cm.nb_sectors)
<< BDRV_SECTOR_BITS;
- qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */
- copy = type & NODE_READ_BUF ?
- qemu_iovec_from_buf(acb->qiov, qiov_offs, node->data + node_offs, size)
- : qemu_iovec_to_buf(acb->qiov, qiov_offs, node->data + node_offs,
size);
- qemu_co_mutex_unlock(&node->lock);
+ if (type & NODE_READ_BUF) {
+ qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */
+ copy = qemu_iovec_from_buf(acb->qiov, qiov_offs,
+ node->data + node_offs, size);
+ qemu_co_mutex_unlock(&node->lock);
+
+ /* pcache node is no longer needed, when it was all read */
+ atomic_add(&node->rdcnt, size >> BDRV_SECTOR_BITS);
+ if (node->rdcnt >= node->cm.nb_sectors) {
+ pcache_node_drop(acb->s, node);
+ }
+ } else {
+ qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */
+ copy = qemu_iovec_to_buf(acb->qiov, qiov_offs,
+ node->data + node_offs, size);
+ qemu_co_mutex_unlock(&node->lock);
+ }
assert(copy == size);
}
--
2.8.3
- [Qemu-block] [PATCH RFC 00/22] I/O prefetch cache, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 01/22] block/pcache: empty pcache driver filter, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 04/22] block/pcache: add pcache debug build, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 02/22] block/pcache: add own AIOCB block, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 07/22] block/pcache: introduce LRU as method of memory, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 10/22] block/pcache: add check node leak, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 08/22] block/pcache: implement pickup parts of the cache, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 11/22] add QEMU style defines for __sync_add_and_fetch, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 12/22] block/pcache: implement read cache to qiov and drop node during aio write, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 15/22] block/pcache: simple readahead one chunk forward, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 22/22] block/pcache: drop used pcache node,
Pavel Butsykin <=
- [Qemu-block] [PATCH RFC 17/22] block/pcache: skip readahead for non-sequential requests, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 16/22] block/pcache: pcache readahead node around, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 20/22] block/pcache: implement pcache error handling of aio cb, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 21/22] block/pcache: add write through node, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 05/22] block/pcache: add aio requests into cache, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 03/22] util/rbtree: add rbtree from linux kernel, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 18/22] block/pcache: add pcache skip large aio read, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 14/22] block/pcache: add support for rescheduling requests, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 13/22] block/pcache: add generic request complete, Pavel Butsykin, 2016/08/25
- [Qemu-block] [PATCH RFC 19/22] block/pcache: add pcache node assert, Pavel Butsykin, 2016/08/25