blk-mq: Rework blk-mq timeout handling again
Subsystems (2)
v12 cover blk-mq: Rework blk-mq timeout handling again
Hello Jens,
This patch series reworks blk-mq timeout handling by introducing a state machine per request. Please consider this patch series for inclusion in the upstream kernel.
Bart.
Changes compared to v11:
- Reworked patch 1/2: instead of introducing CONFIG_ARCH_HAVE_CMPXCHG64, make sure that cmpxchg64() is only defined if it can be used.
Changes compared to v10:
- In patch 1/2, added "default y if 64BIT" to the "config ARCH_HAVE_CMPXCHG64" entry in arch/Kconfig. Left out the "select ARCH_HAVE_CMPXCHG64" statements that became superfluous due to this change (alpha, arm64, powerpc and s390).
- Also in patch 1/2, only select ARCH_HAVE_CMPXCHG64 if X86_CMPXCHG64 has been selected.
- In patch 2/2, moved blk_mq_change_rq_state() from blk-mq.h to blk-mq.c.
- Added a comment header above __blk_mq_requeue_request() and blk_mq_requeue_request().
- Documented the MQ_RQ_* state transitions in block/blk-mq.h.
- Left out the fourth argument of blk_mq_rq_set_deadline().
Changes compared to v9:
- Addressed multiple comments related to patch 1/2: added CONFIG_ARCH_HAVE_CMPXCHG64 for riscv, modified features/locking/cmpxchg64/arch-support.txt as requested and made the order of the symbols in the arch/*/Kconfig alphabetical where possible.
Changes compared to v8:
- Split into two patches.
- Moved the spin_lock_init() call from blk_mq_rq_ctx_init() into blk_mq_init_request().
- Fixed the deadline set by blk_add_timer().
- Surrounded the das_lock member with #ifndef CONFIG_ARCH_HAVE_CMPXCHG64 / #endif.
Changes compared to v7:
- Fixed the generation number mechanism. Note: with this patch applied the behavior of the block layer does not depend on the generation number.
- Added more 32-bit architectures to the list of architectures on which cmpxchg64() should not be used.
Changes compared to v6:
- Used a union instead of bit manipulations to store multiple values into a single 64-bit field.
- Reduced the size of the timeout field from 64 to 32 bits.
- Made sure that the block layer still builds with this patch applied for the sh and mips architectures.
- Fixed two sparse warnings that were introduced by this patch in the WRITE_ONCE() calls.
Changes compared to v5:
- Restored the synchronize_rcu() call between marking a request for timeout handling and the actual timeout handling to avoid that timeout handling starts while .queue_rq() is still in progress if the timeout is very short.
- Only use cmpxchg() if another context could attempt to change the request state concurrently. Use WRITE_ONCE() otherwise.
Changes compared to v4:
- Addressed multiple review comments from Christoph. The most important are that atomic_long_cmpxchg() has been changed into cmpxchg() and also that there is now a nice and clean split between the legacy and blk-mq versions of blk_add_timer().
- Changed the patch name and modified the patch description because there is disagreement about whether or not the v4.16 blk-mq core can complete a single request twice. Kept the "Cc: stable" tag because of
https://bugzilla.kernel.org/show_bug.cgi?id=199077.
Changes compared to v3 (see also https://www.mail-archive.com/[email protected]/msg20073.html):
- Removed the spinlock again that was introduced to protect the request state.
v4 uses atomic_long_cmpxchg() instead.
- Split __deadline into two variables - one for the legacy block layer and one
for blk-mq.
Changes compared to v2 (https://www.mail-archive.com/[email protected]/msg18338.html):
- Rebased and retested on top of kernel v4.16.
Changes compared to v1 (https://www.mail-archive.com/[email protected]/msg18089.html):
- Removed the gstate and aborted_gstate members of struct request and used
the __deadline member to encode both the generation and state information.
Bart Van Assche (2):
ARM: cmpxchg64: Only define cmpxchg64() if not using the Thumb
instruction set
blk-mq: Rework blk-mq timeout handling again
arch/arm/include/asm/cmpxchg.h | 4 + block/blk-core.c | 6 -- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 238 +++++++++++++++++++---------------------- block/blk-mq.h | 64 +++++------ block/blk-timeout.c | 133 +++++++++++++++-------- block/blk.h | 11 +- include/linux/blkdev.h | 48 +++++---- 8 files changed, 267 insertions(+), 238 deletions(-)
Signature · 1 line
2.16.3
PATCH v12 1/2 ARM: cmpxchg64: Only define cmpxchg64() if not using the Thumb instruction set
Since the implementation of cmpxchg64() uses instructions that are not Thumb instructions, only define cmpxchg64() if not building in Thumb mode. This patch allows the next patch in this series to check for cmpxchg64() support using #if defined(cmpxchg64).
--- arch/arm/include/asm/cmpxchg.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/include/asm/cmpxchg.h +4 -0
@@ -141,7 +141,9 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size sizeof(*(ptr))); \ }) +#ifndef CONFIG_THUMB2_KERNEL #define cmpxchg64_local (ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) +#endif /* CONFIG_THUMB2_KERNEL */ #include <asm-generic/cmpxchg.h>
@@ -241,6 +243,7 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr, sizeof(*(ptr))); \ }) +#ifndef CONFIG_THUMB2_KERNEL static inline unsigned long long __cmpxchg64 (unsigned long long *ptr,unsigned long long old,unsigned long long new)
@@ -273,6 +276,7 @@ static inline unsigned long long __cmpxchg64(unsigned long long *ptr, })#define cmpxchg64_local (ptr, o, n) cmpxchg64_relaxed((ptr), (o), (n)) +#endif /* CONFIG_THUMB2_KERNEL */ #endif /* __LINUX_ARM_ARCH__ >= 6 */
Signature · 1 line
2.16.3
PATCH v12 2/2 blk-mq: Rework blk-mq timeout handling again
In reply to Bart Van AsscheRecently the blk-mq timeout handling code was reworked. See also Tejun Heo, "[PATCHSET v4] blk-mq: reimplement timeout handling", 08 Jan 2018
(https://www.mail-archive.com/[email protected]/msg16985.html).
This patch reworks the blk-mq timeout handling code again. The timeout handling code is simplified by introducing a state machine per request. This change avoids that the blk-mq timeout handling code ignores completions that occur after blk_mq_check_expired() has been called and before blk_mq_rq_timed_out() has been called.
Fix this race as follows:
- Replace the __deadline member of struct request by a new member called das that contains the generation number, state and deadline. Only 32 bits are used for the deadline field such that all three fields occupy only 64 bits. This change reduces the maximum supported request timeout value from (2**63/HZ) to (2**31/HZ).
- Remove all request member variables that became superfluous due to this change: gstate, gstate_seq and aborted_gstate_sync.
- Remove the request state information that became superfluous due to this patch, namely RQF_MQ_TIMEOUT_EXPIRED.
- Remove the code that became superfluous due to this change, namely the RCU lock and unlock statements in blk_mq_complete_request() and also the synchronize_rcu() call in the timeout handler.
Notes:
- A spinlock is used to protect atomic changes of rq->das on those architectures that do not provide a cmpxchg64() implementation.
- Atomic instructions are only used to update the request state if a concurrent request state change could be in progress.
- blk_add_timer() has been split into two functions - one for the legacy block layer and one for blk-mq.
--- block/blk-core.c | 6 -- block/blk-mq-debugfs.c | 1 - block/blk-mq.c | 238 ++++++++++++++++++++++--------------------------- block/blk-mq.h | 64 ++++++------- block/blk-timeout.c | 133 ++++++++++++++++++--------- block/blk.h | 11 +-- include/linux/blkdev.h | 48 +++++----- 7 files changed, 263 insertions(+), 238 deletions(-)
block/blk-core.c +0 -6
@@ -198,12 +198,6 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->internal_tag =-1 ; rq->start_time_ns =ktime_get_ns (); rq->part =NULL ; -seqcount_init (&rq->gstate_seq); -u64_stats_init (&rq->aborted_gstate_sync); -/* -* See comment of blk_mq_init_request -*/ -WRITE_ONCE (rq->gstate,MQ_RQ_GEN_INC ); }EXPORT_SYMBOL (blk_rq_init);
block/blk-mq-debugfs.c +0 -1
@@ -344,7 +344,6 @@ static const char *const rqf_name[] = {RQF_NAME (STATS ),RQF_NAME (SPECIAL_PAYLOAD ),RQF_NAME (ZONE_WRITE_LOCKED ), -RQF_NAME (MQ_TIMEOUT_EXPIRED ), RQF_NAME(MQ_POLL_SLEPT), };#undef RQF_NAME
block/blk-mq.c +108 -130
360 lines not on this page · raw message
block/blk-mq.h +33 -31
94 lines not on this page · raw message
block/blk-timeout.c +91 -42
166 lines not on this page · raw message
block/blk.h +6 -5
@@ -170,6 +170,7 @@ static inline bool bio_integrity_endio(struct bio *bio)void blk_timeout_work (struct work_struct *work);unsigned long blk_rq_timeout (unsigned long timeout);void blk_add_timer (struct request *req); +void blk_mq_add_timer (struct request *req,enum mq_rq_state old);void blk_delete_timer (struct request *);
@@ -195,17 +196,17 @@ void blk_account_io_done(struct request *req, u64 now);*/ static inline int blk_mark_rq_complete (struct request *rq) { -return test_and_set_bit (0 , &rq->__deadline); +return test_and_set_bit (0 , &rq->das.legacy_deadline); }static inline void blk_clear_rq_complete (struct request *rq) { -clear_bit (0 , &rq->__deadline); +clear_bit (0 , &rq->das.legacy_deadline); }static inline bool blk_rq_is_complete (struct request *rq) { -return test_bit (0 , &rq->__deadline); +return test_bit (0 , &rq->das.legacy_deadline); }/*
@@ -314,12 +315,12 @@ static inline void req_set_nomerge(struct request_queue *q, struct request *req)*/ static inline void blk_rq_set_deadline (struct request *rq,unsigned long time) { - rq->__deadline = time & ~0x1UL ; + rq->das.legacy_deadline = time & ~0x1UL ; }static inline unsigned long blk_rq_deadline (struct request *rq) { -return rq->__deadline & ~0x1UL ; +return rq->das.legacy_deadline & ~0x1UL ; }/*
include/linux/blkdev.h +25 -23
83 lines not on this page · raw message
Signature · 1 line
2.16.3