[Devel] [PATCH vz9 v1 44/63] dm-ploop: use lockless lists for data ready pios

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


reduce locking for data ready pios chained to bat updates

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

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 809ae3ee71ec..4b4facc79aba 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -62,7 +62,7 @@ void ploop_index_wb_init(struct ploop_index_wb *piwb, struct ploop *ploop)
 	piwb->md = NULL;
 	piwb->bat_page = NULL;
 	piwb->bi_status = 0;
-	INIT_LIST_HEAD(&piwb->ready_data_pios);
+	init_llist_head(&piwb->llready_data_pios);
 	init_llist_head(&piwb->cow_llist);
 
 	/* For ploop_bat_write_complete() */
@@ -904,6 +904,7 @@ static void ploop_bat_write_complete(struct pio *pio, void *piwb_ptr,
 	LIST_HEAD(lready_pios);
 	struct llist_node *pos, *t;
 	struct llist_node *ll_cow_pios;
+	struct llist_node *ll_ready_pios;
 	int completed = atomic_read(&piwb->count) == 1;
 
 	if (completed) {
@@ -925,7 +926,7 @@ static void ploop_bat_write_complete(struct pio *pio, void *piwb_ptr,
 	if (completed)
 		piwb->completed = completed;
 	piwb->bi_status = bi_status;
-	list_splice_init(&piwb->ready_data_pios, &lready_pios);
+	ll_ready_pios = llist_reverse_order(llist_del_all(&piwb->llready_data_pios));
 	spin_unlock_irqrestore(&piwb->lock, flags);
 
 	ll_cow_pios = llist_reverse_order(llist_del_all(&piwb->cow_llist));
@@ -934,7 +935,9 @@ static void ploop_bat_write_complete(struct pio *pio, void *piwb_ptr,
 	 * End pending data bios.
 	 */
 
-	while ((data_pio = ploop_pio_list_pop(&lready_pios)) != NULL) {
+	llist_for_each_safe(pos, t, ll_ready_pios) {
+		pio = list_entry((struct list_head *)pos, typeof(*aux_pio), list);
+		INIT_LIST_HEAD(&pio->list);
 		if (bi_status)
 			data_pio->bi_status = bi_status;
 		ploop_pio_endio(data_pio);
@@ -1222,7 +1225,7 @@ static bool ploop_data_pio_end(struct pio *pio)
 	spin_lock_irqsave(&piwb->lock, flags);
 	completed = piwb->completed;
 	if (!completed)
-		list_add_tail(&pio->list, &piwb->ready_data_pios);
+		llist_add((struct llist_node *)(&pio->list), &piwb->llready_data_pios);
 	else if (!pio->bi_status)
 		pio->bi_status = piwb->bi_status;
 	spin_unlock_irqrestore(&piwb->lock, flags);
@@ -1842,9 +1845,7 @@ static void ploop_process_one_discard_pio(struct ploop *ploop, struct pio *pio)
 		goto err;
 	} else {
 		WRITE_ONCE(to[clu], 0);
-		spin_lock_irqsave(&piwb->lock, flags);
-		list_add_tail(&pio->list, &piwb->ready_data_pios);
-		spin_unlock_irqrestore(&piwb->lock, flags);
+		llist_add((struct llist_node *)(&pio->list), &piwb->llready_data_pios);
 	}
 	kunmap_local(to);
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 3f80d1750ffb..ad1033c0898a 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -101,7 +101,7 @@ struct ploop_index_wb {
 	struct md_page *md;
 	struct pio *pio;
 	struct page *bat_page;
-	struct list_head ready_data_pios;
+	struct llist_head llready_data_pios;
 	struct llist_head cow_llist;
 	atomic_t count;
 	bool completed;
-- 
2.43.0



More information about the Devel mailing list