[Devel] [RFC PATCH vz9 v6 50/62] dm-ploop: use lockless lists for data ready pios

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


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 4c5e4a181f4a..3e0ff9e34684 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -63,7 +63,7 @@ void ploop_index_wb_init(struct ploop_index_wb *piwb, struct ploop *ploop)
 	piwb->bat_page = NULL;
 	piwb->kmpage = 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() */
@@ -902,6 +902,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) {
@@ -923,7 +924,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));
@@ -932,7 +933,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);
@@ -1209,7 +1212,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);
@@ -1850,9 +1853,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);
 	}
 
 	ploop_md_up_prio(ploop, md);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 3306849c7aef..85853dd8f7dd 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -102,7 +102,7 @@ struct ploop_index_wb {
 	struct pio *pio;
 	struct page *bat_page;
 	void *kmpage;
-	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