block, scsi, md: Improve suspend and resume
Subsystems (5)
v8 cover block, scsi, md: Improve suspend and resume
Hello Jens,
It is known that during the resume following a hibernate, especially when using an md RAID1 array created on top of SCSI devices, sometimes the system hangs instead of coming up properly. This patch series fixes that problem. These patches have been tested on top of the block layer for-next branch. Please consider these changes for kernel v4.15.
Thanks,
Bart.
Changes between v7 and v8:
- Fixed a (theoretical?) race identified by Ming Lei.
- Added a tenth patch that checks whether the proper type of flags has been passed to a range of block layer functions.
Changes between v6 and v7:
- Added support for the PREEMPT_ONLY flag in blk-mq-debugfs.c.
- Fixed kerneldoc header of blk_queue_enter().
- Added a rcu_read_lock_sched() / rcu_read_unlock_sched() pair in blk_set_preempt_only().
- Removed a synchronize_rcu() call from scsi_device_quiesce().
- Modified the description of patch 9/9 in this series.
- Removed scsi_run_queue() call from scsi_device_resume().
Changes between v5 and v6:
- Split an md patch into two patches to make it easier to review the changes.
- For the md patch that suspends I/O while the system is frozen, switched back to the freezer mechanism because this makes the code shorter and easier to review.
- Changed blk_set/clear_preempt_only() from EXPORT_SYMBOL() into EXPORT_SYMBOL_GPL().
- Made blk_set_preempt_only() behave as a test-and-set operation.
- Introduced blk_get_request_flags() and BLK_MQ_REQ_PREEMPT as requested by Christoph and reduced the number of arguments of blk_queue_enter() back from three to two.
- In scsi_device_quiesce(), moved the blk_mq_freeze_queue() call out of a critical section. Made the explanation of why the synchronize_rcu() call is necessary more detailed.
Changes between v4 and v5:
- Split blk_set_preempt_only() into two functions as requested by Christoph.
- Made blk_get_request() trigger WARN_ONCE() if it is attempted to allocate a request while the system is frozen. This is a big help to identify drivers that submit I/O while the system is frozen.
- Since kernel thread freezing is on its way out, reworked the approach for avoiding that the md driver submits I/O while the system is frozen such that the approach no longer depends on the kernel thread freeze mechanism.
- Fixed the (theoretical) deadlock in scsi_device_quiesce() that was identified by Ming.
Changes between v3 and v4:
- Made sure that this patch series not only works for scsi-mq but also for the legacy SCSI stack.
- Removed an smp_rmb()/smp_wmb() pair from the hot path and added a comment that explains why that is safe.
- Reordered the patches in this patch series.
Changes between v2 and v3:
- Made md kernel threads freezable.
- Changed the approach for quiescing SCSI devices again.
- Addressed Ming's review comments.
Changes compared to v1 of this patch series:
- Changed the approach and rewrote the patch series.
Bart Van Assche (9):
md: Rename md_notifier into md_reboot_notifier
md: Introduce md_stop_all_writes()
md: Neither resync nor reshape while the system is frozen
block: Introduce blk_get_request_flags()
block: Introduce BLK_MQ_REQ_PREEMPT
ide, scsi: Tell the block layer at request allocation time about
preempt requests
block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag block, scsi: Make SCSI quiesce and resume work reliably block, nvme: Introduce blk_mq_req_flags_t
Ming Lei (1):
block: Make q_usage_counter also track legacy requests
block/blk-core.c | 132 +++++++++++++++++++++++++++++++++++++++------- block/blk-mq-debugfs.c | 1 + block/blk-mq.c | 20 +++---- block/blk-mq.h | 2 +- block/blk-timeout.c | 2 +- drivers/ide/ide-pm.c | 4 +- drivers/md/md.c | 45 +++++++++++++--- drivers/nvme/host/core.c | 5 +- drivers/nvme/host/nvme.h | 5 +- drivers/scsi/scsi_lib.c | 35 +++++++----- fs/block_dev.c | 4 +- include/linux/blk-mq.h | 16 ++++-- include/linux/blk_types.h | 2 + include/linux/blkdev.h | 11 +++- 14 files changed, 217 insertions(+), 67 deletions(-)
Signature · 1 line
2.14.2
PATCH v8 1/10 md: Rename md_notifier into md_reboot_notifier
This avoids confusion with the pm notifier that will be added through a later patch.
--- drivers/md/md.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/md/md.c +3 -3
@@ -8966,7 +8966,7 @@ static int md_notify_reboot(struct notifier_block *this,return NOTIFY_DONE ; } -static struct notifier_block md_notifier = { +static struct notifier_block md_reboot_notifier = { .notifier_call = md_notify_reboot, .next =NULL , .priority =INT_MAX ,/* before any real devices */
@@ -9003,7 +9003,7 @@ static int __init md_init(void)blk_register_region (MKDEV (mdp_major,0 ),1UL <<MINORBITS ,THIS_MODULE , md_probe,NULL ,NULL ); -register_reboot_notifier (&md_notifier); +register_reboot_notifier (&md_reboot_notifier); raid_table_header =register_sysctl_table (raid_root_table);md_geninit ();
@@ -9243,7 +9243,7 @@ static __exit void md_exit(void)unregister_blkdev (MD_MAJOR ,"md" );unregister_blkdev (mdp_major,"mdp" ); -unregister_reboot_notifier (&md_notifier); +unregister_reboot_notifier (&md_reboot_notifier);unregister_sysctl_table (raid_table_header);/* We cannot unload the modules while some process is
Signature · 1 line
2.14.2
PATCH v8 2/10 md: Introduce md_stop_all_writes()
In reply to Bart Van AsscheIntroduce md_stop_all_writes() because the next patch will add a second caller for this function. This patch does not change any functionality.
--- drivers/md/md.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/md/md.c +7 -2
@@ -8937,8 +8937,7 @@ int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors, }EXPORT_SYMBOL_GPL (rdev_clear_badblocks); -static int md_notify_reboot (struct notifier_block *this, -unsigned long code,void *x) +static void md_stop_all_writes (void ) {struct list_head *tmp;struct mddev *mddev;
@@ -8962,6 +8961,12 @@ static int md_notify_reboot(struct notifier_block *this,*/ if (need_delay)mdelay (1000 *1 ); +} + +static int md_notify_reboot (struct notifier_block *this, +unsigned long code,void *x) +{ +md_stop_all_writes ();return NOTIFY_DONE ; }
Signature · 1 line
2.14.2
PATCH v8 3/10 md: Neither resync nor reshape while the system is frozen
In reply to Bart Van AsscheSome people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before a hibernation image is created, interrupt the md resync and reshape actions if the system is being frozen. Note: the resync and reshape will restart after the system is resumed and a message similar to the following will appear in the system log:
md: md0: data-check interrupted.
--- drivers/md/md.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/md/md.c +29 -1
@@ -66,6 +66,8 @@#include <linux/raid/md_u.h> #include <linux/slab.h> #include <linux/percpu-refcount.h> +#include <linux/freezer.h> +#include <linux/suspend.h> #include <trace/events/block.h> #include "md.h"
@@ -7439,6 +7441,7 @@ static int md_thread(void *arg)*/ allow_signal (SIGKILL ); +set_freezable ();while (!kthread_should_stop ()) {/* We need to wait INTERRUPTIBLE so that
@@ -7449,7 +7452,7 @@ static int md_thread(void *arg)if (signal_pending (current))flush_signals (current); - wait_event_interruptible_timeout + wait_event_freezable_timeout (thread->wqueue, test_bit(THREAD_WAKEUP, &thread->flags) || kthread_should_stop() || kthread_should_park(),
@@ -8963,6 +8966,29 @@ static void md_stop_all_writes(void)mdelay (1000 *1 ); } +/* +* Ensure that neither resyncing nor reshaping occurs while the system is +* frozen. +*/ +static int md_notify_pm (struct notifier_block *bl,unsigned long state, +void *unused) +{ +pr_debug ("%s: state = %ld\n" , __func__, state); + +switch (state) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +case PM_RESTORE_PREPARE : +md_stop_all_writes (); +break ; + } +return NOTIFY_DONE ; +} + +static struct notifier_block md_pm_notifier = { + .notifier_call = md_notify_pm, +}; +static int md_notify_reboot (struct notifier_block *this,unsigned long code,void *x) {
@@ -9009,6 +9035,7 @@ static int __init md_init(void) md_probe, NULL, NULL);register_reboot_notifier (&md_reboot_notifier); +register_pm_notifier (&md_pm_notifier); raid_table_header =register_sysctl_table (raid_root_table);md_geninit ();
@@ -9248,6 +9275,7 @@ static __exit void md_exit(void)unregister_blkdev (MD_MAJOR ,"md" );unregister_blkdev (mdp_major,"mdp" ); +unregister_pm_notifier (&md_pm_notifier);unregister_reboot_notifier (&md_reboot_notifier);unregister_sysctl_table (raid_table_header);
Signature · 1 line
2.14.2
PATCH v8 4/10 block: Make q_usage_counter also track legacy requests
In reply to Bart Van AsscheFrom: Ming Lei <[email protected]>
This patch makes it possible to pause request allocation for the legacy block layer by calling blk_mq_freeze_queue() and blk_mq_unfreeze_queue().
[ bvanassche: Combined two patches into one, edited a comment and made sure
REQ_NOWAIT is handled properly in blk_old_get_request() ]
--- block/blk-core.c | 12 ++++++++++++ block/blk-mq.c | 10 ++-------- 2 files changed, 14 insertions(+), 8 deletions(-)
block/blk-core.c +12 -0
@@ -610,6 +610,9 @@ void blk_set_queue_dying(struct request_queue *q) }spin_unlock_irq (q->queue_lock); } + +/* Make blk_queue_enter() reexamine the DYING flag. */ +wake_up_all (&q->mq_freeze_wq); }EXPORT_SYMBOL_GPL (blk_set_queue_dying);
@@ -1395,16 +1398,22 @@ static struct request *blk_old_get_request(struct request_queue *q, unsigned int op, gfp_t gfp_mask) {struct request *rq; +int ret =0 ;WARN_ON_ONCE (q->mq_ops);/* create ioc upfront */ create_io_context (gfp_mask, q->node); + ret =blk_queue_enter (q, !(gfp_mask & __GFP_DIRECT_RECLAIM) || + (op &REQ_NOWAIT )); +if (ret) +return ERR_PTR (ret);spin_lock_irq (q->queue_lock); rq =get_request (q, op,NULL , gfp_mask);if (IS_ERR (rq)) {spin_unlock_irq (q->queue_lock); +blk_queue_exit (q);return rq; }
@@ -1576,6 +1585,7 @@ void __blk_put_request(struct request_queue *q, struct request *req)blk_free_request (rl, req);freed_request (rl, sync, rq_flags);blk_put_rl (rl); +blk_queue_exit (q); } }EXPORT_SYMBOL_GPL (__blk_put_request);
@@ -1857,8 +1867,10 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)* Grab a free request. This is might sleep but can not fail. * Returns with the queue unlocked. */ +blk_queue_enter_live (q); req =get_request (q, bio->bi_opf, bio,GFP_NOIO );if (IS_ERR (req)) { +blk_queue_exit (q);__wbt_done (q->rq_wb, wb_acct);if (PTR_ERR (req) == -ENOMEM ) bio->bi_status =BLK_STS_RESOURCE ;
block/blk-mq.c +2 -8
@@ -125,7 +125,8 @@ void blk_freeze_queue_start(struct request_queue *q) freeze_depth =atomic_inc_return (&q->mq_freeze_depth);if (freeze_depth ==1 ) {percpu_ref_kill (&q->q_usage_counter); -blk_mq_run_hw_queues (q, false); +if (q->mq_ops) +blk_mq_run_hw_queues (q, false); } }EXPORT_SYMBOL_GPL (blk_freeze_queue_start);
@@ -255,13 +256,6 @@ void blk_mq_wake_waiters(struct request_queue *q)queue_for_each_hw_ctx (q, hctx, i)if (blk_mq_hw_queue_mapped (hctx))blk_mq_tag_wakeup_all (hctx->tags, true); - -/* -* If we are called because the queue has now been marked as -* dying, we need to ensure that processes currently waiting on -* the queue are notified as well. -*/ -wake_up_all (&q->mq_freeze_wq); }bool blk_mq_can_queue (struct blk_mq_hw_ctx *hctx)
Signature · 1 line
2.14.2
PATCH v8 5/10 block: Introduce blk_get_request_flags()
In reply to Bart Van AsscheA side effect of this patch is that the GFP mask that is passed to several allocation functions in the legacy block layer is changed from GFP_KERNEL into __GFP_DIRECT_RECLAIM.
--- block/blk-core.c | 50 +++++++++++++++++++++++++++++++++++--------------- include/linux/blkdev.h | 3 +++ 2 files changed, 38 insertions(+), 15 deletions(-)
block/blk-core.c +35 -15
@@ -1157,7 +1157,7 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr)* @rl: request list to allocate from * @op: operation and flags * @bio: bio to allocate request for (can be %NULL) -* @gfp_mask: allocation mask +* @flags: BLQ_MQ_REQ_* flags * * Get a free request from @q. This function may fail under memory * pressure or if @q is dead.
@@ -1167,7 +1167,7 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr)* Returns request pointer on success, with @q->queue_lock *not held*. */ static struct request *__get_request (struct request_list *rl,unsigned int op, -struct bio *bio,gfp_t gfp_mask) +struct bio *bio,unsigned int flags) {struct request_queue *q = rl->q;struct request *rq;
@@ -1176,6 +1176,8 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,struct io_cq *icq =NULL ;const bool is_sync =op_is_sync (op);int may_queue; +gfp_t gfp_mask = flags &BLK_MQ_REQ_NOWAIT ?GFP_ATOMIC : + __GFP_DIRECT_RECLAIM;req_flags_t rq_flags =RQF_ALLOCED ;lockdep_assert_held (q->queue_lock);
@@ -1336,7 +1338,7 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,* @q: request_queue to allocate request from * @op: operation and flags * @bio: bio to allocate request for (can be %NULL) -* @gfp_mask: allocation mask +* @flags: BLK_MQ_REQ_* flags. * * Get a free request from @q. If %__GFP_DIRECT_RECLAIM is set in @gfp_mask, * this function keeps retrying under memory pressure and fails iff @q is dead.
@@ -1346,7 +1348,7 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,* Returns request pointer on success, with @q->queue_lock *not held*. */ static struct request *get_request (struct request_queue *q,unsigned int op, -struct bio *bio,gfp_t gfp_mask) +struct bio *bio,unsigned int flags) {const bool is_sync =op_is_sync (op);DEFINE_WAIT (wait);
@@ -1358,7 +1360,7 @@ static struct request *get_request(struct request_queue *q, unsigned int op, rl =blk_get_rl (q, bio);/* transferred to @rq on success */ retry: - rq =__get_request (rl, op, bio, gfp_mask); + rq =__get_request (rl, op, bio, flags);if (!IS_ERR (rq))return rq;
@@ -1367,7 +1369,7 @@ static struct request *get_request(struct request_queue *q, unsigned int op,return ERR_PTR (-EAGAIN ); } -if (!gfpflags_allow_blocking (gfp_mask) ||unlikely (blk_queue_dying (q))) { +if ((flags &BLK_MQ_REQ_NOWAIT ) ||unlikely (blk_queue_dying (q))) {blk_put_rl (rl);return rq; }
@@ -1394,10 +1396,13 @@ static struct request *get_request(struct request_queue *q, unsigned int op, goto retry; } +/* flags: BLK_MQ_REQ_PREEMPT and/or BLK_MQ_REQ_NOWAIT. */ static struct request *blk_old_get_request (struct request_queue *q, -unsigned int op,gfp_t gfp_mask) +unsigned int op,unsigned int flags) {struct request *rq; +gfp_t gfp_mask = flags &BLK_MQ_REQ_NOWAIT ?GFP_ATOMIC : + __GFP_DIRECT_RECLAIM;int ret =0 ;WARN_ON_ONCE (q->mq_ops);
@@ -1410,7 +1415,7 @@ static struct request *blk_old_get_request(struct request_queue *q,if (ret)return ERR_PTR (ret);spin_lock_irq (q->queue_lock); - rq =get_request (q, op,NULL , gfp_mask); + rq =get_request (q, op,NULL , flags);if (IS_ERR (rq)) {spin_unlock_irq (q->queue_lock);blk_queue_exit (q);
@@ -1424,25 +1429,40 @@ static struct request *blk_old_get_request(struct request_queue *q,return rq; } -struct request *blk_get_request (struct request_queue *q,unsigned int op, -gfp_t gfp_mask) +/** +* blk_get_request_flags - allocate a request +* @q: request queue to allocate a request for +* @op: operation (REQ_OP_*) and REQ_* flags, e.g. REQ_SYNC. +* @flags: BLK_MQ_REQ_* flags, e.g. BLK_MQ_REQ_NOWAIT. +*/ +struct request *blk_get_request_flags (struct request_queue *q,unsigned int op, +unsigned int flags) {struct request *req; +WARN_ON_ONCE (op &REQ_NOWAIT ); +WARN_ON_ONCE (flags & ~BLK_MQ_REQ_NOWAIT ); +if (q->mq_ops) { - req =blk_mq_alloc_request (q, op, - (gfp_mask & __GFP_DIRECT_RECLAIM) ? -0 :BLK_MQ_REQ_NOWAIT ); + req =blk_mq_alloc_request (q, op, flags);if (!IS_ERR (req) && q->mq_ops->initialize_rq_fn) q->mq_ops->initialize_rq_fn (req); }else { - req =blk_old_get_request (q, op, gfp_mask); + req =blk_old_get_request (q, op, flags);if (!IS_ERR (req) && q->initialize_rq_fn) q->initialize_rq_fn (req); }return req; } +EXPORT_SYMBOL (blk_get_request_flags); + +struct request *blk_get_request (struct request_queue *q,unsigned int op, +gfp_t gfp_mask) +{ +return blk_get_request_flags (q, op, gfp_mask & __GFP_DIRECT_RECLAIM ? +0 :BLK_MQ_REQ_NOWAIT ); +}EXPORT_SYMBOL (blk_get_request);/**
@@ -1868,7 +1888,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)* Returns with the queue unlocked. */ blk_queue_enter_live (q); - req =get_request (q, bio->bi_opf, bio,GFP_NOIO ); + req =get_request (q, bio->bi_opf, bio,0 );if (IS_ERR (req)) {blk_queue_exit (q);__wbt_done (q->rq_wb, wb_acct);
include/linux/blkdev.h +3 -0
@@ -935,6 +935,9 @@ extern void blk_rq_init(struct request_queue *q, struct request *rq);extern void blk_init_request_from_bio (struct request *req,struct bio *bio);extern void blk_put_request (struct request *);extern void __blk_put_request (struct request_queue *,struct request *); +extern struct request *blk_get_request_flags (struct request_queue *, +unsigned int op, +unsigned int flags);extern struct request *blk_get_request (struct request_queue *,unsigned int op,gfp_t gfp_mask);extern void blk_requeue_request (struct request_queue *,struct request *);
Signature · 1 line
2.14.2
PATCH v8 6/10 block: Introduce BLK_MQ_REQ_PREEMPT
In reply to Bart Van AsscheSet RQF_PREEMPT if BLK_MQ_REQ_PREEMPT is passed to blk_get_request_flags().
--- block/blk-core.c | 4 +++- block/blk-mq.c | 2 ++ include/linux/blk-mq.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)
block/blk-core.c +3 -1
@@ -1260,6 +1260,8 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,blk_rq_set_rl (rq, rl); rq->cmd_flags = op; rq->rq_flags = rq_flags; +if (flags &BLK_MQ_REQ_PREEMPT ) + rq->rq_flags |=RQF_PREEMPT ;/* init elvpriv */ if (rq_flags &RQF_ELVPRIV ) {
@@ -1441,7 +1443,7 @@ struct request *blk_get_request_flags(struct request_queue *q, unsigned int op,struct request *req;WARN_ON_ONCE (op &REQ_NOWAIT ); -WARN_ON_ONCE (flags & ~BLK_MQ_REQ_NOWAIT ); +WARN_ON_ONCE (flags & ~(BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PREEMPT ));if (q->mq_ops) { req =blk_mq_alloc_request (q, op, flags);
block/blk-mq.c +2 -0
@@ -290,6 +290,8 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, rq->q = data->q; rq->mq_ctx = data->ctx; rq->cmd_flags = op; +if (data->flags &BLK_MQ_REQ_PREEMPT ) + rq->rq_flags |=RQF_PREEMPT ;if (blk_queue_io_stat (data->q)) rq->rq_flags |=RQF_IO_STAT ;/* do not touch atomic flags, it needs atomic ops against the timer */
include/linux/blk-mq.h +1 -0
@@ -200,6 +200,7 @@ enum {BLK_MQ_REQ_NOWAIT = (1 <<0 ),/* return when out of requests */ BLK_MQ_REQ_RESERVED = (1 <<1 ),/* allocate from reserved pool */ BLK_MQ_REQ_INTERNAL = (1 <<2 ),/* allocate internal/sched tag */ + BLK_MQ_REQ_PREEMPT = (1 << 3), /* set RQF_PREEMPT */ }; struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
Signature · 1 line
2.14.2
PATCH v8 7/10 ide, scsi: Tell the block layer at request allocation time about preempt requests
In reply to Bart Van AsscheConvert blk_get_request(q, op, __GFP_RECLAIM) into blk_get_request_flags(q, op, BLK_MQ_PREEMPT). This patch does not change any functionality.
--- drivers/ide/ide-pm.c | 4 ++-- drivers/scsi/scsi_lib.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/ide/ide-pm.c +2 -2
@@ -89,9 +89,9 @@ int generic_ide_resume(struct device *dev) }memset (&rqpm,0 ,sizeof (rqpm)); - rq =blk_get_request (drive->queue,REQ_OP_DRV_IN , __GFP_RECLAIM); + rq =blk_get_request_flags (drive->queue,REQ_OP_DRV_IN , +BLK_MQ_REQ_PREEMPT );ide_req (rq)->type =ATA_PRIV_PM_RESUME ; - rq->rq_flags |=RQF_PREEMPT ; rq->special = &rqpm; rqpm.pm_step =IDE_PM_START_RESUME ; rqpm.pm_state =PM_EVENT_ON ;
drivers/scsi/scsi_lib.c +3 -3
@@ -252,9 +252,9 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,struct scsi_request *rq;int ret =DRIVER_ERROR <<24 ; - req =blk_get_request (sdev->request_queue, + req =blk_get_request_flags (sdev->request_queue, data_direction ==DMA_TO_DEVICE ? -REQ_OP_SCSI_OUT :REQ_OP_SCSI_IN , __GFP_RECLAIM); +REQ_OP_SCSI_OUT :REQ_OP_SCSI_IN ,BLK_MQ_REQ_PREEMPT );if (IS_ERR (req))return ret; rq =scsi_req (req);
@@ -268,7 +268,7 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, rq->retries = retries; req->timeout = timeout; req->cmd_flags |= flags; - req->rq_flags |= rq_flags |RQF_QUIET |RQF_PREEMPT ; + req->rq_flags |= rq_flags |RQF_QUIET ;/* * head injection *required* here otherwise quiesce won't work
Signature · 1 line
2.14.2
PATCH v8 8/10 block: Add the QUEUE_FLAG_PREEMPT_ONLY request queue flag
In reply to Bart Van AsscheThis flag will be used in the next patch to let the block layer core know whether or not a SCSI request queue has been quiesced. A quiesced SCSI queue namely only processes RQF_PREEMPT requests.
--- block/blk-core.c | 30 ++++++++++++++++++++++++++++++ block/blk-mq-debugfs.c | 1 + include/linux/blkdev.h | 6 ++++++ 3 files changed, 37 insertions(+)
block/blk-core.c +30 -0
@@ -346,6 +346,36 @@ void blk_sync_queue(struct request_queue *q) }EXPORT_SYMBOL (blk_sync_queue); +/** +* blk_set_preempt_only - set QUEUE_FLAG_PREEMPT_ONLY +* @q: request queue pointer +* +* Returns the previous value of the PREEMPT_ONLY flag - 0 if the flag was not +* set and 1 if the flag was already set. +*/ +int blk_set_preempt_only (struct request_queue *q) +{ +unsigned long flags; +int res; + +spin_lock_irqsave (q->queue_lock, flags); + res =queue_flag_test_and_set (QUEUE_FLAG_PREEMPT_ONLY , q); +spin_unlock_irqrestore (q->queue_lock, flags); + +return res; +} +EXPORT_SYMBOL_GPL (blk_set_preempt_only); + +void blk_clear_preempt_only (struct request_queue *q) +{ +unsigned long flags; + +spin_lock_irqsave (q->queue_lock, flags); +queue_flag_clear (QUEUE_FLAG_PREEMPT_ONLY , q); +spin_unlock_irqrestore (q->queue_lock, flags); +} +EXPORT_SYMBOL_GPL (blk_clear_preempt_only); +/** * __blk_run_queue_uncond - run a queue whether or not it has been stopped * @q: The queue to run
block/blk-mq-debugfs.c +1 -0
@@ -74,6 +74,7 @@ static const char *const blk_queue_flag_name[] = {QUEUE_FLAG_NAME (REGISTERED ),QUEUE_FLAG_NAME (SCSI_PASSTHROUGH ),QUEUE_FLAG_NAME (QUIESCED ), + QUEUE_FLAG_NAME(PREEMPT_ONLY), };#undef QUEUE_FLAG_NAME
include/linux/blkdev.h +6 -0
@@ -630,6 +630,7 @@ struct request_queue {#define QUEUE_FLAG_REGISTERED 26/* queue has been registered to a disk */ #define QUEUE_FLAG_SCSI_PASSTHROUGH 27/* queue supports SCSI commands */ #define QUEUE_FLAG_QUIESCED 28/* queue has been quiesced */ +#define QUEUE_FLAG_PREEMPT_ONLY 29/* only process REQ_PREEMPT requests */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_SAME_COMP) | \
@@ -730,6 +731,11 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) ((rq)->cmd_flags & (REQ_FAILFAST_DEV |REQ_FAILFAST_TRANSPORT | \ REQ_FAILFAST_DRIVER))#define blk_queue_quiesced (q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) +#define blk_queue_preempt_only (q) \ + test_bit(QUEUE_FLAG_PREEMPT_ONLY, &(q)->queue_flags) + +extern int blk_set_preempt_only (struct request_queue *q); +extern void blk_clear_preempt_only (struct request_queue *q);static inline bool blk_account_rq (struct request *rq) {
Signature · 1 line
2.14.2
PATCH v8 9/10 block, scsi: Make SCSI quiesce and resume work reliably
In reply to Bart Van AsscheThe contexts from which a SCSI device can be quiesced or resumed are:
* Writing into /sys/class/scsi_device/*/device/state.
* SCSI parallel (SPI) domain validation.
* The SCSI device power management methods. See also scsi_bus_pm_ops.
It is essential during suspend and resume that neither the filesystem state nor the filesystem metadata in RAM changes. This is why while the hibernation image is being written or restored that SCSI devices are quiesced. The SCSI core quiesces devices through scsi_device_quiesce() and scsi_device_resume(). In the SDEV_QUIESCE state execution of non-preempt requests is deferred. This is realized by returning BLKPREP_DEFER from inside scsi_prep_state_check() for quiesced SCSI devices. Avoid that a full queue prevents power management requests to be submitted by deferring allocation of non-preempt requests for devices in the quiesced state. This patch has been tested by running the following commands and by verifying that after resume the fio job is still running:
for d in /sys/class/block/sd*[a-z]; do
hcil=$(readlink "$d/device")
hcil=${hcil#../../../}
echo 4 > "$d/queue/nr_requests"
echo 1 > "/sys/class/scsi_device/$hcil/device/queue_depth"
done
bdev=$(readlink /dev/disk/by-uuid/5217d83f-213e-4b42-b86e-20013325ba6c) bdev=${bdev#../../}
hcil=$(readlink "/sys/block/$bdev/device")
hcil=${hcil#../../../}
fio --name="$bdev" --filename="/dev/$bdev" --buffered=0 --bs=512 --rw=randread \
--ioengine=libaio --numjobs=4 --iodepth=16 --iodepth_batch=1 --thread \
--loops=$((2**31)) &
pid=$!
sleep 1
systemctl hibernate
sleep 10
kill $pid
References: "I/O hangs after resuming from suspend-to-ram" (https://marc.info/?l=linux-block&m=150340235201348).
--- block/blk-core.c | 42 +++++++++++++++++++++++++++++++++++------- block/blk-mq.c | 4 ++-- block/blk-timeout.c | 2 +- drivers/scsi/scsi_lib.c | 29 +++++++++++++++++++---------- fs/block_dev.c | 4 ++-- include/linux/blkdev.h | 2 +- 6 files changed, 60 insertions(+), 23 deletions(-)
block/blk-core.c +35 -7
@@ -372,6 +372,7 @@ void blk_clear_preempt_only(struct request_queue *q)spin_lock_irqsave (q->queue_lock, flags);queue_flag_clear (QUEUE_FLAG_PREEMPT_ONLY , q); +wake_up_all (&q->mq_freeze_wq);spin_unlock_irqrestore (q->queue_lock, flags); }EXPORT_SYMBOL_GPL (blk_clear_preempt_only);
@@ -793,15 +794,40 @@ struct request_queue *blk_alloc_queue(gfp_t gfp_mask) }EXPORT_SYMBOL (blk_alloc_queue); -int blk_queue_enter (struct request_queue *q,bool nowait) +/** +* blk_queue_enter() - try to increase q->q_usage_counter +* @q: request queue pointer +* @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PREEMPT +*/ +int blk_queue_enter (struct request_queue *q,unsigned int flags) { +const bool preempt = flags &BLK_MQ_REQ_PREEMPT ; +while (true) { +bool success = false;int ret; -if (percpu_ref_tryget_live (&q->q_usage_counter)) +rcu_read_lock_sched (); +if (percpu_ref_tryget_live (&q->q_usage_counter)) { +/* +* The code that sets the PREEMPT_ONLY flag is +* responsible for ensuring that that flag is globally +* visible before the queue is unfrozen. +*/ +if (preempt || !blk_queue_preempt_only (q)) { + success = true; + }else { +percpu_ref_put (&q->q_usage_counter); +WARN_ONCE ("%s: Attempt to allocate non-preempt request in preempt-only mode.\n" , +kobject_name (q->kobj.parent)); + } + } +rcu_read_unlock_sched (); + +if (success)return 0 ; -if (nowait) +if (flags &BLK_MQ_REQ_NOWAIT )return -EBUSY ;/*
@@ -814,7 +840,8 @@ int blk_queue_enter(struct request_queue *q, bool nowait)smp_rmb (); ret =wait_event_interruptible (q->mq_freeze_wq, - !atomic_read (&q->mq_freeze_depth) || + (atomic_read (&q->mq_freeze_depth) ==0 && + (preempt || !blk_queue_preempt_only (q))) ||blk_queue_dying (q));if (blk_queue_dying (q))return -ENODEV ;
@@ -1442,8 +1469,7 @@ static struct request *blk_old_get_request(struct request_queue *q,/* create ioc upfront */ create_io_context (gfp_mask, q->node); - ret =blk_queue_enter (q, !(gfp_mask & __GFP_DIRECT_RECLAIM) || - (op &REQ_NOWAIT )); + ret =blk_queue_enter (q, flags);if (ret)return ERR_PTR (ret);spin_lock_irq (q->queue_lock);
@@ -2264,8 +2290,10 @@ blk_qc_t generic_make_request(struct bio *bio) current->bio_list = bio_list_on_stack; do { struct request_queue *q = bio->bi_disk->queue; + unsigned int flags = bio->bi_opf & REQ_NOWAIT ? + BLK_MQ_REQ_NOWAIT : 0; - if (likely(blk_queue_enter(q, bio->bi_opf & REQ_NOWAIT) == 0)) { + if (likely(blk_queue_enter(q, flags) == 0)) { struct bio_list lower, same; /* Create a fresh bio_list for all subordinate requests */
block/blk-mq.c +2 -2
@@ -386,7 +386,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,struct request *rq;int ret; - ret =blk_queue_enter (q, flags &BLK_MQ_REQ_NOWAIT ); + ret =blk_queue_enter (q, flags);if (ret)return ERR_PTR (ret);
@@ -425,7 +425,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,if (hctx_idx >= q->nr_hw_queues)return ERR_PTR (-EIO ); - ret =blk_queue_enter (q, true); + ret =blk_queue_enter (q, flags);if (ret)return ERR_PTR (ret);
block/blk-timeout.c +1 -1
@@ -134,7 +134,7 @@ void blk_timeout_work(struct work_struct *work)struct request *rq, *tmp;int next_set =0 ; -if (blk_queue_enter (q, true)) +if (blk_queue_enter (q,BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PREEMPT ))return ;spin_lock_irqsave (q->queue_lock, flags);
drivers/scsi/scsi_lib.c +19 -10
@@ -2926,21 +2926,30 @@ static void scsi_wait_for_queuecommand(struct scsi_device *sdev)int scsi_device_quiesce (struct scsi_device *sdev) { +struct request_queue *q = sdev->request_queue;int err; +/* If the SCSI device has already been quiesced, do nothing. */ +if (blk_set_preempt_only (q)) +return 0 ; + +blk_mq_freeze_queue (q); +/* +* Ensure that the effect of blk_set_preempt_only() will be visible +* for percpu_ref_tryget() callers that occur after the queue +* unfreeze even if the queue was already frozen before this function +* was called. See also https://lwn.net/Articles/573497/. +*/ +synchronize_rcu (); +blk_mq_unfreeze_queue (q); +mutex_lock (&sdev->state_mutex); err =scsi_device_set_state (sdev,SDEV_QUIESCE ); -mutex_unlock (&sdev->state_mutex); -if (err) -return err; +blk_clear_preempt_only (q); +mutex_unlock (&sdev->state_mutex); -scsi_run_queue (sdev->request_queue); -while (atomic_read (&sdev->device_busy)) { -msleep_interruptible (200 ); -scsi_run_queue (sdev->request_queue); - } -return 0 ; +return err; }EXPORT_SYMBOL (scsi_device_quiesce);
@@ -2962,7 +2971,7 @@ void scsi_device_resume(struct scsi_device *sdev)mutex_lock (&sdev->state_mutex);if (sdev->sdev_state ==SDEV_QUIESCE &&scsi_device_set_state (sdev,SDEV_RUNNING ) ==0 ) -scsi_run_queue (sdev->request_queue); +blk_clear_preempt_only (sdev->request_queue);mutex_unlock (&sdev->state_mutex); }EXPORT_SYMBOL (scsi_device_resume);
fs/block_dev.c +2 -2
@@ -674,7 +674,7 @@ int bdev_read_page(struct block_device *bdev, sector_t sector,if (!ops->rw_page ||bdev_get_integrity (bdev))return result; - result =blk_queue_enter (bdev->bd_queue, false); + result =blk_queue_enter (bdev->bd_queue,0 );if (result)return result; result = ops->rw_page (bdev, sector +get_start_sect (bdev), page, false);
@@ -710,7 +710,7 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,if (!ops->rw_page ||bdev_get_integrity (bdev))return -EOPNOTSUPP ; - result =blk_queue_enter (bdev->bd_queue, false); + result =blk_queue_enter (bdev->bd_queue,0 );if (result)return result;
include/linux/blkdev.h +1 -1
@@ -967,7 +967,7 @@ extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,extern int sg_scsi_ioctl (struct request_queue *,struct gendisk *,fmode_t ,struct scsi_ioctl_command __user *); -extern int blk_queue_enter (struct request_queue *q,bool nowait); +extern int blk_queue_enter (struct request_queue *q,unsigned int flags);extern void blk_queue_exit (struct request_queue *q);extern void blk_start_queue (struct request_queue *q);extern void blk_start_queue_async (struct request_queue *q);
Signature · 1 line
2.14.2
PATCH v8 10/10 block, nvme: Introduce blk_mq_req_flags_t
In reply to Bart Van AsscheSeveral block layer and NVMe core functions accept a combination of BLK_MQ_REQ_* flags through the 'flags' argument but there is no verification at compile time whether the right type of block layer flags is passed. Make it possible for sparse to verify this. This patch does not change any functionality.
--- block/blk-core.c | 12 ++++++------ block/blk-mq.c | 4 ++-- block/blk-mq.h | 2 +- drivers/nvme/host/core.c | 5 +++-- drivers/nvme/host/nvme.h | 5 +++-- include/linux/blk-mq.h | 17 +++++++++++------ include/linux/blk_types.h | 2 ++ include/linux/blkdev.h | 4 ++-- 8 files changed, 30 insertions(+), 21 deletions(-)
block/blk-core.c +6 -6
@@ -799,7 +799,7 @@ EXPORT_SYMBOL(blk_alloc_queue);* @q: request queue pointer * @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PREEMPT */ -int blk_queue_enter (struct request_queue *q,unsigned int flags) +int blk_queue_enter (struct request_queue *q,blk_mq_req_flags_t flags) {const bool preempt = flags &BLK_MQ_REQ_PREEMPT ;
@@ -1224,7 +1224,7 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr)* Returns request pointer on success, with @q->queue_lock *not held*. */ static struct request *__get_request (struct request_list *rl,unsigned int op, -struct bio *bio,unsigned int flags) +struct bio *bio,blk_mq_req_flags_t flags) {struct request_queue *q = rl->q;struct request *rq;
@@ -1407,7 +1407,7 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,* Returns request pointer on success, with @q->queue_lock *not held*. */ static struct request *get_request (struct request_queue *q,unsigned int op, -struct bio *bio,unsigned int flags) +struct bio *bio,blk_mq_req_flags_t flags) {const bool is_sync =op_is_sync (op);DEFINE_WAIT (wait);
@@ -1457,7 +1457,7 @@ static struct request *get_request(struct request_queue *q, unsigned int op,/* flags: BLK_MQ_REQ_PREEMPT and/or BLK_MQ_REQ_NOWAIT. */ static struct request *blk_old_get_request (struct request_queue *q, -unsigned int op,unsigned int flags) +unsigned int op,blk_mq_req_flags_t flags) {struct request *rq; gfp_t gfp_mask = flags & BLK_MQ_REQ_NOWAIT ? GFP_ATOMIC :
@@ -1494,7 +1494,7 @@ static struct request *blk_old_get_request(struct request_queue *q,* @flags: BLK_MQ_REQ_* flags, e.g. BLK_MQ_REQ_NOWAIT. */ struct request *blk_get_request_flags (struct request_queue *q,unsigned int op, -unsigned int flags) +blk_mq_req_flags_t flags) {struct request *req;
@@ -2290,7 +2290,7 @@ blk_qc_t generic_make_request(struct bio *bio) current->bio_list = bio_list_on_stack; do { struct request_queue *q = bio->bi_disk->queue; - unsigned int flags = bio->bi_opf & REQ_NOWAIT ? + blk_mq_req_flags_t flags = bio->bi_opf & REQ_NOWAIT ? BLK_MQ_REQ_NOWAIT : 0; if (likely(blk_queue_enter(q, flags) == 0)) {
block/blk-mq.c +2 -2
@@ -380,7 +380,7 @@ static struct request *blk_mq_get_request(struct request_queue *q, }struct request *blk_mq_alloc_request (struct request_queue *q,unsigned int op, -unsigned int flags) +blk_mq_req_flags_t flags) {struct blk_mq_alloc_data alloc_data = { .flags = flags };struct request *rq;
@@ -406,7 +406,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,EXPORT_SYMBOL (blk_mq_alloc_request);struct request *blk_mq_alloc_request_hctx (struct request_queue *q, -unsigned int op,unsigned int flags,unsigned int hctx_idx) +unsigned int op,blk_mq_req_flags_t flags,unsigned int hctx_idx) {struct blk_mq_alloc_data alloc_data = { .flags = flags };struct request *rq;
block/blk-mq.h +1 -1
@@ -108,7 +108,7 @@ static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)struct blk_mq_alloc_data {/* input parameter */ struct request_queue *q; -unsigned int flags; +blk_mq_req_flags_t flags;unsigned int shallow_depth;/* input & output parameter */
drivers/nvme/host/core.c +3 -2
@@ -292,7 +292,7 @@ static struct nvme_ns *nvme_get_ns_from_disk(struct gendisk *disk) }struct request *nvme_alloc_request (struct request_queue *q, -struct nvme_command *cmd,unsigned int flags,int qid) +struct nvme_command *cmd,blk_mq_req_flags_t flags,int qid) {unsigned op =nvme_is_write (cmd) ?REQ_OP_DRV_OUT :REQ_OP_DRV_IN ;struct request *req;
@@ -560,7 +560,8 @@ EXPORT_SYMBOL_GPL(nvme_setup_cmd);*/ int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen, -unsigned timeout,int qid,int at_head,int flags) +unsigned timeout,int qid,int at_head, +blk_mq_req_flags_t flags) {struct request *req;int ret;
drivers/nvme/host/nvme.h +3 -2
@@ -314,14 +314,15 @@ void nvme_start_freeze(struct nvme_ctrl *ctrl);#define NVME_QID_ANY -1struct request *nvme_alloc_request (struct request_queue *q, -struct nvme_command *cmd,unsigned int flags,int qid); +struct nvme_command *cmd,blk_mq_req_flags_t flags,int qid);blk_status_t nvme_setup_cmd (struct nvme_ns *ns,struct request *req,struct nvme_command *cmd);int nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,void *buf,unsigned bufflen);int __nvme_submit_sync_cmd (struct request_queue *q,struct nvme_command *cmd,union nvme_result *result,void *buffer,unsigned bufflen, -unsigned timeout,int qid,int at_head,int flags); +unsigned timeout,int qid,int at_head, +blk_mq_req_flags_t flags);int nvme_set_queue_count (struct nvme_ctrl *ctrl,int *count);void nvme_start_keep_alive (struct nvme_ctrl *ctrl);void nvme_stop_keep_alive (struct nvme_ctrl *ctrl);
include/linux/blk-mq.h +11 -6
@@ -197,16 +197,21 @@ void blk_mq_free_request(struct request *rq);bool blk_mq_can_queue (struct blk_mq_hw_ctx *);enum { -BLK_MQ_REQ_NOWAIT = (1 <<0 ),/* return when out of requests */ -BLK_MQ_REQ_RESERVED = (1 <<1 ),/* allocate from reserved pool */ -BLK_MQ_REQ_INTERNAL = (1 <<2 ),/* allocate internal/sched tag */ -BLK_MQ_REQ_PREEMPT = (1 <<3 ),/* set RQF_PREEMPT */ +/* return when out of requests */ +BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 <<0 ), +/* allocate from reserved pool */ +BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 <<1 ), +/* allocate internal/sched tag */ +BLK_MQ_REQ_INTERNAL = (__force blk_mq_req_flags_t)(1 <<2 ), +/* set RQF_PREEMPT */ +BLK_MQ_REQ_PREEMPT = (__force blk_mq_req_flags_t)(1 <<3 ), };struct request *blk_mq_alloc_request (struct request_queue *q,unsigned int op, -unsigned int flags); +blk_mq_req_flags_t flags);struct request *blk_mq_alloc_request_hctx (struct request_queue *q, -unsigned int op,unsigned int flags,unsigned int hctx_idx); +unsigned int op,blk_mq_req_flags_t flags, +unsigned int hctx_idx);struct request *blk_mq_tag_to_rq (struct blk_mq_tags *tags,unsigned int tag);enum {
include/linux/blk_types.h +2 -0
@@ -162,6 +162,8 @@ struct bio {*/ #define BIO_RESET_BITS BVEC_POOL_OFFSET +typedef __u32 __bitwise blk_mq_req_flags_t ; +/* * Operations and flags common to the bio and request structures. * We use 8 bits for encoding the operation, and the remaining 24 for flags.
include/linux/blkdev.h +2 -2
@@ -943,7 +943,7 @@ extern void blk_put_request(struct request *);extern void __blk_put_request (struct request_queue *,struct request *);extern struct request *blk_get_request_flags (struct request_queue *,unsigned int op, -unsigned int flags); +blk_mq_req_flags_t flags);extern struct request *blk_get_request (struct request_queue *,unsigned int op,gfp_t gfp_mask);extern void blk_requeue_request (struct request_queue *,struct request *);
@@ -967,7 +967,7 @@ extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,extern int sg_scsi_ioctl (struct request_queue *,struct gendisk *,fmode_t ,struct scsi_ioctl_command __user *); -extern int blk_queue_enter (struct request_queue *q,unsigned int flags); +extern int blk_queue_enter (struct request_queue *q,blk_mq_req_flags_t flags);extern void blk_queue_exit (struct request_queue *q);extern void blk_start_queue (struct request_queue *q);extern void blk_start_queue_async (struct request_queue *q);
Signature · 1 line
2.14.2
Re: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
In reply to Bart Van AsscheQuoted 9 lines · Bart Van Assche
Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before a hibernation image is created, interrupt the md resync and reshape actions if the system is being frozen. Note: the resync and reshape will restart after the system is resumed and a message similar to the following will appear in the system log:
md: md0: data-check interrupted.
Where do we restart resync and reshape?
Quoted 90 lines
Signed-off-by Bart Van Assche <[email protected]>Cc Shaohua Li <[email protected]>Cc Ming Lei <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/md/md.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)drivers/md/md.c +29
-1@@ -66,6 +66,8 @@#include <linux/raid/md_u.h> #include <linux/slab.h> #include <linux/percpu-refcount.h> +#include <linux/freezer.h> +#include <linux/suspend.h> #include <trace/events/block.h> #include "md.h" @@ -7439,6 +7441,7 @@ static int md_thread(void *arg)*/ allow_signal (SIGKILL ); +set_freezable ();while (!kthread_should_stop ()) {/* We need to wait INTERRUPTIBLE so that @@ -7449,7 +7452,7 @@ static int md_thread(void *arg)if (signal_pending (current))flush_signals (current); - wait_event_interruptible_timeout + wait_event_freezable_timeout (thread->wqueue, test_bit(THREAD_WAKEUP, &thread->flags) || kthread_should_stop() || kthread_should_park(),@@ -8963,6 +8966,29 @@ static void md_stop_all_writes(void)mdelay (1000 *1 ); } +/* +* Ensure that neither resyncing nor reshaping occurs while the system is +* frozen. +*/ +static int md_notify_pm (struct notifier_block *bl,unsigned long state, +void *unused) +{ +pr_debug ("%s: state = %ld\n" , __func__, state); + +switch (state) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +case PM_RESTORE_PREPARE : +md_stop_all_writes (); +break ; + } +return NOTIFY_DONE ; +} + +static struct notifier_block md_pm_notifier = { + .notifier_call = md_notify_pm, +}; +static int md_notify_reboot (struct notifier_block *this,unsigned long code,void *x) {@@ -9009,6 +9035,7 @@ static int __init md_init(void) md_probe, NULL, NULL);register_reboot_notifier (&md_reboot_notifier); +register_pm_notifier (&md_pm_notifier); raid_table_header =register_sysctl_table (raid_root_table);md_geninit ();@@ -9248,6 +9275,7 @@ static __exit void md_exit(void)unregister_blkdev (MD_MAJOR ,"md" );unregister_blkdev (mdp_major,"mdp" ); +unregister_pm_notifier (&md_pm_notifier);unregister_reboot_notifier (&md_reboot_notifier);unregister_sysctl_table (raid_table_header);Signature · 1 line
2.14.2
Re: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
T24gVHVlLCAyMDE3LTEwLTEwIGF0IDE1OjMwIC0wNzAwLCBTaGFvaHVhIExpIHdyb3RlOg0KPiBP biBUdWUsIE9jdCAxMCwgMjAxNyBhdCAwMjowMzozOVBNIC0wNzAwLCBCYXJ0IFZhbiBBc3NjaGUg d3JvdGU6DQo+ID4gU29tZSBwZW9wbGUgdXNlIHRoZSBtZCBkcml2ZXIgb24gbGFwdG9wcyBhbmQg dXNlIHRoZSBzdXNwZW5kIGFuZA0KPiA+IHJlc3VtZSBmdW5jdGlvbmFsaXR5LiBTaW5jZSBpdC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
Re: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
Quoted 31 lines · Bart Van Assche
Quoted 9 lines · Shaohua Li
Quoted 8 lines · Bart Van Assche
Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before a hibernation image is created, interrupt the md resync and reshape actions if the system is being frozen. Note: the resync and reshape will restart after the system is resumed and a message similar to the following will appear in the system log:
Quoted 3 lines
Quoted 1 line
md: md0: data-check interrupted.
Where do we restart resync and reshape?
Hello Shaohua,
My understanding of the md driver is as follows:
- Before any write occurs,md_write_start()is called. That function clearsmddev->safemodeand checksmddev->in_sync. If that variable is set, it is cleared andmd_write_start()wakes upmddev->threadand waits until the superblock has been written to disk.
- Allmddev->threadimplementations callmd_check_recovery(). That function updates the superblock by callingmd_update_sb()if needed.md_check_recovery()also starts a resync thread if the array is not in sync. See also the comment block abovemd_check_recovery().
-md_do_sync()performs the resync. If it completes successfully the "in_sync" state is set (set_in_sync()). If it is interrupted the "in_sync" state is not modified.
-super_90_sync()sets theMD_SB_CLEANflag in the on-disk superblock if the "in_sync" flag is set.
Quoted 4 lines
In other words: if the array is in sync the
MD_SB_CLEANflag is set in the on-disk superblock. If a resync is needed that flag is not set. TheMD_SB_CLEANflag is checked when the superblock is loaded. If that flag is not set a resync is started.
The problem is __md_stop_writes set some bit like MD_RECOVERY_FROZEN, which will prevent md_check_recovery restarting resync/reshape. I think we need preserve mddev->recovery in suspend prepare and restore after resume
Thanks,
Shaohua
Re: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
T24gVHVlLCAyMDE3LTEwLTEwIGF0IDE4OjQ4IC0wNzAwLCBTaGFvaHVhIExpIHdyb3RlOg0KPiBU aGUgcHJvYmxlbSBpcyBfX21kX3N0b3Bfd3JpdGVzIHNldCBzb21lIGJpdCBsaWtlIE1EX1JFQ09W RVJZX0ZST1pFTiwgd2hpY2gNCj4gd2lsbCBwcmV2ZW50IG1kX2NoZWNrX3JlY292ZXJ5IHJlc3Rh cn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lcnMgYW5kIGhlbmNlIHRoYXQgdGhl DQpwYXRjaCBhdCB0aGUgc3RhcnQgb2YgdGhpcyBlLW1haWwgdGhyZWFkIGRvZXMgbm90IG5lZWQg YW55IGZ1cnRoZXINCm1vZGlmaWNhdGlvbnM/DQoNClRoYW5rcywNCg0KQmFydC4=
Re: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
Quoted 17 lines · Bart Van Assche
Quoted 3 lines · Shaohua Li
The problem is
__md_stop_writesset some bit likeMD_RECOVERY_FROZEN, which will preventmd_check_recoveryrestarting resync/reshape. I think we need preservemddev->recoveryin suspend prepare and restore after resumeHello Shaohua,
As far as I can see
__md_stop_writes()setsMD_RECOVERY_FROZENand can setMD_RECOVERY_INTR. Sincemd_check_recovery()clearsMD_RECOVERY_INTRI think it should be sufficient to save and restore the state of theMD_RECOVERY_FROZENflag. However, when I ran the following test:
* echo frozen >/sys/block/md0/md/sync_action
* cat/sys/block/md0/md/sync_action
* systemctl hibernate
* (power on system again)
* cat/sys/block/md0/md/sync_action
Quoted 8 lines
the output that appeared was as follows:
frozen
idle
Does that mean that a hibernate or suspend followed by a resume is sufficient to clear theMD_RECOVERY_FROZENflag for the md drivers and hence that the patch at the start of this e-mail thread does not need any further modifications?
Have no idea why it shows 'idle'. From my understanding, after resume, previous memory is stored and MD_RECOVERY_FROZEN bit should be set. Was trying to understand what happens.
Thanks,
Shaohua
Re: [PATCH v8 09/10] block, scsi: Make SCSI quiesce and resume work reliably
In reply to Bart Van AsscheQuoted 182 lines · Bart Van Assche
The contexts from which a SCSI device can be quiesced or resumed are:
* Writing into/sys/class/scsi_device/*/device/state.
* SCSI parallel (SPI) domain validation.
* The SCSI device power management methods. See alsoscsi_bus_pm_ops.It is essential during suspend and resume that neither the filesystem state nor the filesystem metadata in RAM changes. This is why while the hibernation image is being written or restored that SCSI devices are quiesced. The SCSI core quiesces devices through
scsi_device_quiesce()andscsi_device_resume(). In theSDEV_QUIESCEstate execution of non-preempt requests is deferred. This is realized by returningBLKPREP_DEFERfrom insidescsi_prep_state_check()for quiesced SCSI devices. Avoid that a full queue prevents power management requests to be submitted by deferring allocation of non-preempt requests for devices in the quiesced state. This patch has been tested by running the following commands and by verifying that after resume the fio job is still running:for d in /sys/class/block/sd*[a-z]; do
hcil=$(readlink "$d/device")
hcil=${hcil#../../../}
echo 4 > "$d/queue/nr_requests"
echo 1 > "/sys/class/scsi_device/$hcil/device/queue_depth"
done
bdev=$(readlink/dev/disk/by-uuid/5217d83f-213e-4b42-b86e-20013325ba6c) bdev=${bdev#../../}
hcil=$(readlink "/sys/block/$bdev/device")
hcil=${hcil#../../../}
fio --name="$bdev" --filename="/dev/$bdev" --buffered=0 --bs=512 --rw=randread \
--ioengine=libaio --numjobs=4 --iodepth=16 --iodepth_batch=1 --thread \
--loops=$((2**31)) &
pid=$!
sleep 1
systemctl hibernate
sleep 10
kill $pidReported-by Oleksandr Natalenko <[email protected]>References: "I/O hangs after resuming from suspend-to-ram" (https://marc.info/?l=linux-block&m=150340235201348).
Signed-off-by Bart Van Assche <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Ming Lei <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- block/blk-core.c | 42 +++++++++++++++++++++++++++++++++++------- block/blk-mq.c | 4 ++-- block/blk-timeout.c | 2 +- drivers/scsi/scsi_lib.c | 29 +++++++++++++++++++---------- fs/block_dev.c | 4 ++-- include/linux/blkdev.h | 2 +- 6 files changed, 60 insertions(+), 23 deletions(-)block/blk-core.c +35
-7@@ -372,6 +372,7 @@ void blk_clear_preempt_only(struct request_queue *q)spin_lock_irqsave (q->queue_lock, flags);queue_flag_clear (QUEUE_FLAG_PREEMPT_ONLY , q); +wake_up_all (&q->mq_freeze_wq);spin_unlock_irqrestore (q->queue_lock, flags); }EXPORT_SYMBOL_GPL (blk_clear_preempt_only);@@ -793,15 +794,40 @@ struct request_queue *blk_alloc_queue(gfp_t gfp_mask) }EXPORT_SYMBOL (blk_alloc_queue); -int blk_queue_enter (struct request_queue *q,bool nowait) +/** +* blk_queue_enter() - try to increase q->q_usage_counter +* @q: request queue pointer +* @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PREEMPT +*/ +int blk_queue_enter (struct request_queue *q,unsigned int flags) { +const bool preempt = flags &BLK_MQ_REQ_PREEMPT ; +while (true) { +bool success = false;int ret; -if (percpu_ref_tryget_live (&q->q_usage_counter)) +rcu_read_lock_sched (); +if (percpu_ref_tryget_live (&q->q_usage_counter)) { +/* +* The code that sets the PREEMPT_ONLY flag is +* responsible for ensuring that that flag is globally +* visible before the queue is unfrozen. +*/ +if (preempt || !blk_queue_preempt_only (q)) { + success = true; + }else { +percpu_ref_put (&q->q_usage_counter); +WARN_ONCE ("%s: Attempt to allocate non-preempt request in preempt-only mode.\n" , +kobject_name (q->kobj.parent)); + } + } +rcu_read_unlock_sched (); + +if (success)return 0 ; -if (nowait) +if (flags &BLK_MQ_REQ_NOWAIT )return -EBUSY ;/* @@ -814,7 +840,8 @@ int blk_queue_enter(struct request_queue *q, bool nowait)smp_rmb (); ret =wait_event_interruptible (q->mq_freeze_wq, - !atomic_read (&q->mq_freeze_depth) || + (atomic_read (&q->mq_freeze_depth) ==0 && + (preempt || !blk_queue_preempt_only (q))) ||blk_queue_dying (q));if (blk_queue_dying (q))return -ENODEV ;@@ -1442,8 +1469,7 @@ static struct request *blk_old_get_request(struct request_queue *q,/* create ioc upfront */ create_io_context (gfp_mask, q->node); - ret =blk_queue_enter (q, !(gfp_mask & __GFP_DIRECT_RECLAIM) || - (op &REQ_NOWAIT )); + ret =blk_queue_enter (q, flags);if (ret)return ERR_PTR (ret);spin_lock_irq (q->queue_lock);@@ -2264,8 +2290,10 @@ blk_qc_t generic_make_request(struct bio *bio) current->bio_list = bio_list_on_stack; do { struct request_queue *q = bio->bi_disk->queue; + unsigned int flags = bio->bi_opf & REQ_NOWAIT ? + BLK_MQ_REQ_NOWAIT : 0; - if (likely(blk_queue_enter(q, bio->bi_opf & REQ_NOWAIT) == 0)) { + if (likely(blk_queue_enter(q, flags) == 0)) { struct bio_list lower, same; /* Create a fresh bio_list for all subordinate requests */block/blk-mq.c +2
-2@@ -386,7 +386,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,struct request *rq;int ret; - ret =blk_queue_enter (q, flags &BLK_MQ_REQ_NOWAIT ); + ret =blk_queue_enter (q, flags);if (ret)return ERR_PTR (ret);@@ -425,7 +425,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,if (hctx_idx >= q->nr_hw_queues)return ERR_PTR (-EIO ); - ret =blk_queue_enter (q, true); + ret =blk_queue_enter (q, flags);if (ret)return ERR_PTR (ret);block/blk-timeout.c +1
-1@@ -134,7 +134,7 @@ void blk_timeout_work(struct work_struct *work)struct request *rq, *tmp;int next_set =0 ; -if (blk_queue_enter (q, true)) +if (blk_queue_enter (q,BLK_MQ_REQ_NOWAIT |BLK_MQ_REQ_PREEMPT ))return ;spin_lock_irqsave (q->queue_lock, flags);drivers/scsi/scsi_lib.c +0
-0
drivers/scsi/scsi_lib.c static void scsi_wait_for_queuecommand(struct scsi_device *sdev) · line 2934
Quoted 9 lines
drivers/scsi/scsi_lib.c +4
-0@@ -2926,21 +2926,30 @@ static void scsi_wait_for_queuecommand(struct scsi_device *sdev)int scsi_device_quiesce (struct scsi_device *sdev) { +struct request_queue *q = sdev->request_queue;int err; +/* If the SCSI device has already been quiesced, do nothing. */ +if (blk_set_preempt_only (q)) +return 0 ;
Last time, I have mentioned that this way isn't safe, especially the SCSI domain command can be sent concurrently, also there might be issue wrt. runtime PM vs. system suspend.
The issue should have been avoided simply by setting the flag and continue to freeze queue.
drivers/scsi/scsi_lib.c static void scsi_wait_for_queuecommand(struct scsi_device *sdev) · line 2943
Quoted 9 lines
drivers/scsi/scsi_lib.c +9
-0+ +blk_mq_freeze_queue (q); +/* +* Ensure that the effect of blk_set_preempt_only() will be visible +* for percpu_ref_tryget() callers that occur after the queue +* unfreeze even if the queue was already frozen before this function +* was called. See also https://lwn.net/Articles/573497/. +*/ +synchronize_rcu ();
No, it is a bad idea to do two synchronize_rcu() which can be very slow, especially in big machine, this way may slow down suspend much.
Signature · 1 line
Ming
Re: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
In reply to Shaohua LiT24gV2VkLCAyMDE3LTEwLTExIGF0IDEyOjMyIC0wNzAwLCBTaGFvaHVhIExpIHdyb3RlOg0KPiBP biBXZWQsIE9jdCAxMSwgMjAxNyBhdCAwNToxNzo1NlBNICswMDAwLCBCYXJ0IFZhbiBBc3NjaGUg d3JvdGU6DQo+ID4gT24gVHVlLCAyMDE3LTEwLTEwIGF0IDE4OjQ4IC0wNzAwLCBTaGFvaHVhIExp IHdyb3RlOg0KPiA+ID4gVGhlIHByb2JsZW0gaXMgX19tZF9zdG9wX3dyaXRlcyBzZXQgc29tZSBi aXQgbGlrZSBNRF9SRUNPVkVSWV9GUk9aRU4sIHdoaWNoDQo+ID4gPiB3aWxsIHByZXZlbnQgbWRf Y2hlY2tfcmVjb3ZlcnkgcmVzdGFydGluZyByZXN5bmMvcmVzaGFwZS4gSSB0aGluayB3ZSBuZWVk DQo+ID4gPiBwcmVzZXJ2ZSBtZGRldi0+cmVjb3ZlcnkgaW4gc3VzcGVuZCBwcmVwYXJlIGFuZCBy ZXN0b3JlIGFmdGVyIHJlc3VtZQ0KPiA+IA0KPiA+IEhlbGxvIFNoYW9odWEsDQo+ID4gDQo+ID4g QXMgZmFyIGFzIEkgY2FuIHNlZSBfX21kX3N0b3Bfd3JpdGVzKCkgc2V0cyBNRF9SRUNPVkVSWV9G Uk9aRU4gYW5kIGNhbiBzZXQNCj4gPiBNRF9SRUNPVkVSWV9JTlRSLiBTaW5jZSBtZF9jaGVja19y ZWNvdmVyeSgpIGNsZWFycyBNRF9SRUNPVkVSWV9JTlRSIEkgdGhpbmsNCj4gPiBpdCBzaG91bGQg YmUgc3VmZmljaWVudCB0byB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nQu
Shaohua Li
Reviewed-byRe: [PATCH v8 03/10] md: Neither resync nor reshape while the system is frozen
In reply to Bart Van AsscheQuoted 48 lines · Bart Van Assche
Quoted 27 lines · Shaohua Li
Quoted 17 lines · Bart Van Assche
Quoted 3 lines · Shaohua Li
The problem is
__md_stop_writesset some bit likeMD_RECOVERY_FROZEN, which will preventmd_check_recoveryrestarting resync/reshape. I think we need preservemddev->recoveryin suspend prepare and restore after resumeHello Shaohua,
As far as I can see
__md_stop_writes()setsMD_RECOVERY_FROZENand can setMD_RECOVERY_INTR. Sincemd_check_recovery()clearsMD_RECOVERY_INTRI think it should be sufficient to save and restore the state of theMD_RECOVERY_FROZENflag. However, when I ran the following test:
* echo frozen >/sys/block/md0/md/sync_action
* cat/sys/block/md0/md/sync_action
* systemctl hibernate
* (power on system again)
* cat/sys/block/md0/md/sync_actionQuoted 8 lines
the output that appeared was as follows:
frozen
idle
Does that mean that a hibernate or suspend followed by a resume is sufficient to clear theMD_RECOVERY_FROZENflag for the md drivers and hence that the patch at the start of this e-mail thread does not need any further modifications?Quoted 3 lines
Have no idea why it shows 'idle'. From my understanding, after resume, previous memory is stored and
MD_RECOVERY_FROZENbit should be set. Was trying to understand what happens.Hello Shaohua,
I think a user space action causes the
MD_RECOVERY_FROZENbit to be cleared. After I had added a few debug statements in the md driver this is what I found in the system log:Oct 12 09:38:39 kernel: action_store: storing action check Oct 12 09:38:39 kernel: md: data-check of RAID array md0 Oct 12 09:38:40 systemd[1]: Starting Hibernate... Oct 12 09:38:40 kernel: md: md0: data-check interrupted. [ powered on system manually ] Oct 12 09:39:05 kernel: action_store: storing action check Oct 12 09:39:05 kernel: md: data-check of RAID array md0 Oct 12 09:39:11 kernel: action_store: storing action idle Oct 12 09:39:11 kernel: md: md0: data-check interrupted.
Quoted 2 lines
Anyway, how about the patch below? I have verified by adding a debug
pr_info()statement that the newly added code really clears theMD_RECOVERY_FROZENbit.
Ok, for patch 1-3:
Quoted 146 lines
Subject: [PATCH] md: Neither resync nor reshape while the system is frozen
Some people use the md driver on laptops and use the suspend and resume functionality. Since it is essential that submitting of new I/O requests stops before a hibernation image is created, interrupt the md resync and reshape actions if the system is being frozen. Note: the resync and reshape will restart after the system is resumed and a message similar to the following will appear in the system log:
md: md0: data-check interrupted.
Signed-off-by Bart Van Assche <[email protected]>Cc Shaohua Li <[email protected]>Cc Ming Lei <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Johannes Thumshirn <[email protected]>--- drivers/md/md.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- drivers/md/md.h | 8 ++++++++ 2 files changed, 57 insertions(+), 1 deletion(-)drivers/md/md.c +49
-1@@ -66,6 +66,8 @@#include <linux/raid/md_u.h> #include <linux/slab.h> #include <linux/percpu-refcount.h> +#include <linux/freezer.h> +#include <linux/suspend.h> #include <trace/events/block.h> #include "md.h" @@ -7439,6 +7441,7 @@ static int md_thread(void *arg)*/ allow_signal (SIGKILL ); +set_freezable ();while (!kthread_should_stop ()) {/* We need to wait INTERRUPTIBLE so that @@ -7449,7 +7452,7 @@ static int md_thread(void *arg)if (signal_pending (current))flush_signals (current); - wait_event_interruptible_timeout + wait_event_freezable_timeout (thread->wqueue, test_bit(THREAD_WAKEUP, &thread->flags) || kthread_should_stop() || kthread_should_park(),@@ -8944,6 +8947,8 @@ static void md_stop_all_writes(void)int need_delay =0 ;for_each_mddev (mddev, tmp) { + mddev->frozen_before_suspend = +test_bit (MD_RECOVERY_FROZEN , &mddev->recovery);if (mddev_trylock (mddev)) {if (mddev->pers)__md_stop_writes (mddev);@@ -8963,6 +8968,47 @@ static void md_stop_all_writes(void)mdelay (1000 *1 ); } +static void md_restore_frozen_flag (void ) +{ +struct list_head *tmp; +struct mddev *mddev; + +for_each_mddev (mddev, tmp) { +if (mddev->frozen_before_suspend) +set_bit (MD_RECOVERY_FROZEN , &mddev->recovery); +else +clear_bit (MD_RECOVERY_FROZEN , &mddev->recovery); + } +} + +/* +* Ensure that neither resyncing nor reshaping occurs while the system is +* frozen. +*/ +static int md_notify_pm (struct notifier_block *bl,unsigned long state, +void *unused) +{ +pr_debug ("%s: state = %ld\n" , __func__, state); + +switch (state) { +case PM_HIBERNATION_PREPARE : +case PM_SUSPEND_PREPARE : +case PM_RESTORE_PREPARE : +md_stop_all_writes (); +break ; +case PM_POST_HIBERNATION : +case PM_POST_SUSPEND : +case PM_POST_RESTORE : +md_restore_frozen_flag (); +break ; + } +return NOTIFY_DONE ; +} + +static struct notifier_block md_pm_notifier = { + .notifier_call = md_notify_pm, +}; +static int md_notify_reboot (struct notifier_block *this,unsigned long code,void *x) {@@ -9009,6 +9055,7 @@ static int __init md_init(void) md_probe, NULL, NULL);register_reboot_notifier (&md_reboot_notifier); +register_pm_notifier (&md_pm_notifier); raid_table_header =register_sysctl_table (raid_root_table);md_geninit ();@@ -9248,6 +9295,7 @@ static __exit void md_exit(void)unregister_blkdev (MD_MAJOR ,"md" );unregister_blkdev (mdp_major,"mdp" ); +unregister_pm_notifier (&md_pm_notifier);unregister_reboot_notifier (&md_reboot_notifier);unregister_sysctl_table (raid_table_header);drivers/md/md.h +8
-0@@ -356,6 +356,14 @@ struct mddev {*/ int recovery_disabled; +/* Writes are stopped before hibernation, suspend and restore by +* calling md_stop_all_writes(). That function sets the +* MD_RECOVERY_FROZEN flag. The value of that flag is saved before +* writes are stopped such that it can be restored after hibernation, +* suspend or restore have finished. +*/ +bool frozen_before_suspend; +int in_sync;/* know to not need resync */ /* 'open_mutex' avoids races between 'md_open' and 'do_md_stop', so * that we are never stopping an array while it is open.