qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] vmdk: Optimize cluster allocation


From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH] vmdk: Optimize cluster allocation
Date: Tue, 22 Apr 2014 14:38:01 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Am 18.04.2014 um 14:39 hat Fam Zheng geschrieben:
> On mounted NFS filesystem, ftruncate is much much slower than doing a
> zero write. Changing this significantly speeds up cluster allocation.
> 
> Comparing by converting a cirros image (296M) to VMDK on an NFS mount
> point, over 1Gbe LAN:
> 
>     $ time qemu-img convert cirros-0.3.1.img /mnt/a.raw -O vmdk
> 
> Before:
>     real    0m26.464s
>     user    0m0.133s
>     sys     0m0.527s
> 
> After:
>     real    0m2.120s
>     user    0m0.080s
>     sys     0m0.197s
> 
> Signed-off-by: Fam Zheng <address@hidden>
> ---
>  block/vmdk.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index b69988d..b829265 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -1036,6 +1036,7 @@ static int get_cluster_offset(BlockDriverState *bs,
>      int min_index, i, j;
>      uint32_t min_count, *l2_table;
>      bool zeroed = false;
> +    int ret;
>  
>      if (m_data) {
>          m_data->valid = 0;
> @@ -1110,11 +1111,15 @@ static int get_cluster_offset(BlockDriverState *bs,
>  
>          /* Avoid the L2 tables update for the images that have snapshots. */
>          *cluster_offset = bdrv_getlength(extent->file);
> +        assert(0 == (*cluster_offset & (extent->cluster_sectors - 1)));

Are you sure that this is what you wanted to assert? cluster_offset is
in bytes, whereas extent->cluster_sectors is in sectors. I think the
assertion holds true, but might be weaker than what you intended to
assert (that the offset is on a cluster boundary).

Kevin

>          if (!extent->compressed) {
> -            bdrv_truncate(
> -                extent->file,
> -                *cluster_offset + (extent->cluster_sectors << 9)
> -            );
> +            ret = bdrv_write_zeroes(extent->file,
> +                                    *cluster_offset >> BDRV_SECTOR_BITS,
> +                                    extent->cluster_sectors,
> +                                    0);
> +            if (ret) {
> +                return VMDK_ERROR;
> +            }
>          }
>  
>          *cluster_offset >>= 9;
> -- 
> 1.9.2
> 



reply via email to

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