[Devel] [RFC PATCH vz9 v3 06/11] ploop: reduce the time lock is hold, taking it only to protect data

Alexander Atanasov alexander.atanasov at virtuozzo.com
Mon Oct 21 13:13:53 MSK 2024


Currently lock is taken once for all pios submitted(code block),
move it to protect only the list insertion (data).
The goal is to reduce lock contention on the deferred lock as
it is in the top of lock stats.

Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 4f31000a8c1e..e50e4ff58902 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -340,8 +340,9 @@ static void ploop_dispatch_pio(struct ploop *ploop, struct pio *pio,
 			       bool *is_data, bool *is_flush)
 {
 	struct list_head *list = &ploop->pios[pio->queue_list_id];
+	unsigned long flags;
 
-	lockdep_assert_held(&ploop->deferred_lock);
+	lockdep_assert_not_held(&ploop->deferred_lock);
 	WARN_ON_ONCE(pio->queue_list_id >= PLOOP_LIST_COUNT);
 
 	if (pio->queue_list_id == PLOOP_LIST_FLUSH)
@@ -349,23 +350,22 @@ static void ploop_dispatch_pio(struct ploop *ploop, struct pio *pio,
 	else
 		*is_data = true;
 
+	spin_lock_irqsave(&ploop->deferred_lock, flags);
 	list_add_tail(&pio->list, list);
+	spin_unlock_irqrestore(&ploop->deferred_lock, flags);
 }
 
 void ploop_dispatch_pios(struct ploop *ploop, struct pio *pio,
 			 struct list_head *pio_list)
 {
 	bool is_data = false, is_flush = false;
-	unsigned long flags;
 
-	spin_lock_irqsave(&ploop->deferred_lock, flags);
 	if (pio)
 		ploop_dispatch_pio(ploop, pio, &is_data, &is_flush);
 	if (pio_list) {
 		while ((pio = ploop_pio_list_pop(pio_list)) != NULL)
 			ploop_dispatch_pio(ploop, pio, &is_data, &is_flush);
 	}
-	spin_unlock_irqrestore(&ploop->deferred_lock, flags);
 
 	if (is_data)
 		queue_work(ploop->wq, &ploop->worker);
-- 
2.43.0



More information about the Devel mailing list