Skip to content

Commit f484697

Browse files
mingnusMikulas Patocka
authored andcommitted
dm cache: optimize dirty bit checking with find_next_bit when resizing
When shrinking the fast device, dm-cache iteratively searches for a dirty bit among the cache blocks to be dropped, which is less efficient. Use find_next_bit instead, as it is twice as fast as the iterative approach with test_bit. Signed-off-by: Ming-Hung Tsai <[email protected]> Fixes: f494a9c ("dm cache: cache shrinking support") Cc: [email protected] Signed-off-by: Mikulas Patocka <[email protected]> Acked-by: Joe Thornber <[email protected]>
1 parent 7922277 commit f484697

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/md/dm-cache-target.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,14 +2911,14 @@ static bool can_resize(struct cache *cache, dm_cblock_t new_size)
29112911
/*
29122912
* We can't drop a dirty block when shrinking the cache.
29132913
*/
2914-
while (from_cblock(new_size) < from_cblock(cache->cache_size)) {
2915-
if (is_dirty(cache, new_size)) {
2916-
DMERR("%s: unable to shrink cache; cache block %llu is dirty",
2917-
cache_device_name(cache),
2918-
(unsigned long long) from_cblock(new_size));
2919-
return false;
2920-
}
2921-
new_size = to_cblock(from_cblock(new_size) + 1);
2914+
new_size = to_cblock(find_next_bit(cache->dirty_bitset,
2915+
from_cblock(cache->cache_size),
2916+
from_cblock(new_size)));
2917+
if (new_size != cache->cache_size) {
2918+
DMERR("%s: unable to shrink cache; cache block %llu is dirty",
2919+
cache_device_name(cache),
2920+
(unsigned long long) from_cblock(new_size));
2921+
return false;
29222922
}
29232923

29242924
return true;

0 commit comments

Comments
 (0)