All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] block/part_stat: remove rcu_read_lock() from part_stat_lock()
@ 2020-05-04 13:29 Konstantin Khlebnikov
  2020-05-04 13:29 ` [PATCH 2/4] block/part_stat: use __this_cpu_add() instead of access by smp_processor_id() Konstantin Khlebnikov
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Konstantin Khlebnikov @ 2020-05-04 13:29 UTC (permalink / raw)
  To: linux-kernel, linux-block, Jens Axboe

RCU lock is required only in blk_account_io_start() to lookup partition.
After that request holds reference to related hd_struct.

Replace get_cpu() with preempt_disable() - returned cpu index is unused.

Non-SMP case also needs preempt_disable, otherwise statistics update could
be non-atomic. Previously that was provided by rcu_read_lock().

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
 block/blk-core.c          |    3 +++
 include/linux/part_stat.h |    7 +++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 7f11560bfddb..45ddf7238c06 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1362,6 +1362,7 @@ void blk_account_io_start(struct request *rq, bool new_io)
 		part = rq->part;
 		part_stat_inc(part, merges[rw]);
 	} else {
+		rcu_read_lock();
 		part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
 		if (!hd_struct_try_get(part)) {
 			/*
@@ -1375,6 +1376,8 @@ void blk_account_io_start(struct request *rq, bool new_io)
 			part = &rq->rq_disk->part0;
 			hd_struct_get(part);
 		}
+		rcu_read_unlock();
+
 		part_inc_in_flight(rq->q, part, rw);
 		rq->part = part;
 	}
diff --git a/include/linux/part_stat.h b/include/linux/part_stat.h
index ece607607a86..755a01f0fd61 100644
--- a/include/linux/part_stat.h
+++ b/include/linux/part_stat.h
@@ -16,9 +16,10 @@
  * part_stat_{add|set_all}() and {init|free}_part_stats are for
  * internal use only.
  */
+#define part_stat_lock()	preempt_disable()
+#define part_stat_unlock()	preempt_enable()
+
 #ifdef	CONFIG_SMP
-#define part_stat_lock()	({ rcu_read_lock(); get_cpu(); })
-#define part_stat_unlock()	do { put_cpu(); rcu_read_unlock(); } while (0)
 
 #define part_stat_get_cpu(part, field, cpu)				\
 	(per_cpu_ptr((part)->dkstats, (cpu))->field)
@@ -58,8 +59,6 @@ static inline void free_part_stats(struct hd_struct *part)
 }
 
 #else /* !CONFIG_SMP */
-#define part_stat_lock()	({ rcu_read_lock(); 0; })
-#define part_stat_unlock()	rcu_read_unlock()
 
 #define part_stat_get(part, field)		((part)->dkstats.field)
 #define part_stat_get_cpu(part, field, cpu)	part_stat_get(part, field)


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-05-04 15:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-04 13:29 [PATCH 1/4] block/part_stat: remove rcu_read_lock() from part_stat_lock() Konstantin Khlebnikov
2020-05-04 13:29 ` [PATCH 2/4] block/part_stat: use __this_cpu_add() instead of access by smp_processor_id() Konstantin Khlebnikov
2020-05-04 14:03   ` Christoph Hellwig
2020-05-04 15:02     ` Konstantin Khlebnikov
2020-05-04 15:10       ` Christoph Hellwig
2020-05-04 13:30 ` [PATCH 3/4] block/part_stat: account merge of two requests Konstantin Khlebnikov
2020-05-04 14:03   ` Christoph Hellwig
2020-05-04 13:31 ` [PATCH 4/4] block/part_stat: add helper blk_account_io_merge_bio() Konstantin Khlebnikov
2020-05-04 14:06   ` Christoph Hellwig
2020-05-04 14:00 ` [PATCH 1/4] block/part_stat: remove rcu_read_lock() from part_stat_lock() Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.