[PATCH] blk: __make_request efficiency

In the case where the request is not able to be merged by the elevator, don't
retake the lock and retry the merge mechanism after allocating a new request.

Instead assume that the chance of a merge remains slim, and now that we've
done most of the work allocating a request we may as well just go with it.

Also be rid of the GFP_ATOMIC allocation: we've got working mempools for the
block layer now, so let's save atomic memory for things like networking.

Lastly, in get_request_wait, do an initial get_request call before going into
the waitqueue. This is reported to help efficiency.

Signed-off-by: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Jens Axboe <axboe@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Nick Piggin and committed by Linus Torvalds 450991bc 69f63c5c

+22 -42
+22 -42
drivers/block/ll_rw_blk.c
··· 1971 static struct request *get_request_wait(request_queue_t *q, int rw, 1972 struct bio *bio) 1973 { 1974 - DEFINE_WAIT(wait); 1975 struct request *rq; 1976 1977 - do { 1978 struct request_list *rl = &q->rq; 1979 1980 prepare_to_wait_exclusive(&rl->wait[rw], &wait, ··· 2000 put_io_context(ioc); 2001 } 2002 finish_wait(&rl->wait[rw], &wait); 2003 - } while (!rq); 2004 2005 return rq; 2006 } ··· 2522 2523 static int __make_request(request_queue_t *q, struct bio *bio) 2524 { 2525 - struct request *req, *freereq = NULL; 2526 int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync; 2527 unsigned short prio; 2528 sector_t sector; ··· 2550 goto end_io; 2551 } 2552 2553 - again: 2554 spin_lock_irq(q->queue_lock); 2555 2556 - if (elv_queue_empty(q)) { 2557 - blk_plug_device(q); 2558 - goto get_rq; 2559 - } 2560 - if (barrier) 2561 goto get_rq; 2562 2563 el_ret = elv_merge(q, &req, bio); ··· 2597 elv_merged_request(q, req); 2598 goto out; 2599 2600 - /* 2601 - * elevator says don't/can't merge. get new request 2602 - */ 2603 - case ELEVATOR_NO_MERGE: 2604 - break; 2605 - 2606 default: 2607 - printk("elevator returned crap (%d)\n", el_ret); 2608 - BUG(); 2609 } 2610 2611 - /* 2612 - * Grab a free request from the freelist - if that is empty, check 2613 - * if we are doing read ahead and abort instead of blocking for 2614 - * a free slot. 2615 - */ 2616 get_rq: 2617 - if (freereq) { 2618 - req = freereq; 2619 - freereq = NULL; 2620 - } else { 2621 - spin_unlock_irq(q->queue_lock); 2622 - if ((freereq = get_request(q, rw, bio, GFP_ATOMIC)) == NULL) { 2623 - /* 2624 - * READA bit set 2625 - */ 2626 - err = -EWOULDBLOCK; 2627 - if (bio_rw_ahead(bio)) 2628 - goto end_io; 2629 - 2630 - freereq = get_request_wait(q, rw, bio); 2631 - } 2632 - goto again; 2633 - } 2634 2635 req->flags |= REQ_CMD; 2636 ··· 2642 req->rq_disk = bio->bi_bdev->bd_disk; 2643 req->start_time = jiffies; 2644 2645 add_request(q, req); 2646 out: 2647 - if (freereq) 2648 - __blk_put_request(q, freereq); 2649 if (sync) 2650 __generic_unplug_device(q); 2651
··· 1971 static struct request *get_request_wait(request_queue_t *q, int rw, 1972 struct bio *bio) 1973 { 1974 struct request *rq; 1975 1976 + rq = get_request(q, rw, bio, GFP_NOIO); 1977 + while (!rq) { 1978 + DEFINE_WAIT(wait); 1979 struct request_list *rl = &q->rq; 1980 1981 prepare_to_wait_exclusive(&rl->wait[rw], &wait, ··· 1999 put_io_context(ioc); 2000 } 2001 finish_wait(&rl->wait[rw], &wait); 2002 + } 2003 2004 return rq; 2005 } ··· 2521 2522 static int __make_request(request_queue_t *q, struct bio *bio) 2523 { 2524 + struct request *req; 2525 int el_ret, rw, nr_sectors, cur_nr_sectors, barrier, err, sync; 2526 unsigned short prio; 2527 sector_t sector; ··· 2549 goto end_io; 2550 } 2551 2552 spin_lock_irq(q->queue_lock); 2553 2554 + if (unlikely(barrier) || elv_queue_empty(q)) 2555 goto get_rq; 2556 2557 el_ret = elv_merge(q, &req, bio); ··· 2601 elv_merged_request(q, req); 2602 goto out; 2603 2604 + /* ELV_NO_MERGE: elevator says don't/can't merge. */ 2605 default: 2606 + ; 2607 } 2608 2609 get_rq: 2610 + /* 2611 + * Grab a free request. This is might sleep but can not fail. 2612 + */ 2613 + spin_unlock_irq(q->queue_lock); 2614 + req = get_request_wait(q, rw, bio); 2615 + /* 2616 + * After dropping the lock and possibly sleeping here, our request 2617 + * may now be mergeable after it had proven unmergeable (above). 2618 + * We don't worry about that case for efficiency. It won't happen 2619 + * often, and the elevators are able to handle it. 2620 + */ 2621 2622 req->flags |= REQ_CMD; 2623 ··· 2663 req->rq_disk = bio->bi_bdev->bd_disk; 2664 req->start_time = jiffies; 2665 2666 + spin_lock_irq(q->queue_lock); 2667 + if (elv_queue_empty(q)) 2668 + blk_plug_device(q); 2669 add_request(q, req); 2670 out: 2671 if (sync) 2672 __generic_unplug_device(q); 2673