* [PATCH v2] block: Fix __blkdev_issue_zeroout loop
@ 2017-07-04 8:27 Damien Le Moal
2017-07-05 17:26 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2017-07-04 8:27 UTC (permalink / raw)
To: linux-block, Jens Axboe; +Cc: Christoph Hellwig
The BIO issuing loop in __blkdev_issue_zeroout() is allocating BIOs
with a maximum number of bvec (pages) equal to
min(nr_sects, (sector_t)BIO_MAX_PAGES)
This works since the BIO will always be limited to the absolute maximum
number of pages but this is ineficient as too many bvec entries may be
requested since different units (number of sectors vs number of pages)
are used in the min() operation. Fix this by correctly using the same
unit (number of pages), making sure that this number is at least 1 for
cases where the number of sectors is less that the number of sectors in
a page.
Also remove a trailing space after the bit shift in the internal loop
min() call.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
block/blk-lib.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index e8caecd..a19e6cd 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -307,14 +307,15 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
ret = 0;
while (nr_sects != 0) {
- bio = next_bio(bio, min(nr_sects, (sector_t)BIO_MAX_PAGES),
- gfp_mask);
+ sz = min((nr_sects << 9) >> PAGE_SHIFT,
+ (sector_t)BIO_MAX_PAGES);
+ bio = next_bio(bio, max(1U, sz), gfp_mask);
bio->bi_iter.bi_sector = sector;
bio->bi_bdev = bdev;
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
while (nr_sects != 0) {
- sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects);
+ sz = min((sector_t) PAGE_SIZE >> 9, nr_sects);
bi_size = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0);
nr_sects -= bi_size >> 9;
sector += bi_size >> 9;
--
2.9.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] block: Fix __blkdev_issue_zeroout loop
2017-07-04 8:27 [PATCH v2] block: Fix __blkdev_issue_zeroout loop Damien Le Moal
@ 2017-07-05 17:26 ` Christoph Hellwig
2017-07-05 23:50 ` Damien Le Moal
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2017-07-05 17:26 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-block, Jens Axboe, Christoph Hellwig
On Tue, Jul 04, 2017 at 05:27:02PM +0900, Damien Le Moal wrote:
> The BIO issuing loop in __blkdev_issue_zeroout() is allocating BIOs
> with a maximum number of bvec (pages) equal to
>
> min(nr_sects, (sector_t)BIO_MAX_PAGES)
>
> This works since the BIO will always be limited to the absolute maximum
> number of pages but this is ineficient as too many bvec entries may be
> requested since different units (number of sectors vs number of pages)
> are used in the min() operation. Fix this by correctly using the same
> unit (number of pages), making sure that this number is at least 1 for
> cases where the number of sectors is less that the number of sectors in
> a page.
>
> Also remove a trailing space after the bit shift in the internal loop
> min() call.
Can you move the nr sectors calculation into a helper and add some
comments?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] block: Fix __blkdev_issue_zeroout loop
2017-07-05 17:26 ` Christoph Hellwig
@ 2017-07-05 23:50 ` Damien Le Moal
0 siblings, 0 replies; 3+ messages in thread
From: Damien Le Moal @ 2017-07-05 23:50 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-block, Jens Axboe
On 7/6/17 02:26, Christoph Hellwig wrote:
> On Tue, Jul 04, 2017 at 05:27:02PM +0900, Damien Le Moal wrote:
>> The BIO issuing loop in __blkdev_issue_zeroout() is allocating BIOs
>> with a maximum number of bvec (pages) equal to
>>
>> min(nr_sects, (sector_t)BIO_MAX_PAGES)
>>
>> This works since the BIO will always be limited to the absolute maximum
>> number of pages but this is ineficient as too many bvec entries may be
>> requested since different units (number of sectors vs number of pages)
>> are used in the min() operation. Fix this by correctly using the same
>> unit (number of pages), making sure that this number is at least 1 for
>> cases where the number of sectors is less that the number of sectors in
>> a page.
>>
>> Also remove a trailing space after the bit shift in the internal loop
>> min() call.
>
> Can you move the nr sectors calculation into a helper and add some
> comments?
Sure, no problem. I will send a v3 today.
--
Damien Le Moal,
Western Digital
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-05 23:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-04 8:27 [PATCH v2] block: Fix __blkdev_issue_zeroout loop Damien Le Moal
2017-07-05 17:26 ` Christoph Hellwig
2017-07-05 23:50 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).