[Devel] [PATCH vz9 v1 18/63] dm-ploop: simplify llseek

Alexander Atanasov alexander.atanasov at virtuozzo.com
Fri Jan 24 18:35:52 MSK 2025


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

Do not bother with locked clusters. For llseek we can ignore all
concurrent operations.
Do not call ploop_bat_entries() on every cluster as this is slow.
Just remember md and read it directly.

Return EINVAL if it fails to find md page.

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

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 119ef21323f8..90290221341b 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -2080,32 +2080,23 @@ ALLOW_ERROR_INJECTION(ploop_prepare_reloc_index_wb, ERRNO);
 loff_t ploop_llseek_hole(struct dm_target *ti, loff_t offset, int whence)
 {
 	struct ploop *ploop = ti->private;
-	u32 clu, dst_clu;
+	u32 clu, dst_clu, id, *bat;
+	struct md_page *md;
 	loff_t result;
 
 	clu = SEC_TO_CLU(ploop, to_sector(offset) + ploop->skip_off);
+	id = U32_MAX;
 
 	while (clu < ploop->nr_bat_entries) {
-
-		/*
-		 * Assume a locked cluster to have a data.
-		 * In worst case someone will read zeroes
-		 */
-		if (ploop_postpone_if_cluster_locked(ploop, NULL, clu)) {
-			if (whence & SEEK_DATA)
-				break;
-			if (whence & SEEK_HOLE) {
-				clu++;
-				continue;
-			}
+		if (id != ploop_bat_clu_to_page_nr(clu)) {
+			id = ploop_bat_clu_to_page_nr(clu);
+			md = ploop_md_page_find(ploop, id);
+			if (!md)
+				return -EINVAL;
 		}
 
-		/*
-		 * It *may* be possible to speed this up by iterating over clusters
-		 * in mapped metadata page, but this is a bit problematic
-		 * since we want to check if cluster is locked
-		 */
-		dst_clu = ploop_bat_entries(ploop, clu, NULL, NULL);
+		bat = md->kmpage;
+		dst_clu = READ_ONCE(bat[ploop_bat_clu_idx_in_page(clu)]);
 
 		if (whence & SEEK_DATA && dst_clu != BAT_ENTRY_NONE)
 			break;
-- 
2.43.0



More information about the Devel mailing list