[Devel] [PATCH RHEL8 COMMIT] ploop: Always defer bios for work

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 17 19:04:37 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.30
------>
commit 8e22feaf12b11d34a1f6ee8a0f69f2ded748596d
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon May 17 19:04:37 2021 +0300

    ploop: Always defer bios for work
    
    This is preparations for killing loop. Since there won't be loop,
    we always need work to submit IO.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    dm-ploop: Kill loop
    
    Intermediate patches can't be base for bisect.
    
    In scope of https://jira.sw.ru/browse/PSBM-123654
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c | 13 ++-------
 drivers/md/dm-ploop-map.c | 67 ++++++++---------------------------------------
 drivers/md/dm-ploop.h     | 19 --------------
 3 files changed, 13 insertions(+), 86 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 139dffca1ce5..346f69056a11 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -231,7 +231,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 {
 	struct bio *bio = cmd->resize.bio;
 	unsigned int new_dst, cluster, dst_cluster;
-	bool is_locked, defer_bio_count = false;
+	bool is_locked;
 	int ret = 0;
 
 	dst_cluster = cmd->resize.dst_cluster;
@@ -254,9 +254,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 		goto not_occupied;
 	}
 
-	/* Redirect bios to kwork and wait inflights, which may use @cluster */
-	force_defer_bio_count_inc(ploop);
-	defer_bio_count = true;
+	/* Wait inflights, which may use @cluster */
 	ret = ploop_inflight_bios_ref_switch(ploop, true);
 	if (ret < 0)
 		goto out;
@@ -300,9 +298,6 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 	/* Zero new BAT entries on disk. */
 	ret = ploop_write_zero_cluster_sync(ploop, bio, dst_cluster);
 out:
-	if (defer_bio_count)
-		force_defer_bio_count_dec(ploop);
-
 	return ret;
 }
 
@@ -712,7 +707,6 @@ static void process_notify_delta_merged(struct ploop *ploop,
 	struct file *file;
 	int ret;
 
-	force_defer_bio_count_inc(ploop);
 	ret = ploop_inflight_bios_ref_switch(ploop, true);
 	if (ret) {
 		cmd->retval = ret;
@@ -761,7 +755,6 @@ static void process_notify_delta_merged(struct ploop *ploop,
 	fput(file);
 	cmd->retval = 0;
 out:
-	force_defer_bio_count_dec(ploop);
 	complete(&cmd->comp); /* Last touch of cmd memory */
 }
 
@@ -773,7 +766,6 @@ static void process_update_delta_index(struct ploop *ploop,
 	unsigned int cluster, dst_cluster, n;
 	int ret;
 
-	force_defer_bio_count_inc(ploop);
 	ret = ploop_inflight_bios_ref_switch(ploop, true);
 	if (ret)
 		goto out;
@@ -801,7 +793,6 @@ static void process_update_delta_index(struct ploop *ploop,
 unlock:
 	write_unlock_irq(&ploop->bat_rwlock);
 out:
-	force_defer_bio_count_dec(ploop);
 	cmd->retval = ret;
 	complete(&cmd->comp); /* Last touch of cmd memory */
 }
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 0b902a67f5de..dd209f2a0a8c 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -440,22 +440,18 @@ static void handle_discard_bio(struct ploop *ploop, struct bio *bio,
 
 	if (!ploop->force_link_inflight_bios) {
 		/*
-		 * Switch ploop to mode, when requests are handled
-		 * from kwork only, and force all not exclusive
-		 * inflight bios to link into inflight_bios_rbtree.
-		 * Note, that this does not wait completion of
-		 * two-stages requests (currently, these may be only
-		 * cow, which take cluster lk, so we are safe with
-		 * them).
+		 * Force all not exclusive inflight bios to link into
+		 * inflight_bios_rbtree. Note, that this does not wait
+		 * completion of two-stages requests (currently, these
+		 * may be only cow, which take cluster lk, so we are
+		 * safe with them).
 		 */
 		ploop->force_link_inflight_bios = true;
-		force_defer_bio_count_inc(ploop);
 		ret = ploop_inflight_bios_ref_switch(ploop, true);
 		if (ret) {
 			pr_err_ratelimited("ploop: discard ignored by err=%d\n",
 					ret);
 			ploop->force_link_inflight_bios = false;
-			force_defer_bio_count_dec(ploop);
 			goto enotsupp;
 		}
 	}
@@ -1456,10 +1452,8 @@ static void do_discard_cleanup(struct ploop *ploop)
 		smp_rmb();
 		cleanup_jiffies = READ_ONCE(ploop->pending_discard_cleanup);
 
-		if (time_after(jiffies, cleanup_jiffies + CLEANUP_DELAY * HZ)) {
+		if (time_after(jiffies, cleanup_jiffies + CLEANUP_DELAY * HZ))
 			ploop->force_link_inflight_bios = false;
-			force_defer_bio_count_dec(ploop);
-		}
 	}
 }
 
@@ -1596,20 +1590,6 @@ void do_ploop_work(struct work_struct *ws)
 	check_services_timeout(ploop);
 }
 
-static bool should_defer_bio(struct ploop *ploop, struct bio *bio,
-			     unsigned int cluster)
-{
-	struct push_backup *pb = ploop->pb;
-
-	lockdep_assert_held(&ploop->bat_rwlock);
-
-	if (ploop->force_defer_bio_count)
-		return true;
-	if (pb && pb->alive && op_is_write(bio->bi_opf))
-		return test_bit(cluster, pb->ppb_map);
-	return false;
-}
-
 /*
  * ploop_map() tries to map bio to origins or delays it.
  * It never modifies ploop->bat_entries and other cached
@@ -1618,43 +1598,18 @@ static bool should_defer_bio(struct ploop *ploop, struct bio *bio,
 int ploop_map(struct dm_target *ti, struct bio *bio)
 {
 	struct ploop *ploop = ti->private;
-	unsigned int cluster, dst_cluster;
-	unsigned long flags;
-	bool in_top_delta;
+	unsigned int cluster;
 
 	ploop_init_end_io(ploop, bio);
 
 	if (bio_sectors(bio)) {
-		if (op_is_discard(bio->bi_opf))
-			return ploop_map_discard(ploop, bio);
 		if (ploop_bio_cluster(ploop, bio, &cluster) < 0)
 			return DM_MAPIO_KILL;
+		if (op_is_discard(bio->bi_opf))
+			return ploop_map_discard(ploop, bio);
 
-		/* map it */
-		read_lock_irqsave(&ploop->bat_rwlock, flags);
-		dst_cluster = ploop_bat_entries(ploop, cluster, NULL);
-		in_top_delta = cluster_is_in_top_delta(ploop, cluster);
-		if (unlikely(should_defer_bio(ploop, bio, cluster))) {
-			/* defer all bios */
-			in_top_delta = false;
-			dst_cluster = 0;
-		}
-		if (in_top_delta)
-			inc_nr_inflight(ploop, bio);
-		read_unlock_irqrestore(&ploop->bat_rwlock, flags);
-
-		if (!in_top_delta) {
-			if (op_is_write(bio->bi_opf) || dst_cluster != BAT_ENTRY_NONE) {
-				defer_bios(ploop, bio, NULL);
-			} else {
-				zero_fill_bio(bio);
-				bio_endio(bio);
-			}
-
-			return DM_MAPIO_SUBMITTED;
-		}
-
-		remap_to_cluster(ploop, bio, dst_cluster);
+		defer_bios(ploop, bio, NULL);
+		return DM_MAPIO_SUBMITTED;
 	}
 
 	remap_to_origin(ploop, bio);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 93a902d66acf..0eb313d4c412 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -175,7 +175,6 @@ struct ploop {
 	unsigned int tb_nr; /* tracking_bitmap size in bits */
 	unsigned int tb_cursor;
 
-	int force_defer_bio_count; /* Protected by bat_rwlock */
 	bool force_link_inflight_bios;
 	/*
 	 * Hash table to link non-exclusive submitted bios.
@@ -446,24 +445,6 @@ static inline void init_bat_entries_iter(struct ploop *ploop, unsigned int page_
 		*end = ((ploop->nr_bat_entries + PLOOP_MAP_OFFSET) % count) - 1;
 }
 
-static inline void force_defer_bio_count_inc(struct ploop *ploop)
-{
-	unsigned long flags;
-
-	write_lock_irqsave(&ploop->bat_rwlock, flags);
-	WARN_ON_ONCE(ploop->force_defer_bio_count++ < 0);
-	write_unlock_irqrestore(&ploop->bat_rwlock, flags);
-}
-
-static inline void force_defer_bio_count_dec(struct ploop *ploop)
-{
-	unsigned long flags;
-
-	write_lock_irqsave(&ploop->bat_rwlock, flags);
-	WARN_ON_ONCE(--ploop->force_defer_bio_count < 0);
-	write_unlock_irqrestore(&ploop->bat_rwlock, flags);
-}
-
 extern void __track_bio(struct ploop *ploop, struct bio *bio);
 
 static inline void track_bio(struct ploop *ploop, struct bio *bio)


More information about the Devel mailing list