[Devel] [RFC PATCH vz9 v6 38/62] dm-ploop: convert bat_rwlock to bat_lock spinlock

Alexander Atanasov alexander.atanasov at virtuozzo.com
Fri Dec 6 00:56:11 MSK 2024


Prepare for threads. Convert rwlock to spin lock.
This patch converts existing rwlocks only.
In the next one lock is used where required.

https://virtuozzo.atlassian.net/browse/VSTOR-91821
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c    |  8 ++++----
 drivers/md/dm-ploop-map.c    | 32 ++++++++++++++++++++------------
 drivers/md/dm-ploop-target.c |  2 +-
 drivers/md/dm-ploop.h        |  2 +-
 4 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 017250328ea3..78cdcc81c75f 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -34,7 +34,7 @@ static void ploop_advance_holes_bitmap(struct ploop *ploop,
 		return;
 	cmd->resize.stage++;
 
-	write_lock_irq(&ploop->bat_rwlock);
+	spin_lock_irqsave(&ploop->bat_lock, flags);
 	/* Copy and swap holes_bitmap */
 	size = DIV_ROUND_UP(ploop->hb_nr, 8);
 	memcpy(cmd->resize.holes_bitmap, ploop->holes_bitmap, size);
@@ -59,7 +59,7 @@ static void ploop_advance_holes_bitmap(struct ploop *ploop,
 		}
 		spin_unlock(&md->md_lock);
 	}
-	write_unlock_irq(&ploop->bat_rwlock);
+	spin_unlock_irqrestore(&ploop->bat_lock, flags);
 }
 
 static int ploop_wait_for_completion_maybe_killable(struct completion *comp,
@@ -450,7 +450,7 @@ static int ploop_process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 	/* Update header metadata */
 	ret = ploop_grow_update_header(ploop, cmd);
 out:
-	write_lock_irq(&ploop->bat_rwlock);
+	spin_lock_irq(&ploop->bat_lock);
 	if (ret) {
 		/* Cleanup: mark new BAT overages as free clusters */
 		dst_clu = cmd->resize.dst_clu - 1;
@@ -464,7 +464,7 @@ static int ploop_process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 		ploop_add_md_pages(ploop, &cmd->resize.md_pages_root);
 		swap(ploop->nr_bat_entries, cmd->resize.nr_bat_entries);
 	}
-	write_unlock_irq(&ploop->bat_rwlock);
+	spin_unlock_irq(&ploop->bat_lock);
 
 	return ret;
 }
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 2a6ff9e2996b..bb15fa1f854b 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -555,13 +555,13 @@ static bool ploop_md_make_dirty(struct ploop *ploop, struct md_page *md)
 	unsigned long flags;
 	bool new = false;
 
-	write_lock_irqsave(&ploop->bat_rwlock, flags);
+	spin_lock_irqsave(&ploop->bat_lock, flags);
 	WARN_ON_ONCE(test_bit(MD_WRITEBACK, &md->status));
 	if (!test_and_set_bit(MD_DIRTY, &md->status)) {
 		llist_add((struct llist_node *)&md->wb_link, &ploop->wb_batch_llist);
 		new = true;
 	}
-	write_unlock_irqrestore(&ploop->bat_rwlock, flags);
+	spin_unlock_irqrestore(&ploop->bat_lock, flags);
 	md->dirty_timeout = jiffies + ploop->md_submit_delay_ms*HZ/1000;
 
 	return new;
@@ -571,7 +571,7 @@ static void ploop_md_up_prio(struct ploop *ploop, struct md_page *md)
 {
 	unsigned long flags;
 
-	write_lock_irqsave(&ploop->bat_rwlock, flags);
+	spin_lock_irqsave(&ploop->bat_lock, flags);
 	if (test_bit(MD_WRITEBACK, &md->status))
 		goto out;
 	if (test_and_set_bit(MD_HIGHPRIO, &md->status))
@@ -579,7 +579,7 @@ static void ploop_md_up_prio(struct ploop *ploop, struct md_page *md)
 
 	WARN_ON_ONCE(!test_bit(MD_DIRTY, &md->status));
 out:
-	write_unlock_irqrestore(&ploop->bat_rwlock, flags);
+	spin_unlock_irqrestore(&ploop->bat_lock, flags);
 }
 
 void ploop_disable_writeback_delay(struct ploop *ploop)
@@ -730,9 +730,9 @@ static void ploop_complete_cow(struct ploop_cow *cow, blk_status_t bi_status)
 	ploop_del_cluster_lk(ploop, cow_pio);
 
 	if (dst_clu != BAT_ENTRY_NONE && bi_status != BLK_STS_OK) {
-		read_lock_irqsave(&ploop->bat_rwlock, flags);
+		spin_lock_irqsave(&ploop->bat_lock, flags);
 		ploop_hole_set_bit(dst_clu, ploop);
-		read_unlock_irqrestore(&ploop->bat_rwlock, flags);
+		spin_unlock_irqrestore(&ploop->bat_lock, flags);
 	}
 
 	ploop_queue_or_fail(ploop, blk_status_to_errno(bi_status), cow_pio);
@@ -1828,9 +1828,16 @@ static void ploop_process_resubmit_pios(struct ploop *ploop,
 	}
 }
 
-static void ploop_submit_metadata_writeback(struct ploop *ploop)
+#ifdef USE_RUNNERS
+static inline int ploop_runners_have_pending(struct ploop *ploop)
 {
-	ktime_t ktime, ktimeout;
+	return atomic_read(&ploop->kt_worker->inflight_pios);
+}
+#endif
+
+static void ploop_submit_metadata_writeback(struct ploop *ploop, int force)
+{
+	unsigned long flags;
 	LIST_HEAD(ll_skipped);
 	struct md_page *md;
 	struct llist_node *pos, *t;
@@ -1838,9 +1845,9 @@ static void ploop_submit_metadata_writeback(struct ploop *ploop)
 	unsigned long timeout = jiffies;
 
 	/* Lock here to protect against md_inflight counting */
-	write_lock_irq(&ploop->bat_rwlock);
+	spin_lock_irqsave(&ploop->bat_lock, flags);
 	ll_wb_batch = llist_del_all(&ploop->wb_batch_llist);
-	write_unlock_irq(&ploop->bat_rwlock);
+	spin_unlock_irqrestore(&ploop->bat_lock, flags);
 	/*
 	 * Pages are set dirty so no one must touch lists
 	 * if new md entries are dirtied they are added at the start of the list
@@ -1998,6 +2005,7 @@ static int ploop_prepare_flush(struct ploop *ploop, struct pio *pio)
 	struct md_page *md, *n;
 	int md_inflight = 0;
 	struct llist_node *pos, *t;
+	unsigned long flags;
 
 	if (pio->bi_op & REQ_PREFLUSH && (pio->bi_op & REQ_OP_MASK) != REQ_OP_FLUSH) {
 		flush_pio = ploop_alloc_pio(ploop, GFP_NOIO);
@@ -2014,7 +2022,7 @@ static int ploop_prepare_flush(struct ploop *ploop, struct pio *pio)
 		flush_pio->free_on_endio = true;
 	}
 
-	write_lock_irq(&ploop->bat_rwlock);
+	spin_lock_irqsave(&ploop->bat_lock, flags);
 	llist_for_each_safe(pos, t, ploop->wb_batch_llist.first) {
 		md = list_entry((struct list_head *)pos, typeof(*md), wb_link);
 		md_inflight++;
@@ -2023,7 +2031,7 @@ static int ploop_prepare_flush(struct ploop *ploop, struct pio *pio)
 	}
 
 	atomic_set(&flush_pio->md_inflight, md_inflight);
-	write_unlock_irq(&ploop->bat_rwlock);
+	spin_unlock_irqrestore(&ploop->bat_lock, flags);
 
 	return md_inflight;
 }
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 6c60043c0487..772a5fd25c47 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -420,7 +420,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		goto err;
 	}
 
-	rwlock_init(&ploop->bat_rwlock);
+	spin_lock_init(&ploop->bat_lock);
 	spin_lock_init(&ploop->err_status_lock);
 	init_rwsem(&ploop->ctl_rwsem);
 	init_waitqueue_head(&ploop->service_wq);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 42a1b4759d75..02e47033f97c 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -176,7 +176,7 @@ struct ploop {
 	 */
 	void *holes_bitmap; /* Clearing a bit occurs from kwork only */
 	u32 hb_nr; /* holes_bitmap size in bits */
-	rwlock_t bat_rwlock;
+	spinlock_t bat_lock;
 
 	struct llist_head wb_batch_llist;
 
-- 
2.43.0



More information about the Devel mailing list