From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 1/4] block/part_stat: remove rcu_read_lock() from part_stat_lock()
Date: Mon, 04 May 2020 16:29:29 +0300 [thread overview]
Message-ID: <158859896942.19836.15240144203131230746.stgit@buzz> (raw)
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)
next reply other threads:[~2020-05-04 13:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 13:29 Konstantin Khlebnikov [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=158859896942.19836.15240144203131230746.stgit@buzz \
--to=khlebnikov@yandex-team.ru \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.