diff --git a/block/blk-core.c b/block/blk-core.c index a33775cd97be..d3a6da3012a4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1741,8 +1741,12 @@ EXPORT_SYMBOL_GPL(part_round_stats); #ifdef CONFIG_PM static void blk_pm_put_request(struct request *rq) { - if (rq->q->dev && !(rq->rq_flags & RQF_PM) && !--rq->q->nr_pending) - pm_runtime_mark_last_busy(rq->q->dev); + if (rq->q->dev && !(rq->rq_flags & RQF_PM) && + (rq->rq_flags & RQF_PM_ADDED)) { + rq->rq_flags &= ~RQF_PM_ADDED; + if (!--rq->q->nr_pending) + pm_runtime_mark_last_busy(rq->q->dev); + } } #else static inline void blk_pm_put_request(struct request *rq) {} diff --git a/block/elevator.c b/block/elevator.c index 6d94044681f7..335dc50f0081 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -560,15 +560,22 @@ void elv_bio_merged(struct request_queue *q, struct request *rq, #ifdef CONFIG_PM static void blk_pm_requeue_request(struct request *rq) { - if (rq->q->dev && !(rq->rq_flags & RQF_PM)) + if (rq->q->dev && !(rq->rq_flags & RQF_PM) && + (rq->rq_flags & (RQF_PM_ADDED | RQF_FLUSH_SEQ))) { + rq->rq_flags &= ~RQF_PM_ADDED; rq->q->nr_pending--; + } } static void blk_pm_add_request(struct request_queue *q, struct request *rq) { - if (q->dev && !(rq->rq_flags & RQF_PM) && q->nr_pending++ == 0 && - (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING)) - pm_request_resume(q->dev); + if (q->dev && !(rq->rq_flags & RQF_PM)) { + rq->rq_flags |= RQF_PM_ADDED; + if (q->nr_pending++ == 0 && + (q->rpm_status == RPM_SUSPENDED || + q->rpm_status == RPM_SUSPENDING)) + pm_request_resume(q->dev); + } } #else static inline void blk_pm_requeue_request(struct request *rq) {} diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 26f0a62c303c..96f3ff01778f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -128,6 +128,8 @@ typedef __u32 __bitwise req_flags_t; #define RQF_MQ_POLL_SLEPT ((__force req_flags_t)(1 << 20)) /* ->timeout has been called, don't expire again */ #define RQF_TIMED_OUT ((__force req_flags_t)(1 << 21)) +/* increased nr_pending for this request */ +#define RQF_PM_ADDED ((__force req_flags_t)(1 << 22)) /* flags that prevent us from merging requests: */ #define RQF_NOMERGE_FLAGS \