[Devel] [PATCH VZ9 3/3] vhost-blk: fix allocation size for bio pointers
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Wed Nov 6 12:20:31 MSK 2024
Even pages with continious virtual addresses may not be merged in one
bio vector in bio_add_page -> bvec_try_merge_page. So it looks like the
best estimate on the number of required bios we can make is a total
number of pages in the request divided by BIO_MAX_VECS (worst case is
when each of BIO_MAX_VECS bio vectors has exactly one page added to it).
Fixes: 17bfe6e0400da ("drivers/vhost: vhost-blk accelerator for virtio-blk guests")
https://virtuozzo.atlassian.net/browse/VSTOR-94596
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
---
drivers/vhost/blk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c
index d77e5fc494dee..90d20d0eb722c 100644
--- a/drivers/vhost/blk.c
+++ b/drivers/vhost/blk.c
@@ -228,7 +228,7 @@ static struct page **vhost_blk_prepare_req(struct vhost_blk_req *req,
req->use_inline = false;
pl_len = iov_nr * sizeof(req->pl[0]);
page_len = total_pages * sizeof(struct page *);
- bio_len = (total_pages / (UINT_MAX / PAGE_SIZE) + 1) * sizeof(struct bio *);
+ bio_len = (total_pages + BIO_MAX_VECS - 1) / BIO_MAX_VECS * sizeof(struct bio *);
buf = kmalloc(pl_len + page_len + bio_len, GFP_KERNEL);
if (!buf)
--
2.46.2
More information about the Devel
mailing list