Skip to content

Commit

Permalink
block: drop @tsk from attempt_plug_merge() and explain sync rules
Browse files Browse the repository at this point in the history
attempt_plug_merge() accesses elevator without holding queue_lock and
may call into ->elevator_bio_merge_fn().  The elvator is guaranteed to
be valid because it's accessed iff the plugged list has requests and
elevator is never exited with live requests, so as long as the
elevator method can deal with unlocked access, this is safe.

Explain the sync rules around attempt_plug_merge() and drop the
unnecessary @tsk parameter.

This patch doesn't introduce any functional change.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and axboe committed Oct 19, 2011
1 parent da8303c commit bd87b58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
28 changes: 21 additions & 7 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1203,18 +1203,32 @@ static bool bio_attempt_front_merge(struct request_queue *q,
return true;
}

/*
* Attempts to merge with the plugged list in the current process. Returns
* true if merge was successful, otherwise false.
/**
* attempt_plug_merge - try to merge with %current's plugged list
* @q: request_queue new bio is being queued at
* @bio: new bio being queued
* @request_count: out parameter for number of traversed plugged requests
*
* Determine whether @bio being queued on @q can be merged with a request
* on %current's plugged list. Returns %true if merge was successful,
* otherwise %false.
*
* This function is called without @q->queue_lock; however, elevator is
* accessed iff there already are requests on the plugged list which in
* turn guarantees validity of the elevator.
*
* Note that, on successful merge, elevator operation
* elevator_bio_merged_fn() will be called without queue lock. Elevator
* must be ready for this.
*/
static bool attempt_plug_merge(struct task_struct *tsk, struct request_queue *q,
struct bio *bio, unsigned int *request_count)
static bool attempt_plug_merge(struct request_queue *q, struct bio *bio,
unsigned int *request_count)
{
struct blk_plug *plug;
struct request *rq;
bool ret = false;

plug = tsk->plug;
plug = current->plug;
if (!plug)
goto out;
*request_count = 0;
Expand Down Expand Up @@ -1282,7 +1296,7 @@ void blk_queue_bio(struct request_queue *q, struct bio *bio)
* Check if we can merge with the plugged list before grabbing
* any locks.
*/
if (attempt_plug_merge(current, q, bio, &request_count))
if (attempt_plug_merge(q, bio, &request_count))
return;

spin_lock_irq(q->queue_lock);
Expand Down
6 changes: 6 additions & 0 deletions include/linux/elevator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ struct elevator_ops
elevator_merged_fn *elevator_merged_fn;
elevator_merge_req_fn *elevator_merge_req_fn;
elevator_allow_merge_fn *elevator_allow_merge_fn;

/*
* Used for both plugged list and elevator merging and in the
* former case called without queue_lock. Read comment on top of
* attempt_plug_merge() for details.
*/
elevator_bio_merged_fn *elevator_bio_merged_fn;

elevator_dispatch_fn *elevator_dispatch_fn;
Expand Down

0 comments on commit bd87b58

Please sign in to comment.