qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH
@ 2019-07-25 10:05 Vladimir Sementsov-Ogievskiy
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-07-25 10:05 UTC (permalink / raw)
  To: qemu-devel, qemu-block
  Cc: kwolf, fam, vsementsov, mreitz, stefanha, den, jsnow

Hi all!

Here is small new read flag: BDRV_REQ_PREFETCH, which in combination with
BDRV_REQ_COPY_ON_READ does copy-on-read without
extra buffer for read data. This means that only parts that needs COR
will be actually read and only corresponding buffers allocated, no more.

This allows to improve a bit block-stream and NBD_CMD_CACHE

v3: rebase 02 on master, fix commit message of 03.

v2: change interface to be just one flag BDRV_REQ_PREFETCH

v1 was "[PATCH 0/3] block: blk_co_pcache"
   https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg01047.html

Vladimir Sementsov-Ogievskiy (3):
  block: implement BDRV_REQ_PREFETCH
  block/stream: use BDRV_REQ_PREFETCH
  nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH

 include/block/block.h |  8 +++++++-
 block/io.c            | 18 ++++++++++++------
 block/stream.c        | 20 +++++++-------------
 nbd/server.c          | 43 +++++++++++++++++++++++++++++++++++--------
 4 files changed, 61 insertions(+), 28 deletions(-)

-- 
2.18.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH
  2019-07-25 10:05 [Qemu-devel] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
@ 2019-07-25 10:05 ` Vladimir Sementsov-Ogievskiy
  2019-07-29 21:13   ` Eric Blake
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 2/3] block/stream: use BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-07-25 10:05 UTC (permalink / raw)
  To: qemu-devel, qemu-block
  Cc: kwolf, fam, vsementsov, mreitz, stefanha, den, jsnow

Do effective copy-on-read request when we don't need data actually. It
will be used for block-stream and NBD_CMD_CACHE.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/block/block.h |  8 +++++++-
 block/io.c            | 18 ++++++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index 50a07c1c33..73c3fc4daa 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -88,8 +88,14 @@ typedef enum {
      * fallback. */
     BDRV_REQ_NO_FALLBACK        = 0x100,
 
+    /*
+     * BDRV_REQ_PREFETCH may be used only together with BDRV_REQ_COPY_ON_READ
+     * on read request and means that caller don't really need data to be
+     * written to qiov parameter which may be NULL.
+     */
+    BDRV_REQ_PREFETCH  = 0x200,
     /* Mask of valid flags */
-    BDRV_REQ_MASK               = 0x1ff,
+    BDRV_REQ_MASK               = 0x3ff,
 } BdrvRequestFlags;
 
 typedef struct BlockSizes {
diff --git a/block/io.c b/block/io.c
index 06305c6ea6..9d99858b55 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1167,7 +1167,8 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
 }
 
 static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
-        int64_t offset, unsigned int bytes, QEMUIOVector *qiov)
+        int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
+        int flags)
 {
     BlockDriverState *bs = child->bs;
 
@@ -1278,9 +1279,11 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
                 goto err;
             }
 
-            qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes,
-                                pnum - skip_bytes);
-        } else {
+            if (!(flags & BDRV_REQ_PREFETCH)) {
+                qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes,
+                                    pnum - skip_bytes);
+            }
+        } else if (!(flags & BDRV_REQ_PREFETCH)) {
             /* Read directly into the destination */
             qemu_iovec_init(&local_qiov, qiov->niov);
             qemu_iovec_concat(&local_qiov, qiov, progress, pnum - skip_bytes);
@@ -1331,7 +1334,8 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
      * potential fallback support, if we ever implement any read flags
      * to pass through to drivers.  For now, there aren't any
      * passthrough flags.  */
-    assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ)));
+    assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ |
+                       BDRV_REQ_PREFETCH)));
 
     /* Handle Copy on Read and associated serialisation */
     if (flags & BDRV_REQ_COPY_ON_READ) {
@@ -1359,7 +1363,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child,
         }
 
         if (!ret || pnum != bytes) {
-            ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov);
+            ret = bdrv_co_do_copy_on_readv(child, offset, bytes, qiov, flags);
+            goto out;
+        } else if (flags & BDRV_REQ_PREFETCH) {
             goto out;
         }
     }
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 2/3] block/stream: use BDRV_REQ_PREFETCH
  2019-07-25 10:05 [Qemu-devel] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
@ 2019-07-25 10:05 ` Vladimir Sementsov-Ogievskiy
  2019-07-29 21:19   ` Eric Blake
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 3/3] nbd: improve CMD_CACHE: " Vladimir Sementsov-Ogievskiy
  2019-07-29 15:00 ` [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Stefan Hajnoczi
  3 siblings, 1 reply; 10+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-07-25 10:05 UTC (permalink / raw)
  To: qemu-devel, qemu-block
  Cc: kwolf, fam, vsementsov, mreitz, stefanha, den, jsnow

This helps to avoid extra io, allocations and memory copying.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/stream.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/block/stream.c b/block/stream.c
index 6ac1e7bec4..170e3b43be 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -22,11 +22,11 @@
 
 enum {
     /*
-     * Size of data buffer for populating the image file.  This should be large
+     * Maximum chunk size to feed it to copy-on-read.  This should be large
      * enough to process multiple clusters in a single call, so that populating
      * contiguous regions of the image is efficient.
      */
-    STREAM_BUFFER_SIZE = 512 * 1024, /* in bytes */
+    STREAM_CHUNK = 512 * 1024, /* in bytes */
 };
 
 typedef struct StreamBlockJob {
@@ -39,13 +39,12 @@ typedef struct StreamBlockJob {
 } StreamBlockJob;
 
 static int coroutine_fn stream_populate(BlockBackend *blk,
-                                        int64_t offset, uint64_t bytes,
-                                        void *buf)
+                                        int64_t offset, uint64_t bytes)
 {
     assert(bytes < SIZE_MAX);
 
-    /* Copy-on-read the unallocated clusters */
-    return blk_co_pread(blk, offset, bytes, buf, BDRV_REQ_COPY_ON_READ);
+    return blk_co_preadv(blk, offset, bytes, NULL,
+                         BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH);
 }
 
 static void stream_abort(Job *job)
@@ -117,7 +116,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
     int error = 0;
     int ret = 0;
     int64_t n = 0; /* bytes */
-    void *buf;
 
     if (bs == s->bottom) {
         /* Nothing to stream */
@@ -130,8 +128,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
     }
     job_progress_set_remaining(&s->common.job, len);
 
-    buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE);
-
     /* Turn on copy-on-read for the whole block device so that guest read
      * requests help us make progress.  Only do this when copying the entire
      * backing chain since the copy-on-read operation does not take base into
@@ -154,7 +150,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
 
         copy = false;
 
-        ret = bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n);
+        ret = bdrv_is_allocated(bs, offset, STREAM_CHUNK, &n);
         if (ret == 1) {
             /* Allocated in the top, no need to copy.  */
         } else if (ret >= 0) {
@@ -171,7 +167,7 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
         }
         trace_stream_one_iteration(s, offset, n, ret);
         if (copy) {
-            ret = stream_populate(blk, offset, n, buf);
+            ret = stream_populate(blk, offset, n);
         }
         if (ret < 0) {
             BlockErrorAction action =
@@ -202,8 +198,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
         bdrv_disable_copy_on_read(bs);
     }
 
-    qemu_vfree(buf);
-
     /* Do not remove the backing file if an error was there but ignored. */
     return error;
 }
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH v3 3/3] nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH
  2019-07-25 10:05 [Qemu-devel] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 2/3] block/stream: use BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
@ 2019-07-25 10:05 ` Vladimir Sementsov-Ogievskiy
  2019-07-29 21:24   ` Eric Blake
  2019-07-29 15:00 ` [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Stefan Hajnoczi
  3 siblings, 1 reply; 10+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-07-25 10:05 UTC (permalink / raw)
  To: qemu-devel, qemu-block
  Cc: kwolf, fam, vsementsov, mreitz, stefanha, den, jsnow

This helps to avoid extra io, allocations and memory copying.
We assume here that CMD_CACHE is always used with copy-on-read, as
otherwise it's a noop.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 nbd/server.c | 43 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/nbd/server.c b/nbd/server.c
index 10faedcfc5..a2cf085f76 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -2104,12 +2104,15 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,
             return -EINVAL;
         }
 
-        req->data = blk_try_blockalign(client->exp->blk, request->len);
-        if (req->data == NULL) {
-            error_setg(errp, "No memory");
-            return -ENOMEM;
+        if (request->type != NBD_CMD_CACHE) {
+            req->data = blk_try_blockalign(client->exp->blk, request->len);
+            if (req->data == NULL) {
+                error_setg(errp, "No memory");
+                return -ENOMEM;
+            }
         }
     }
+
     if (request->type == NBD_CMD_WRITE) {
         if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data",
                      errp) < 0)
@@ -2194,7 +2197,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
     int ret;
     NBDExport *exp = client->exp;
 
-    assert(request->type == NBD_CMD_READ || request->type == NBD_CMD_CACHE);
+    assert(request->type == NBD_CMD_READ);
 
     /* XXX: NBD Protocol only documents use of FUA with WRITE */
     if (request->flags & NBD_CMD_FLAG_FUA) {
@@ -2206,7 +2209,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
     }
 
     if (client->structured_reply && !(request->flags & NBD_CMD_FLAG_DF) &&
-        request->len && request->type != NBD_CMD_CACHE)
+        request->len)
     {
         return nbd_co_send_sparse_read(client, request->handle, request->from,
                                        data, request->len, errp);
@@ -2214,7 +2217,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
 
     ret = blk_pread(exp->blk, request->from + exp->dev_offset, data,
                     request->len);
-    if (ret < 0 || request->type == NBD_CMD_CACHE) {
+    if (ret < 0) {
         return nbd_send_generic_reply(client, request->handle, ret,
                                       "reading from file failed", errp);
     }
@@ -2233,6 +2236,28 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
     }
 }
 
+/*
+ * nbd_do_cmd_cache
+ *
+ * Handle NBD_CMD_CACHE request.
+ * Return -errno if sending fails. Other errors are reported directly to the
+ * client as an error reply.
+ */
+static coroutine_fn int nbd_do_cmd_cache(NBDClient *client, NBDRequest *request,
+                                         Error **errp)
+{
+    int ret;
+    NBDExport *exp = client->exp;
+
+    assert(request->type == NBD_CMD_CACHE);
+
+    ret = blk_co_preadv(exp->blk, request->from + exp->dev_offset, request->len,
+                        NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH);
+
+    return nbd_send_generic_reply(client, request->handle, ret,
+                                  "caching data failed", errp);
+}
+
 /* Handle NBD request.
  * Return -errno if sending fails. Other errors are reported directly to the
  * client as an error reply. */
@@ -2246,8 +2271,10 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
     char *msg;
 
     switch (request->type) {
-    case NBD_CMD_READ:
     case NBD_CMD_CACHE:
+        return nbd_do_cmd_cache(client, request, errp);
+
+    case NBD_CMD_READ:
         return nbd_do_cmd_read(client, request, data, errp);
 
     case NBD_CMD_WRITE:
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH
  2019-07-25 10:05 [Qemu-devel] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
                   ` (2 preceding siblings ...)
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 3/3] nbd: improve CMD_CACHE: " Vladimir Sementsov-Ogievskiy
@ 2019-07-29 15:00 ` Stefan Hajnoczi
  2019-07-29 15:29   ` Vladimir Sementsov-Ogievskiy
  2019-07-29 15:38   ` Eric Blake
  3 siblings, 2 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2019-07-29 15:00 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy
  Cc: kwolf, fam, qemu-block, qemu-devel, mreitz, stefanha, den

[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]

On Thu, Jul 25, 2019 at 01:05:47PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> Hi all!
> 
> Here is small new read flag: BDRV_REQ_PREFETCH, which in combination with
> BDRV_REQ_COPY_ON_READ does copy-on-read without
> extra buffer for read data. This means that only parts that needs COR
> will be actually read and only corresponding buffers allocated, no more.
> 
> This allows to improve a bit block-stream and NBD_CMD_CACHE
> 
> v3: rebase 02 on master, fix commit message of 03.
> 
> v2: change interface to be just one flag BDRV_REQ_PREFETCH
> 
> v1 was "[PATCH 0/3] block: blk_co_pcache"
>    https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg01047.html
> 
> Vladimir Sementsov-Ogievskiy (3):
>   block: implement BDRV_REQ_PREFETCH
>   block/stream: use BDRV_REQ_PREFETCH
>   nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH
> 
>  include/block/block.h |  8 +++++++-
>  block/io.c            | 18 ++++++++++++------
>  block/stream.c        | 20 +++++++-------------
>  nbd/server.c          | 43 +++++++++++++++++++++++++++++++++++--------
>  4 files changed, 61 insertions(+), 28 deletions(-)
> 
> -- 
> 2.18.0
> 
> 

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH
  2019-07-29 15:00 ` [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Stefan Hajnoczi
@ 2019-07-29 15:29   ` Vladimir Sementsov-Ogievskiy
  2019-07-29 15:38   ` Eric Blake
  1 sibling, 0 replies; 10+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2019-07-29 15:29 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: kwolf, fam, Denis Lunev, qemu-block, qemu-devel, mreitz, stefanha

29.07.2019 18:00, Stefan Hajnoczi wrote:
> On Thu, Jul 25, 2019 at 01:05:47PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> Hi all!
>>
>> Here is small new read flag: BDRV_REQ_PREFETCH, which in combination with
>> BDRV_REQ_COPY_ON_READ does copy-on-read without
>> extra buffer for read data. This means that only parts that needs COR
>> will be actually read and only corresponding buffers allocated, no more.
>>
>> This allows to improve a bit block-stream and NBD_CMD_CACHE
>>
>> v3: rebase 02 on master, fix commit message of 03.
>>
>> v2: change interface to be just one flag BDRV_REQ_PREFETCH
>>
>> v1 was "[PATCH 0/3] block: blk_co_pcache"
>>     https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg01047.html
>>
>> Vladimir Sementsov-Ogievskiy (3):
>>    block: implement BDRV_REQ_PREFETCH
>>    block/stream: use BDRV_REQ_PREFETCH
>>    nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH
>>
>>   include/block/block.h |  8 +++++++-
>>   block/io.c            | 18 ++++++++++++------
>>   block/stream.c        | 20 +++++++-------------
>>   nbd/server.c          | 43 +++++++++++++++++++++++++++++++++++--------
>>   4 files changed, 61 insertions(+), 28 deletions(-)
>>
>> -- 
>> 2.18.0
>>
>>
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 

Thank you for reviewing!

-- 
Best regards,
Vladimir


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH
  2019-07-29 15:00 ` [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Stefan Hajnoczi
  2019-07-29 15:29   ` Vladimir Sementsov-Ogievskiy
@ 2019-07-29 15:38   ` Eric Blake
  1 sibling, 0 replies; 10+ messages in thread
From: Eric Blake @ 2019-07-29 15:38 UTC (permalink / raw)
  To: Stefan Hajnoczi, Vladimir Sementsov-Ogievskiy
  Cc: kwolf, fam, qemu-block, qemu-devel, mreitz, stefanha, den


[-- Attachment #1.1: Type: text/plain, Size: 1485 bytes --]

On 7/29/19 10:00 AM, Stefan Hajnoczi wrote:
> On Thu, Jul 25, 2019 at 01:05:47PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> Hi all!
>>
>> Here is small new read flag: BDRV_REQ_PREFETCH, which in combination with
>> BDRV_REQ_COPY_ON_READ does copy-on-read without
>> extra buffer for read data. This means that only parts that needs COR
>> will be actually read and only corresponding buffers allocated, no more.
>>
>> This allows to improve a bit block-stream and NBD_CMD_CACHE
>>
>> v3: rebase 02 on master, fix commit message of 03.
>>
>> v2: change interface to be just one flag BDRV_REQ_PREFETCH
>>
>> v1 was "[PATCH 0/3] block: blk_co_pcache"
>>    https://lists.gnu.org/archive/html/qemu-devel/2019-06/msg01047.html
>>
>> Vladimir Sementsov-Ogievskiy (3):
>>   block: implement BDRV_REQ_PREFETCH
>>   block/stream: use BDRV_REQ_PREFETCH
>>   nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH
>>
>>  include/block/block.h |  8 +++++++-
>>  block/io.c            | 18 ++++++++++++------
>>  block/stream.c        | 20 +++++++-------------
>>  nbd/server.c          | 43 +++++++++++++++++++++++++++++++++++--------
>>  4 files changed, 61 insertions(+), 28 deletions(-)
>>
>> -- 
>> 2.18.0
>>
>>
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 

I'm happy to queue this one through my NBD tree for 4.2.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
@ 2019-07-29 21:13   ` Eric Blake
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Blake @ 2019-07-29 21:13 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block
  Cc: kwolf, fam, mreitz, stefanha, den, jsnow


[-- Attachment #1.1: Type: text/plain, Size: 1874 bytes --]

On 7/25/19 5:05 AM, Vladimir Sementsov-Ogievskiy wrote:
> Do effective copy-on-read request when we don't need data actually. It
> will be used for block-stream and NBD_CMD_CACHE.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  include/block/block.h |  8 +++++++-
>  block/io.c            | 18 ++++++++++++------
>  2 files changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/include/block/block.h b/include/block/block.h
> index 50a07c1c33..73c3fc4daa 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -88,8 +88,14 @@ typedef enum {
>       * fallback. */
>      BDRV_REQ_NO_FALLBACK        = 0x100,
>  
> +    /*
> +     * BDRV_REQ_PREFETCH may be used only together with BDRV_REQ_COPY_ON_READ
> +     * on read request and means that caller don't really need data to be

doesn't

can fix up while staging.


> +++ b/block/io.c
> @@ -1167,7 +1167,8 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
>  }
>  
>  static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child,
> -        int64_t offset, unsigned int bytes, QEMUIOVector *qiov)
> +        int64_t offset, unsigned int bytes, QEMUIOVector *qiov,
> +        int flags)

We're bad about this, but 'int flags' does not play well with the C
language and well-defined behavior when it comes to 1<<31 (bit
operations and unsigned types have guaranteed behavior, bit operations
and negative signed types can cause the compiler to do differently than
you expect).  Not a problem for uses where we don't have 32 flags to OR
together, so I won't change it, so much as point it out for a bigger
task of auditing the entire code base if we are worried.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3 2/3] block/stream: use BDRV_REQ_PREFETCH
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 2/3] block/stream: use BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
@ 2019-07-29 21:19   ` Eric Blake
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Blake @ 2019-07-29 21:19 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block
  Cc: kwolf, fam, mreitz, stefanha, den, jsnow


[-- Attachment #1.1: Type: text/plain, Size: 836 bytes --]

On 7/25/19 5:05 AM, Vladimir Sementsov-Ogievskiy wrote:
> This helps to avoid extra io, allocations and memory copying.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/stream.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/block/stream.c b/block/stream.c
> index 6ac1e7bec4..170e3b43be 100644
> --- a/block/stream.c
> +++ b/block/stream.c
> @@ -22,11 +22,11 @@
>  
>  enum {
>      /*
> -     * Size of data buffer for populating the image file.  This should be large
> +     * Maximum chunk size to feed it to copy-on-read.  This should be large

s/feed it/feed/

Will fix during staging

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH v3 3/3] nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH
  2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 3/3] nbd: improve CMD_CACHE: " Vladimir Sementsov-Ogievskiy
@ 2019-07-29 21:24   ` Eric Blake
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Blake @ 2019-07-29 21:24 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu-devel, qemu-block
  Cc: kwolf, fam, mreitz, stefanha, den, jsnow


[-- Attachment #1.1: Type: text/plain, Size: 877 bytes --]

On 7/25/19 5:05 AM, Vladimir Sementsov-Ogievskiy wrote:
> This helps to avoid extra io, allocations and memory copying.
> We assume here that CMD_CACHE is always used with copy-on-read, as
> otherwise it's a noop.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  nbd/server.c | 43 +++++++++++++++++++++++++++++++++++--------
>  1 file changed, 35 insertions(+), 8 deletions(-)

libnbd is able to test NBD_CMD_CACHE requests, and I've confirmed that
behavior looks sane under requests issued that way.  I'm wondering if
qemu-io should also be able to drive this mode of operation, so that we
can give it iotest coverage without depending on libnbd.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-07-29 21:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-25 10:05 [Qemu-devel] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 1/3] block: implement BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
2019-07-29 21:13   ` Eric Blake
2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 2/3] block/stream: use BDRV_REQ_PREFETCH Vladimir Sementsov-Ogievskiy
2019-07-29 21:19   ` Eric Blake
2019-07-25 10:05 ` [Qemu-devel] [PATCH v3 3/3] nbd: improve CMD_CACHE: " Vladimir Sementsov-Ogievskiy
2019-07-29 21:24   ` Eric Blake
2019-07-29 15:00 ` [Qemu-devel] [Qemu-block] [PATCH v3 for-4.2 0/3] block: BDRV_REQ_PREFETCH Stefan Hajnoczi
2019-07-29 15:29   ` Vladimir Sementsov-Ogievskiy
2019-07-29 15:38   ` Eric Blake

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).