<div dir="ltr">Hi 

Konstantin:<div><br><div>  Thanks for your reply.</div><div>virtio_blk.c is the front-end driver code of the virtio block, which has the following code:<br>        /* We need to know how many segments before we allocate. */<br>        err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SEG_MAX,<br>                                   struct virtio_blk_config, seg_max,<br>                                   &amp;sg_elems);<br><br>        /* We need at least one SG element, whatever they say. */<br>        if (err || !sg_elems)<br>                sg_elems = 1;<br><br>Eventually, the max number of segments will be configured through the blk_queue_max_segments interface.<br>When I modify the value of the sg_elems due to performance reasons, such as 128, I will find that the<br>front-end operating system cannot be started normally, which is manifested as the Android file system <br>cannot be mounted normally.<br><br>You can do a simple test to modify the default value of sg_elems virtio_blk.c in your company&#39;s<br>virtualization solution, as follows:<br>vzkernel$ git diff drivers/block/virtio_blk.c<br>diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c<br>index fd086179f980..0a216c9cb563 100644<br>--- a/drivers/block/virtio_blk.c<br>+++ b/drivers/block/virtio_blk.c<br>@@ -719,7 +719,7 @@ static int virtblk_probe(struct virtio_device *vdev)<br> <br>        /* We need at least one SG element, whatever they say. */<br>        if (err || !sg_elems)<br>-               sg_elems = 1;<br>+               sg_elems = 2;<br> <br>        /* Prevent integer overflows and honor max vq size */<br>        sg_elems = min_t(u32, sg_elems, VIRTIO_BLK_MAX_SG_ELEMS - 2);<br><br>At this point, the expected test symptom is that the front-end OS does not boot properly.<br><br>In our virtualization solution, we used your company&#39;s blk.c as the back-end driver of Virtio Block,<br>found the above problems, and made problem fixes, and at the same time, the performance of Virtio <br>Block has also been improved, so we want to give back to the open source community.<br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Konstantin Khorenko &lt;<a href="mailto:khorenko@virtuozzo.com">khorenko@virtuozzo.com</a>&gt; 于2024年6月14日周五 19:23写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Lynch, Andrey,<br>
<br>
thank you for the patch, but can you please describe the problem it fixes in a bit more details?<br>
i see that the patch preserves original req-&gt;sector, but why/how that becomes important in case <br>
VIRTIO_BLK_F_MQ feature is set?<br>
<br>
Thank you.<br>
<br>
--<br>
Best regards,<br>
<br>
Konstantin Khorenko,<br>
Virtuozzo Linux Kernel Team<br>
<br>
On 17.05.2024 11:09, Andrey Zhadchenko wrote:<br>
&gt; Hi<br>
&gt; <br>
&gt; Thank you for the patch.<br>
&gt; vhost-blk didn&#39;t spark enough interest to be reviewed and merged into<br>
&gt; the upstream and the code is not present here.<br>
&gt; I have forwarded your patch to relevant openvz kernel mailing list.<br>
&gt; <br>
&gt; On 5/17/24 07:34, Lynch wrote:<br>
&gt;&gt; ---<br>
&gt;&gt;    drivers/vhost/blk.c | 6 ++++--<br>
&gt;&gt;    1 file changed, 4 insertions(+), 2 deletions(-)<br>
&gt;&gt;<br>
&gt;&gt; diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c<br>
&gt;&gt; index 44fbf253e773..0e946d9dfc33 100644<br>
&gt;&gt; --- a/drivers/vhost/blk.c<br>
&gt;&gt; +++ b/drivers/vhost/blk.c<br>
&gt;&gt; @@ -251,6 +251,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,<br>
&gt;&gt;      struct page **pages, *page;<br>
&gt;&gt;      struct bio *bio = NULL;<br>
&gt;&gt;      int bio_nr = 0;<br>
&gt;&gt; +    sector_t sector_tmp;<br>
&gt;&gt;    <br>
&gt;&gt;      if (unlikely(req-&gt;bi_opf == REQ_OP_FLUSH))<br>
&gt;&gt;              return vhost_blk_bio_make_simple(req, bdev);<br>
&gt;&gt; @@ -270,6 +271,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,<br>
&gt;&gt;              req-&gt;bio = req-&gt;inline_bio;<br>
&gt;&gt;      }<br>
&gt;&gt;    <br>
&gt;&gt; +    sector_tmp = req-&gt;sector;<br>
&gt;&gt;      req-&gt;iov_nr = 0;<br>
&gt;&gt;      for (i = 0; i &lt; iov_nr; i++) {<br>
&gt;&gt;              int pages_nr = iov_num_pages(&amp;iov[i]);<br>
&gt;&gt; @@ -302,7 +304,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,<br>
&gt;&gt;                              bio = bio_alloc(GFP_KERNEL, pages_nr_total);<br>
&gt;&gt;                              if (!bio)<br>
&gt;&gt;                                      goto fail;<br>
&gt;&gt; -                            bio-&gt;bi_iter.bi_sector  = req-&gt;sector;<br>
&gt;&gt; +                            bio-&gt;bi_iter.bi_sector  = sector_tmp;<br>
&gt;&gt;                              bio_set_dev(bio, bdev);<br>
&gt;&gt;                              bio-&gt;bi_private = req;<br>
&gt;&gt;                              bio-&gt;bi_end_io  = vhost_blk_req_done;<br>
&gt;&gt; @@ -314,7 +316,7 @@ static int vhost_blk_bio_make(struct vhost_blk_req *req,<br>
&gt;&gt;                      iov_len         -= len;<br>
&gt;&gt;    <br>
&gt;&gt;                      pos = (iov_base &amp; VHOST_BLK_SECTOR_MASK) + iov_len;<br>
&gt;&gt; -                    req-&gt;sector += pos &gt;&gt; VHOST_BLK_SECTOR_BITS;<br>
&gt;&gt; +                    sector_tmp += pos &gt;&gt; VHOST_BLK_SECTOR_BITS;<br>
&gt;&gt;              }<br>
&gt;&gt;    <br>
&gt;&gt;              pages += pages_nr;<br>
</blockquote></div>