Skip to content

Commit 27a84d5

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: refactor generic_make_request
Move all the checks performed on a bio into a new helper, and call it as soon as bio is submitted even if it is a re-submission from ->make_request. We explicitly mark the new helper as beeing non-inlined as the stack usage for printing the block device name in the failure case is quite high and this a patch where we have to be extremely conservative about stack usage. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5a7bbad commit 27a84d5

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

block/blk-core.c

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,31 +1412,8 @@ static inline int bio_check_eod(struct bio *bio, unsigned int nr_sectors)
14121412
return 0;
14131413
}
14141414

1415-
/**
1416-
* generic_make_request - hand a buffer to its device driver for I/O
1417-
* @bio: The bio describing the location in memory and on the device.
1418-
*
1419-
* generic_make_request() is used to make I/O requests of block
1420-
* devices. It is passed a &struct bio, which describes the I/O that needs
1421-
* to be done.
1422-
*
1423-
* generic_make_request() does not return any status. The
1424-
* success/failure status of the request, along with notification of
1425-
* completion, is delivered asynchronously through the bio->bi_end_io
1426-
* function described (one day) else where.
1427-
*
1428-
* The caller of generic_make_request must make sure that bi_io_vec
1429-
* are set to describe the memory buffer, and that bi_dev and bi_sector are
1430-
* set to describe the device address, and the
1431-
* bi_end_io and optionally bi_private are set to describe how
1432-
* completion notification should be signaled.
1433-
*
1434-
* generic_make_request and the drivers it calls may use bi_next if this
1435-
* bio happens to be merged with someone else, and may change bi_dev and
1436-
* bi_sector for remaps as it sees fit. So the values of these fields
1437-
* should NOT be depended on after the call to generic_make_request.
1438-
*/
1439-
static inline void __generic_make_request(struct bio *bio)
1415+
static noinline_for_stack bool
1416+
generic_make_request_checks(struct bio *bio)
14401417
{
14411418
struct request_queue *q;
14421419
int nr_sectors = bio_sectors(bio);
@@ -1515,58 +1492,84 @@ static inline void __generic_make_request(struct bio *bio)
15151492

15161493
/* if bio = NULL, bio has been throttled and will be submitted later. */
15171494
if (!bio)
1518-
return;
1495+
return false;
1496+
15191497
trace_block_bio_queue(q, bio);
1520-
q->make_request_fn(q, bio);
1521-
return;
1498+
return true;
15221499

15231500
end_io:
15241501
bio_endio(bio, err);
1502+
return false;
15251503
}
15261504

1527-
/*
1528-
* We only want one ->make_request_fn to be active at a time,
1529-
* else stack usage with stacked devices could be a problem.
1530-
* So use current->bio_list to keep a list of requests
1531-
* submited by a make_request_fn function.
1532-
* current->bio_list is also used as a flag to say if
1533-
* generic_make_request is currently active in this task or not.
1534-
* If it is NULL, then no make_request is active. If it is non-NULL,
1535-
* then a make_request is active, and new requests should be added
1536-
* at the tail
1505+
/**
1506+
* generic_make_request - hand a buffer to its device driver for I/O
1507+
* @bio: The bio describing the location in memory and on the device.
1508+
*
1509+
* generic_make_request() is used to make I/O requests of block
1510+
* devices. It is passed a &struct bio, which describes the I/O that needs
1511+
* to be done.
1512+
*
1513+
* generic_make_request() does not return any status. The
1514+
* success/failure status of the request, along with notification of
1515+
* completion, is delivered asynchronously through the bio->bi_end_io
1516+
* function described (one day) else where.
1517+
*
1518+
* The caller of generic_make_request must make sure that bi_io_vec
1519+
* are set to describe the memory buffer, and that bi_dev and bi_sector are
1520+
* set to describe the device address, and the
1521+
* bi_end_io and optionally bi_private are set to describe how
1522+
* completion notification should be signaled.
1523+
*
1524+
* generic_make_request and the drivers it calls may use bi_next if this
1525+
* bio happens to be merged with someone else, and may resubmit the bio to
1526+
* a lower device by calling into generic_make_request recursively, which
1527+
* means the bio should NOT be touched after the call to ->make_request_fn.
15371528
*/
15381529
void generic_make_request(struct bio *bio)
15391530
{
15401531
struct bio_list bio_list_on_stack;
15411532

1533+
if (!generic_make_request_checks(bio))
1534+
return;
1535+
1536+
/*
1537+
* We only want one ->make_request_fn to be active at a time, else
1538+
* stack usage with stacked devices could be a problem. So use
1539+
* current->bio_list to keep a list of requests submited by a
1540+
* make_request_fn function. current->bio_list is also used as a
1541+
* flag to say if generic_make_request is currently active in this
1542+
* task or not. If it is NULL, then no make_request is active. If
1543+
* it is non-NULL, then a make_request is active, and new requests
1544+
* should be added at the tail
1545+
*/
15421546
if (current->bio_list) {
1543-
/* make_request is active */
15441547
bio_list_add(current->bio_list, bio);
15451548
return;
15461549
}
1550+
15471551
/* following loop may be a bit non-obvious, and so deserves some
15481552
* explanation.
15491553
* Before entering the loop, bio->bi_next is NULL (as all callers
15501554
* ensure that) so we have a list with a single bio.
15511555
* We pretend that we have just taken it off a longer list, so
15521556
* we assign bio_list to a pointer to the bio_list_on_stack,
15531557
* thus initialising the bio_list of new bios to be
1554-
* added. __generic_make_request may indeed add some more bios
1558+
* added. ->make_request() may indeed add some more bios
15551559
* through a recursive call to generic_make_request. If it
15561560
* did, we find a non-NULL value in bio_list and re-enter the loop
15571561
* from the top. In this case we really did just take the bio
15581562
* of the top of the list (no pretending) and so remove it from
1559-
* bio_list, and call into __generic_make_request again.
1560-
*
1561-
* The loop was structured like this to make only one call to
1562-
* __generic_make_request (which is important as it is large and
1563-
* inlined) and to keep the structure simple.
1563+
* bio_list, and call into ->make_request() again.
15641564
*/
15651565
BUG_ON(bio->bi_next);
15661566
bio_list_init(&bio_list_on_stack);
15671567
current->bio_list = &bio_list_on_stack;
15681568
do {
1569-
__generic_make_request(bio);
1569+
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
1570+
1571+
q->make_request_fn(q, bio);
1572+
15701573
bio = bio_list_pop(current->bio_list);
15711574
} while (bio);
15721575
current->bio_list = NULL; /* deactivate */

0 commit comments

Comments
 (0)