Commit 7861b072 authored by Ming-Hung Tsai's avatar Ming-Hung Tsai Committed by Zheng Qixing
Browse files

dm cache: optimize dirty bit checking with find_next_bit when resizing

stable inclusion
from stable-v4.19.324
commit c90c5e02556d2781b6506ab4b8dd7613d9008bcd
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IB5AV2
CVE: CVE-2024-50278

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c90c5e02556d2781b6506ab4b8dd7613d9008bcd



--------------------------------

commit f484697e619a83ecc370443a34746379ad99d204 upstream.

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: default avatarMing-Hung Tsai <mtsai@redhat.com>
Fixes: f494a9c6 ("dm cache: cache shrinking support")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Acked-by: default avatarJoe Thornber <thornber@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarZheng Qixing <zhengqixing@huawei.com>
parent 3f54cfbc
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -2996,15 +2996,15 @@ static bool can_resize(struct cache *cache, dm_cblock_t new_size)
	/*
	 * We can't drop a dirty block when shrinking the cache.
	 */
	while (from_cblock(new_size) < from_cblock(cache->cache_size)) {
		if (is_dirty(cache, new_size)) {
	new_size = to_cblock(find_next_bit(cache->dirty_bitset,
					   from_cblock(cache->cache_size),
					   from_cblock(new_size)));
	if (new_size != cache->cache_size) {
		DMERR("%s: unable to shrink cache; cache block %llu is dirty",
		      cache_device_name(cache),
		      (unsigned long long) from_cblock(new_size));
		return false;
	}
		new_size = to_cblock(from_cblock(new_size) + 1);
	}

	return true;
}