From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7926213144; Tue, 12 Nov 2024 10:44:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731408289; cv=none; b=tIy1nT2R5ChuChPNIjel3Otd7iwUiQ6LW0+6pNeSnA5VN0kKX5d6zQLAtC7A6vSOCPd9OSQiOH/sm6L0q4iyGfnvZGABM1sUTdbGZjaUG6TvpyrbedUvJH+vQUeW7xRKoQcOZquLzYuvneXxaolMoLqx4D+YjC4DMhGB4VXUnYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731408289; c=relaxed/simple; bh=XWN+8NVCJEFahfzlBXt3ujDiOxvmkywTaW2612OHvNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DoYDNcxwI873ezNJC+om69uVLcJzIKxy2H44cGh6P1Pf9RbR5HXmmF1CaUgMTaIybE2pcc7TQuhDCWJKi9FKXHh/EZ6oXLXoAVjZUwl4PnqbTjJaT4h5vwRUfSjYD1ZGEclhUgS0aaS36e3a0pwFskz+vy8j/77BIOji8K7Ejmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CSGMQLfJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CSGMQLfJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10357C4CECD; Tue, 12 Nov 2024 10:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731408289; bh=XWN+8NVCJEFahfzlBXt3ujDiOxvmkywTaW2612OHvNw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CSGMQLfJL6M7y/4F98ayXaX4akE0ycMN3lVlCls1Sqk+bcUs89sEkRaV6Ribz9krr UgMkYejH2GiHNLWiypVL4TsUzDiXTEcu0Gk/2yslXKS3Pjq7td1JOBk1Z5s7jNwgOt /JkhHW3/xUMYPXEBRTSw0DZokXdd45J/xBXBFOhc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ming-Hung Tsai , Mikulas Patocka , Joe Thornber Subject: [PATCH 6.11 117/184] dm cache: optimize dirty bit checking with find_next_bit when resizing Date: Tue, 12 Nov 2024 11:21:15 +0100 Message-ID: <20241112101905.359232004@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241112101900.865487674@linuxfoundation.org> References: <20241112101900.865487674@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.11-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ming-Hung Tsai 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: Ming-Hung Tsai Fixes: f494a9c6b1b6 ("dm cache: cache shrinking support") Cc: stable@vger.kernel.org Signed-off-by: Mikulas Patocka Acked-by: Joe Thornber Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-cache-target.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/drivers/md/dm-cache-target.c +++ b/drivers/md/dm-cache-target.c @@ -2911,14 +2911,14 @@ static bool can_resize(struct cache *cac /* * 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)) { - 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); + 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; } return true;