block: pm: Fix possible unbalanced nr_pending
When someone calls blk_get_request() and blk_put_request() without invoking blk_execute_rq() in between, nr_pending will be unbalanced. Fix this by adding a flag, namely the RQF_PM_ADDED, to track the usage of nr_pending, so that blk_pm_put_request() won't touch nr_pending if the flag is not set. Extra care should be given to blk_pm_requeue_request(), because blk-flush.c inserts flush requests into queue without calling blk_pm_add_request(), if the flush requests get requeued by LLD, blk_pm_requeue_request() should anyways decrease nr_pending in this situation to keep it balanced. Change-Id: I7baa2049ac532e4fd22a0ce358133ba88266a314 Signed-off-by: Ziqi Chen <ziqichen@codeaurora.org> Signed-off-by: Can Guo <cang@codeaurora.org>
This commit is contained in:
parent
ef299a6053
commit
36a7bd907c
3 changed files with 19 additions and 6 deletions
|
@ -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) {}
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in a new issue