qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 2/6] block-copy: streamline choice of copy_range vs. read/


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH v4 2/6] block-copy: streamline choice of copy_range vs. read/write
Date: Sat, 19 Jun 2021 18:05:30 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

14.06.2021 10:33, Emanuele Giuseppe Esposito wrote:
From: Paolo Bonzini <pbonzini@redhat.com>

Put the logic to determine the copy size in a separate function, so
that there is a simple state machine for the possible methods of
copying data from one BlockDriverState to the other.

Use .method instead of .copy_range as in-out argument, and
include also .zeroes as an additional copy method.

While at it, store the common computation of block_copy_max_transfer
into a new field of BlockCopyState, and make sure that we always
obey max_transfer; that's more efficient even for the
COPY_RANGE_READ_WRITE case.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
  block/block-copy.c | 174 +++++++++++++++++++++++----------------------
  1 file changed, 89 insertions(+), 85 deletions(-)


[..]

@@ -267,28 +293,28 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, 
BdrvChild *target,
          .len = bdrv_dirty_bitmap_size(copy_bitmap),
          .write_flags = write_flags,
          .mem = shres_create(BLOCK_COPY_MAX_MEM),
+        .max_transfer = QEMU_ALIGN_DOWN(
+                                    block_copy_max_transfer(source, target),
+                                    cluster_size),
      };
- if (block_copy_max_transfer(source, target) < cluster_size) {
+    if (s->max_transfer < cluster_size) {
          /*
           * copy_range does not respect max_transfer. We don't want to bother
           * with requests smaller than block-copy cluster size, so fallback to
           * buffered copying (read and write respect max_transfer on their
           * behalf).
           */
-        s->use_copy_range = false;
-        s->copy_size = cluster_size;
+        s->method = COPY_READ_WRITE_CLUSTER;
      } else if (write_flags & BDRV_REQ_WRITE_COMPRESSED) {
          /* Compression supports only cluster-size writes and no copy-range. */
-        s->use_copy_range = false;
-        s->copy_size = cluster_size;
+        s->method = COPY_READ_WRITE_CLUSTER;
      } else {
          /*
           * We enable copy-range, but keep small copy_size, until first
           * successful copy_range (look at block_copy_do_copy).
           */

Comment outdated. Maybe:

/* if copy range enabled, start with COPY_RANGE_SMALL, until first successful 
copy_range (look at block_copy_do_copy). */

-        s->use_copy_range = use_copy_range;
-        s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
+        s->method = use_copy_range ? COPY_RANGE_SMALL : COPY_READ_WRITE;
      }
ratelimit_init(&s->rate_limit);

[..]

@@ -377,76 +400,59 @@ static int coroutine_fn block_copy_do_copy(BlockCopyState 
*s,
              *error_is_read = false;
          }
          return ret;
-    }
- if (*copy_range) {
+    case COPY_RANGE_SMALL:
+    case COPY_RANGE_FULL:
          ret = bdrv_co_copy_range(s->source, offset, s->target, offset, nbytes,
                                   0, s->write_flags);
-        if (ret < 0) {
-            trace_block_copy_copy_range_fail(s, offset, ret);
-            *copy_range = false;
-            /* Fallback to read+write with allocated buffer */
-        } else {
+        if (ret >= 0) {
+            /* Successful copy-range, increase copy_size.  */

No copy_size now. So, "increase chunk size".

+            *method = COPY_RANGE_FULL;
              return 0;
          }
-    }

Comment tweaks are non-critical, can be done in-flight.

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

--
Best regards,
Vladimir



reply via email to

[Prev in Thread] Current Thread [Next in Thread]