[Libguestfs] [nbdkit PATCH v2] Introduce cacheextents filter

Eric Blake eblake at redhat.com
Tue Jun 11 16:35:15 UTC 2019


On 6/11/19 3:49 AM, Martin Kletzander wrote:
> This filter caches the last result of the extents() call and offers a nice
> speed-up for clients that only support req_one=1 in combination with plugins
> like vddk, which has no overhead for returning information for multiple extents
> in one call, but that call is very time-consuming.
> 
> Quick test showed that on a fast connection and a sparsely allocated 16G disk
> with a OS installed `qemu-img map` runs 16s instead of 33s (out of which it
> takes 5s to the first extents request).  For 100G disk with no data on it, that
> is one hole extent spanning the whole disk (where there is no space for
> improvement) this does not add any noticeable overhead.
> 
> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
> ---
> 

> +static int
> +cacheextents_fill (struct nbdkit_extents *extents, int *err)
> +{
> +  size_t i = 0;
> +  size_t count = nbdkit_extents_count (extents);
> +  struct nbdkit_extent first = nbdkit_get_extent (extents, 0);
> +  struct nbdkit_extent last = nbdkit_get_extent (extents, count - 1);
> +
> +  nbdkit_extents_free (cache_extents);
> +  cache_start = first.offset;
> +  cache_end = last.offset + last.length;
> +  cache_extents = nbdkit_extents_new (cache_start, cache_end);
> +
> +  for (i = 0; i < count; i++) {
> +    struct nbdkit_extent ex = nbdkit_get_extent (extents, i);
> +    nbdkit_debug ("cacheextents: updating cache with"
> +                  ": offset=%" PRIu64
> +                  ": length=%" PRIu64
> +                  "; type=%x",
> +                  ex.offset, ex.length, ex.type);
> +    if (nbdkit_add_extent (cache_extents, ex.offset, ex.length, ex.type) == -1) {
> +      *err = errno;
> +      return -1;
> +    }

We need to clear cache_extents on this error path (otherwise cache_end
is wrong, and future extents requests may try to read from the cache but
fail, when they should instead be treated as a cache miss). Sorry I
missed it during my initial review; I'll push the patch shortly.

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190611/d7ccd6db/attachment.sig>


More information about the Libguestfs mailing list