[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 09/18] block/pcache: skip readahead for unallocat
From: |
Pavel Butsykin |
Subject: |
[Qemu-block] [PATCH v2 09/18] block/pcache: skip readahead for unallocated clusters |
Date: |
Fri, 30 Dec 2016 17:31:33 +0300 |
Typically, data for unallocated clusters is filled with zeros, so it makes no
sense to store it in the cache.
Signed-off-by: Pavel Butsykin <address@hidden>
---
block/pcache.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/block/pcache.c b/block/pcache.c
index 57eebd434a..f30e9e7bfe 100644
--- a/block/pcache.c
+++ b/block/pcache.c
@@ -174,6 +174,28 @@ static RBCacheNode *pcache_node_alloc(uint64_t offset,
uint64_t bytes,
return &node->common;
}
+static bool check_allocated_clusters(BlockDriverState *bs, uint64_t offset,
+ uint64_t bytes)
+{
+ int64_t sector_num = offset >> BDRV_SECTOR_BITS;
+ int32_t nb_sectors = bytes >> BDRV_SECTOR_BITS;
+
+ assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
+ assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
+
+ do {
+ int num, ret = bdrv_is_allocated(bs, sector_num, nb_sectors, &num);
+ if (ret <= 0) {
+ return false;
+ }
+ sector_num += num;
+ nb_sectors -= num;
+
+ } while (nb_sectors);
+
+ return true;
+}
+
#define PCACHE_STEPS_FORWARD 2
static PCacheNode *get_readahead_node(BlockDriverState *bs, RBCache *rbcache,
@@ -193,6 +215,10 @@ static PCacheNode *get_readahead_node(BlockDriverState
*bs, RBCache *rbcache,
break;
}
+ if (!check_allocated_clusters(bs, offset, bytes)) {
+ break;
+ }
+
node = rbcache_search_and_insert(rbcache, offset, bytes);
if (node->status == NODE_STATUS_NEW) {
return node;
--
2.11.0
- [Qemu-block] [PATCH v2 03/18] util/rbcache: range-based cache core, (continued)
- [Qemu-block] [PATCH v2 03/18] util/rbcache: range-based cache core, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 08/18] block/pcache: add AIO readahead, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 07/18] block/pcache: updating statistics for overlapping requests, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 14/18] block/pcache: up-to-date cache for removed nodes, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 17/18] qapi: allow blockdev-add for pcache, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 05/18] block/pcache: statistics collection read requests, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 10/18] block/pcache: cache invalidation on write requests, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 06/18] block/pcache: skip large aio read, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 04/18] tests/test-rbcache: add test cases, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 01/18] block/pcache: empty pcache driver filter, Pavel Butsykin, 2016/12/30
- [Qemu-block] [PATCH v2 09/18] block/pcache: skip readahead for unallocated clusters,
Pavel Butsykin <=
- [Qemu-block] [PATCH v2 13/18] block/pcache: write through, Pavel Butsykin, 2016/12/30