[Devel] [RFC PATCH vz9 v4 20/33] dm-ploop: reduce BAT accesses on discard completion

Alexander Atanasov alexander.atanasov at virtuozzo.com
Mon Nov 4 13:59:15 MSK 2024


From: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

Drop extra ploop_cluster_is_in_top_delta() as we are planning to
access BAT anyway

https://virtuozzo.atlassian.net/browse/VSTOR-91817
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index fa0c67e0b3d9..b7f186e2ec72 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -714,12 +714,15 @@ static void ploop_complete_cow(struct ploop_cow *cow, blk_status_t bi_status)
 	kmem_cache_free(cow_cache, cow);
 }
 
-static void ploop_release_cluster(struct ploop *ploop, u32 clu)
+static void ploop_piwb_discard_completed(struct ploop *ploop,
+					 bool success, u32 clu, u32 new_dst_clu)
 {
 	u32 id, *bat_entries, dst_clu;
 	struct md_page *md;
+	u8 level;
 
-	lockdep_assert_held(&ploop->bat_rwlock);
+	if (new_dst_clu)
+		return;
 
 	id = ploop_bat_clu_to_page_nr(clu);
 	md = ploop_md_page_find(ploop, id);
@@ -729,22 +732,15 @@ static void ploop_release_cluster(struct ploop *ploop, u32 clu)
 
 	bat_entries = md->kmpage;
 	dst_clu = READ_ONCE(bat_entries[clu]);
-	WRITE_ONCE(bat_entries[clu], BAT_ENTRY_NONE);
-	WRITE_ONCE(md->bat_levels[clu], 0);
-
-	ploop_hole_set_bit(dst_clu, ploop);
-}
-
-static void ploop_piwb_discard_completed(struct ploop *ploop,
-					 bool success, u32 clu, u32 new_dst_clu)
-{
-	if (new_dst_clu)
-		return;
+	level = md->bat_levels[clu];
 
-	if (ploop_cluster_is_in_top_delta(ploop, clu)) {
+	if (!(dst_clu == BAT_ENTRY_NONE || level < ploop_top_level(ploop))) {
 		WARN_ON_ONCE(ploop->nr_deltas != 1);
-		if (success)
-			ploop_release_cluster(ploop, clu);
+		if (success) {
+			WRITE_ONCE(bat_entries[clu], BAT_ENTRY_NONE);
+			WRITE_ONCE(md->bat_levels[clu], 0);
+			ploop_hole_set_bit(dst_clu, ploop);
+		}
 	}
 }
 
-- 
2.43.0



More information about the Devel mailing list