[Devel] [RFC PATCH vz9 v6 36/62] dm-ploop: use jiffies when calculating writeback time

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


ktime_* are expnsive functions, we do not need ns precision.
using jiffies is fine.

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

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index e7d5ddd10615..3a741bb9d2db 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -557,12 +557,13 @@ static bool ploop_md_make_dirty(struct ploop *ploop, struct md_page *md)
 
 	write_lock_irqsave(&ploop->bat_rwlock, flags);
 	WARN_ON_ONCE(test_bit(MD_WRITEBACK, &md->status));
-	md->dirty_time = ktime_get();
 	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);
+	md->dirty_timeout = jiffies + ploop->md_submit_delay_ms*HZ/1000;
+
 	return new;
 }
 
@@ -1835,9 +1836,8 @@ static void ploop_submit_metadata_writeback(struct ploop *ploop)
 	struct md_page *md;
 	struct llist_node *pos, *t;
 	struct llist_node *ll_wb_batch;
+	unsigned long timeout = jiffies;
 
-	ktime = ktime_get();
-	ktimeout = ktime_add_ms(ktime, ploop->md_submit_delay_ms);
 	/* Lock here to protect against md_inflight counting */
 	write_lock_irq(&ploop->bat_rwlock);
 	ll_wb_batch = llist_del_all(&ploop->wb_batch_llist);
@@ -1848,8 +1848,7 @@ static void ploop_submit_metadata_writeback(struct ploop *ploop)
 	 */
 	llist_for_each_safe(pos, t, ll_wb_batch) {
 		md = list_entry((struct list_head *)pos, typeof(*md), wb_link);
-		INIT_LIST_HEAD(&md->wb_link);
-		if (test_bit(MD_HIGHPRIO, &md->status) || ktime_after(md->dirty_time, ktimeout)
+		if (test_bit(MD_HIGHPRIO, &md->status) || time_before(md->dirty_timeout, timeout)
 		    || ploop->force_md_writeback) {
 			/* L1L2 mustn't be redirtyed, when wb in-flight! */
 			WARN_ON_ONCE(!test_bit(MD_DIRTY, &md->status));
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 8dfd75e97845..3c632eab37d7 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -130,7 +130,7 @@ struct md_page {
 
 	rwlock_t lock;
 
-	ktime_t dirty_time;
+	unsigned long dirty_timeout;
 };
 
 enum {
-- 
2.43.0



More information about the Devel mailing list