Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-07 Thread Max Reitz
On 2018-03-07 18:05, Kevin Wolf wrote:
> Am 07.03.2018 um 16:57 hat Max Reitz geschrieben:
>> On 2018-03-06 18:37, Kevin Wolf wrote:
>>> Am 06.03.2018 um 14:47 hat Stefan Hajnoczi geschrieben:
 On Wed, Feb 28, 2018 at 09:11:32PM +0100, Max Reitz wrote:
> So...  It's more extreme than I had hoped, that's for sure.  What I
> conclude from this is:
>
> (1) This patch is generally good for nearly fully allocated images.  In
> the worst case (on well-behaving filesystems with well-optimized image
> formats) it changes nothing.  In the best case, conversion time is
> reduced drastically.
>>>
>>> This makes sense. Asking the kernel whether a block is zero only helps
>>> the performance if the result is yes occasionally, otherwise it's just
>>> wasted work.
>>>
>>> Maybe we could try to guess the ratio by comparing the number of
>>> allocated blocks in the image file and the virtual disk size or
>>> something? Then we could only call lseek() when we can actually expect
>>> an improvement from it.
>>
>> Sounds like "qemu should not contain policy" to me.  If the user expects
>> the image to be fully allocated, they might as well use -S 0.
> 
> Optimising special cases isn't really what is meant when we're talking
> about having policy in qemu. The result doesn't change, but the
> performance does potentially. And as long as you access the whole image
> like in qemu-img convert, qemu can make a pretty good estimation because
> it knows both physical and virtual image sizes, so why bother the
> management layer with it?

Oh, I thought we should measure how long an lseek() takes and then
decide based on that.  Hm, well, yes, comparing the allocation size
would be worse thinking about.  But then it gets tricky with internal
snapshots and such...

> The thing that could be considered policy is the threshold where you
> switch from one method to the other.
> 
> (2) For sparse raw images, this is absolutely devastating.  Reading them
> now takes more than (ext4) or nearly (xfs) twice as much time as reading
> a fully allocated image.  So much for "if a filesystem driver has any
> sense".
>>>
>>> Are you sure that only the filesystem is the problem? Checking for every
>>> single byte of an image whether it is zero has to cost some performance.
>>
>> Well, yes, but "read data location from FS metadata" + "realize it's a
>> hole" + memset() + "repe scasb" shouldn't take twice as much time as
>> "read data location from FS metadata" + "read data from SSD".
>>
>> I expected the "realize it's a hole" part to fall out for free, so this
>> would that memset() + repe scasb take much longer than reading data from
>> the SSD -- and that's just pretty much impossible.
> 
> Not sure where you get the SSD part from. The scenarios you're comparing
> are these:
> 
> 1. Query holes with lseek() and then memset() in qemu's emulation of
>bdrv_co_pwrite_zeroes() for drivers that don't implement it. (Which
>is true for your null-co, but not representative for the real-world
>use cases with an actual file-posix protocol layer. Benchmarking with
>an extended null-co that has write_zero support would probably
>better.)

That's before this patch for sparsely allocated images.

> 2. Uncondtionally call pread() and let the kernel do a memset(), at the
>cost of having to scan the buffer afterwards because qemu doesn't
>know yet that it contains zeros.

That's after this patch for sparsely allocated images.

What I was wondering about was solely post-patch behavior, namely
sparsely vs. nearly fully allocated images.

The thing was that converting a sparsely allocated image from an SSD
took twice as much time as converting a fully allocated image.  Reading
data comes in for the fully allocated case.

The thing was that I forgot to drop the caches (and I really do want to
drop those, because they only help for my 2 GB test case, but in the
real world with 300+ GB images, they won't do much).  So, yes, I guess
what I compared was an in-memory metadata lookup + memset() +
O(n) buffer_is_zero() vs. in-memory metadata lookup + memcpy() +
O(1) buffer_is_zero().

Still leaves something to be explained (because I'd expect memset() to
be twice as fast as memcpy()), but at least it isn't completely weird.

> Neither case involves disk accesses if the filesystem metadata is
> cached. You're comparing a memset+scan to just a memset (and the more
> realistic case should be comparing memset+scan to nothing).
> 
> (BTW, buffer_is_zero() does complicated stuff, but 'repe scasb' isn't
> among it.)

I know, that was just a simplification.

>>> The fully allocated image doesn't suffer from this because (a) it only
>>> has to check the first byte in each block and (b) the cost was already
>>> there before this patch.
>>>
>>> In fact, if null-co supported .bdrv_co_pwrite_zeroes, I think you would
>>> get even worse results for your patch because then the pre-patch version
>>> doesn't even have to 

Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-07 Thread Kevin Wolf
Am 07.03.2018 um 16:57 hat Max Reitz geschrieben:
> On 2018-03-06 18:37, Kevin Wolf wrote:
> > Am 06.03.2018 um 14:47 hat Stefan Hajnoczi geschrieben:
> >> On Wed, Feb 28, 2018 at 09:11:32PM +0100, Max Reitz wrote:
> >>> So...  It's more extreme than I had hoped, that's for sure.  What I
> >>> conclude from this is:
> >>>
> >>> (1) This patch is generally good for nearly fully allocated images.  In
> >>> the worst case (on well-behaving filesystems with well-optimized image
> >>> formats) it changes nothing.  In the best case, conversion time is
> >>> reduced drastically.
> > 
> > This makes sense. Asking the kernel whether a block is zero only helps
> > the performance if the result is yes occasionally, otherwise it's just
> > wasted work.
> > 
> > Maybe we could try to guess the ratio by comparing the number of
> > allocated blocks in the image file and the virtual disk size or
> > something? Then we could only call lseek() when we can actually expect
> > an improvement from it.
> 
> Sounds like "qemu should not contain policy" to me.  If the user expects
> the image to be fully allocated, they might as well use -S 0.

Optimising special cases isn't really what is meant when we're talking
about having policy in qemu. The result doesn't change, but the
performance does potentially. And as long as you access the whole image
like in qemu-img convert, qemu can make a pretty good estimation because
it knows both physical and virtual image sizes, so why bother the
management layer with it?

The thing that could be considered policy is the threshold where you
switch from one method to the other.

> >>> (2) For sparse raw images, this is absolutely devastating.  Reading them
> >>> now takes more than (ext4) or nearly (xfs) twice as much time as reading
> >>> a fully allocated image.  So much for "if a filesystem driver has any
> >>> sense".
> > 
> > Are you sure that only the filesystem is the problem? Checking for every
> > single byte of an image whether it is zero has to cost some performance.
> 
> Well, yes, but "read data location from FS metadata" + "realize it's a
> hole" + memset() + "repe scasb" shouldn't take twice as much time as
> "read data location from FS metadata" + "read data from SSD".
> 
> I expected the "realize it's a hole" part to fall out for free, so this
> would that memset() + repe scasb take much longer than reading data from
> the SSD -- and that's just pretty much impossible.

Not sure where you get the SSD part from. The scenarios you're comparing
are these:

1. Query holes with lseek() and then memset() in qemu's emulation of
   bdrv_co_pwrite_zeroes() for drivers that don't implement it. (Which
   is true for your null-co, but not representative for the real-world
   use cases with an actual file-posix protocol layer. Benchmarking with
   an extended null-co that has write_zero support would probably
   better.)

2. Uncondtionally call pread() and let the kernel do a memset(), at the
   cost of having to scan the buffer afterwards because qemu doesn't
   know yet that it contains zeros.

Neither case involves disk accesses if the filesystem metadata is
cached. You're comparing a memset+scan to just a memset (and the more
realistic case should be comparing memset+scan to nothing).

(BTW, buffer_is_zero() does complicated stuff, but 'repe scasb' isn't
among it.)

> > The fully allocated image doesn't suffer from this because (a) it only
> > has to check the first byte in each block and (b) the cost was already
> > there before this patch.
> > 
> > In fact, if null-co supported .bdrv_co_pwrite_zeroes, I think you would
> > get even worse results for your patch because then the pre-patch version
> > doesn't even have to do the memset().
> > 
> >>> (2a) It might be worth noting that on xfs, reading the sparse file took
> >>> longer even before this patch...
> >>>
> >>> (3) qcow2 is different: It benefits from this patch on tmpfs and xfs
> >>> (note that reading a sparse qcow2 file took longer than reading a full
> >>> qcow2 file before this patch!), but it gets pretty much destroyed on
> >>> ext4, too.
> > 
> > I suppose an empty qcow2 with metadata preallocation behaves roughly
> > like sparse raw?
> 
> Yep, more on that below.
> 
> > As long as the qcow2 metadata reflects the allocation status in the
> > image file (which it probably usually does, except with preallocation),
> > it makes sense that qcow2 performs better with just relying on its
> > metadata. Calling an lseek() that just returns the same result is a
> > wasted effort then.
> > 
> >>> (4) As for sparse vmdk images...  Reading them takes longer, but it's
> >>> still fasster than reading full vmdk images, so that's not horrible.
> > 
> > Hm, why is that? Shouldn't vmdk metadata reflect the allocation status
> > in the image file just as well as qcow2 metadata?
> > 
> > But actually, the absolute numbers are much lower than both raw and
> > qcow2, which is a bit surprising. Is there a bug somewhere in vmdk or
> > are we m

Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-07 Thread Max Reitz
On 2018-03-07 17:33, Paolo Bonzini wrote:
> On 07/03/2018 16:57, Max Reitz wrote:
> (2) For sparse raw images, this is absolutely devastating.  Reading them
> now takes more than (ext4) or nearly (xfs) twice as much time as reading
> a fully allocated image.  So much for "if a filesystem driver has any
> sense".
>>> Are you sure that only the filesystem is the problem? Checking for every
>>> single byte of an image whether it is zero has to cost some performance.
>> Well, yes, but "read data location from FS metadata" + "realize it's a
>> hole" + memset() + "repe scasb" shouldn't take twice as much time as
>> "read data location from FS metadata" + "read data from SSD".
>>
>> I expected the "realize it's a hole" part to fall out for free, so this
>> would that memset() + repe scasb take much longer than reading data from
>> the SSD -- and that's just pretty much impossible.
>>
> 
> This makes a lot of sense, but just to double-check, what does profiling
> say?

Oops, right.  I forgot that I forgot to drop the caches in that first
benchmark...
(http://lists.nongnu.org/archive/html/qemu-block/2018-02/msg01166.html)

I don't have a full test run for this RFC version, but with the modified
series I hinted at in
http://lists.nongnu.org/archive/html/qemu-block/2018-03/msg00244.html I get:
- 0.6 s for a sparse qcow2
- 1.3 s for a preallocated qcow2 (basically like a sparse raw file in
this RFC here)
- 4.0 s for a fully allocated qcow2

So that makes more sense.

Max



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-07 Thread Paolo Bonzini
On 07/03/2018 16:57, Max Reitz wrote:
 (2) For sparse raw images, this is absolutely devastating.  Reading them
 now takes more than (ext4) or nearly (xfs) twice as much time as reading
 a fully allocated image.  So much for "if a filesystem driver has any
 sense".
>> Are you sure that only the filesystem is the problem? Checking for every
>> single byte of an image whether it is zero has to cost some performance.
> Well, yes, but "read data location from FS metadata" + "realize it's a
> hole" + memset() + "repe scasb" shouldn't take twice as much time as
> "read data location from FS metadata" + "read data from SSD".
> 
> I expected the "realize it's a hole" part to fall out for free, so this
> would that memset() + repe scasb take much longer than reading data from
> the SSD -- and that's just pretty much impossible.
> 

This makes a lot of sense, but just to double-check, what does profiling
say?

Paolo



Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-07 Thread Max Reitz
On 2018-03-06 18:37, Kevin Wolf wrote:
> Am 06.03.2018 um 14:47 hat Stefan Hajnoczi geschrieben:
>> On Wed, Feb 28, 2018 at 09:11:32PM +0100, Max Reitz wrote:
>>> On 2018-02-28 19:08, Max Reitz wrote:
 On 2018-02-27 17:17, Stefan Hajnoczi wrote:
> On Mon, Feb 26, 2018 at 06:03:13PM +0100, Max Reitz wrote:
>> There are filesystems (among which is tmpfs) that have a hard time
>> reporting allocation status.  That is definitely a bug in them.
>>
>> However, there is no good reason why qemu-img convert should query the
>> allocation status in the first place.  It does zero detection by itself
>> anyway, so we can detect unallocated areas ourselves.
>>
>> Furthermore, if a filesystem driver has any sense, reading unallocated
>> data should take just as much time as lseek(SEEK_DATA) + memset().  So
>> the only overhead we introduce by dropping the manual lseek() call is a
>> memset() in the driver and a buffer_is_zero() in qemu-img, both of which
>> should be relatively quick.
>
> This makes sense.  Which file systems did you test this patch on?

 On tmpfs and xfs, so far.

> XFS, ext4, and tmpfs would be a good minimal test set to prove the
> patch.  Perhaps with two input files:
> 1. A file that is mostly filled with data.
> 2. A file that is only sparsely populated with data.

 And probably with vmdk, which (by default) forbids querying any areas
 larger than 64 kB.

> The time taken should be comparable with the time before this patch.

 Yep, I'll do some benchmarks.
>>>
>>> And the results are in.  I've created 2 GB images on various filesystems
>>> in various formats, then I've either written 64 kB every 32 MB to them
>>> ("sparse"), or left out 64 kB every 32 MB ("full").  Then I've converted
>>> them to null-co:// and took the (real) time through "time". (Script is
>>> attached.)
>>>
>>> I've attached the raw results before and after this patch.  Usually, I
>>> did six runs for each case and dropped the most extreme outlier --
>>> except for full vmdk images, where I've only done one run for each case
>>> because creating these images can take a very long time.
>>>
>>> Here are the differences from before to after:
>>>
>>> sparse raw on tmpfs:+ 19 % (436 ms to 520 ms)
>>> sparse qcow2 on tmpfs:  - 31 % (435 ms to 301 ms)
>>> sparse vmdk on tmpfs:   + 37 % (214 ms to 294 ms)
>>>
>>> sparse raw on xfs:  + 69 % (452 ms to 762 ms)
>>> sparse qcow2 on xfs:- 34 % (462 ms to 304 ms)
>>> sparse vmdk on xfs: + 42 % (210 ms to 298 ms)
>>>
>>> sparse raw on ext4: +360 % (144 ms to 655 ms)
>>> sparse qcow2 on ext4:   +120 % (147 ms to 330 ms)
>>> sparse vmdk on ext4:+ 16 % (253 ms to 293 ms)
>>>
>>>
>>> full raw on tmpfs:  -  9 % (437 ms to 398 ms)
>>> full qcow2 on tmpfs:- 75 % (1.63 s to 403 ms)
>>> full vmdk on tmpfs: -100 % (10 min to 767 ms)
>>>
>>> full raw on xfs:-  1 % (407 ms to 404 ms, insignificant)
>>> full qcow2 on xfs:  -  1 % (410 ms to 404 ms, insignificant)
>>> full vmdk on xfs:   - 33 % (1.05 s to 695 ms)
>>>
>>>
>>>
>>>
>>> full raw on ext4:   -  2 % (308 ms to 301 ms, insignificant)
>>> full qcow2 on ext4: +  2 % (307 ms to 312 ms, insignificant)
>>> full vmdk on ext4:  - 74 % (3.53 s to 839 ms)
>>>
>>>
>>> So...  It's more extreme than I had hoped, that's for sure.  What I
>>> conclude from this is:
>>>
>>> (1) This patch is generally good for nearly fully allocated images.  In
>>> the worst case (on well-behaving filesystems with well-optimized image
>>> formats) it changes nothing.  In the best case, conversion time is
>>> reduced drastically.
> 
> This makes sense. Asking the kernel whether a block is zero only helps
> the performance if the result is yes occasionally, otherwise it's just
> wasted work.
> 
> Maybe we could try to guess the ratio by comparing the number of
> allocated blocks in the image file and the virtual disk size or
> something? Then we could only call lseek() when we can actually expect
> an improvement from it.

Sounds like "qemu should not contain policy" to me.  If the user expects
the image to be fully allocated, they might as well use -S 0.

>>> (2) For sparse raw images, this is absolutely devastating.  Reading them
>>> now takes more than (ext4) or nearly (xfs) twice as much time as reading
>>> a fully allocated image.  So much for "if a filesystem driver has any
>>> sense".
> 
> Are you sure that only the filesystem is the problem? Checking for every
> single byte of an image whether it is zero has to cost some performance.

Well, yes, but "read data location from FS metadata" + "realize it's a
hole" + memset() + "repe scasb" shouldn't take twice as much time as
"read data location from FS metadata" + "read data from SSD".

I expected the "realize it's a hole" part to fall out for free, so this
would that memset() + repe scasb take much longer than reading data from
the SSD -- and t

Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-06 Thread Kevin Wolf
Am 06.03.2018 um 14:47 hat Stefan Hajnoczi geschrieben:
> On Wed, Feb 28, 2018 at 09:11:32PM +0100, Max Reitz wrote:
> > On 2018-02-28 19:08, Max Reitz wrote:
> > > On 2018-02-27 17:17, Stefan Hajnoczi wrote:
> > >> On Mon, Feb 26, 2018 at 06:03:13PM +0100, Max Reitz wrote:
> > >>> There are filesystems (among which is tmpfs) that have a hard time
> > >>> reporting allocation status.  That is definitely a bug in them.
> > >>>
> > >>> However, there is no good reason why qemu-img convert should query the
> > >>> allocation status in the first place.  It does zero detection by itself
> > >>> anyway, so we can detect unallocated areas ourselves.
> > >>>
> > >>> Furthermore, if a filesystem driver has any sense, reading unallocated
> > >>> data should take just as much time as lseek(SEEK_DATA) + memset().  So
> > >>> the only overhead we introduce by dropping the manual lseek() call is a
> > >>> memset() in the driver and a buffer_is_zero() in qemu-img, both of which
> > >>> should be relatively quick.
> > >>
> > >> This makes sense.  Which file systems did you test this patch on?
> > > 
> > > On tmpfs and xfs, so far.
> > > 
> > >> XFS, ext4, and tmpfs would be a good minimal test set to prove the
> > >> patch.  Perhaps with two input files:
> > >> 1. A file that is mostly filled with data.
> > >> 2. A file that is only sparsely populated with data.
> > > 
> > > And probably with vmdk, which (by default) forbids querying any areas
> > > larger than 64 kB.
> > > 
> > >> The time taken should be comparable with the time before this patch.
> > > 
> > > Yep, I'll do some benchmarks.
> > 
> > And the results are in.  I've created 2 GB images on various filesystems
> > in various formats, then I've either written 64 kB every 32 MB to them
> > ("sparse"), or left out 64 kB every 32 MB ("full").  Then I've converted
> > them to null-co:// and took the (real) time through "time". (Script is
> > attached.)
> > 
> > I've attached the raw results before and after this patch.  Usually, I
> > did six runs for each case and dropped the most extreme outlier --
> > except for full vmdk images, where I've only done one run for each case
> > because creating these images can take a very long time.
> > 
> > Here are the differences from before to after:
> > 
> > sparse raw on tmpfs:+ 19 % (436 ms to 520 ms)
> > sparse qcow2 on tmpfs:  - 31 % (435 ms to 301 ms)
> > sparse vmdk on tmpfs:   + 37 % (214 ms to 294 ms)
> > 
> > sparse raw on xfs:  + 69 % (452 ms to 762 ms)
> > sparse qcow2 on xfs:- 34 % (462 ms to 304 ms)
> > sparse vmdk on xfs: + 42 % (210 ms to 298 ms)
> > 
> > sparse raw on ext4: +360 % (144 ms to 655 ms)
> > sparse qcow2 on ext4:   +120 % (147 ms to 330 ms)
> > sparse vmdk on ext4:+ 16 % (253 ms to 293 ms)
> > 
> > 
> > full raw on tmpfs:  -  9 % (437 ms to 398 ms)
> > full qcow2 on tmpfs:- 75 % (1.63 s to 403 ms)
> > full vmdk on tmpfs: -100 % (10 min to 767 ms)
> > 
> > full raw on xfs:-  1 % (407 ms to 404 ms, insignificant)
> > full qcow2 on xfs:  -  1 % (410 ms to 404 ms, insignificant)
> > full vmdk on xfs:   - 33 % (1.05 s to 695 ms)
> > 
> > 
> > 
> > 
> > full raw on ext4:   -  2 % (308 ms to 301 ms, insignificant)
> > full qcow2 on ext4: +  2 % (307 ms to 312 ms, insignificant)
> > full vmdk on ext4:  - 74 % (3.53 s to 839 ms)
> > 
> > 
> > So...  It's more extreme than I had hoped, that's for sure.  What I
> > conclude from this is:
> > 
> > (1) This patch is generally good for nearly fully allocated images.  In
> > the worst case (on well-behaving filesystems with well-optimized image
> > formats) it changes nothing.  In the best case, conversion time is
> > reduced drastically.

This makes sense. Asking the kernel whether a block is zero only helps
the performance if the result is yes occasionally, otherwise it's just
wasted work.

Maybe we could try to guess the ratio by comparing the number of
allocated blocks in the image file and the virtual disk size or
something? Then we could only call lseek() when we can actually expect
an improvement from it.

> > (2) For sparse raw images, this is absolutely devastating.  Reading them
> > now takes more than (ext4) or nearly (xfs) twice as much time as reading
> > a fully allocated image.  So much for "if a filesystem driver has any
> > sense".

Are you sure that only the filesystem is the problem? Checking for every
single byte of an image whether it is zero has to cost some performance.
The fully allocated image doesn't suffer from this because (a) it only
has to check the first byte in each block and (b) the cost was already
there before this patch.

In fact, if null-co supported .bdrv_co_pwrite_zeroes, I think you would
get even worse results for your patch because then the pre-patch version
doesn't even have to do the memset().

> > (2a) It might be worth noting that on xfs, reading the sparse file took
> > longer even before this patch...
> > 
> > (3) qcow2 is different: It benefits from t

Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-03-06 Thread Stefan Hajnoczi
On Wed, Feb 28, 2018 at 09:11:32PM +0100, Max Reitz wrote:
> On 2018-02-28 19:08, Max Reitz wrote:
> > On 2018-02-27 17:17, Stefan Hajnoczi wrote:
> >> On Mon, Feb 26, 2018 at 06:03:13PM +0100, Max Reitz wrote:
> >>> There are filesystems (among which is tmpfs) that have a hard time
> >>> reporting allocation status.  That is definitely a bug in them.
> >>>
> >>> However, there is no good reason why qemu-img convert should query the
> >>> allocation status in the first place.  It does zero detection by itself
> >>> anyway, so we can detect unallocated areas ourselves.
> >>>
> >>> Furthermore, if a filesystem driver has any sense, reading unallocated
> >>> data should take just as much time as lseek(SEEK_DATA) + memset().  So
> >>> the only overhead we introduce by dropping the manual lseek() call is a
> >>> memset() in the driver and a buffer_is_zero() in qemu-img, both of which
> >>> should be relatively quick.
> >>
> >> This makes sense.  Which file systems did you test this patch on?
> > 
> > On tmpfs and xfs, so far.
> > 
> >> XFS, ext4, and tmpfs would be a good minimal test set to prove the
> >> patch.  Perhaps with two input files:
> >> 1. A file that is mostly filled with data.
> >> 2. A file that is only sparsely populated with data.
> > 
> > And probably with vmdk, which (by default) forbids querying any areas
> > larger than 64 kB.
> > 
> >> The time taken should be comparable with the time before this patch.
> > 
> > Yep, I'll do some benchmarks.
> 
> And the results are in.  I've created 2 GB images on various filesystems
> in various formats, then I've either written 64 kB every 32 MB to them
> ("sparse"), or left out 64 kB every 32 MB ("full").  Then I've converted
> them to null-co:// and took the (real) time through "time". (Script is
> attached.)
> 
> I've attached the raw results before and after this patch.  Usually, I
> did six runs for each case and dropped the most extreme outlier --
> except for full vmdk images, where I've only done one run for each case
> because creating these images can take a very long time.
> 
> Here are the differences from before to after:
> 
> sparse raw on tmpfs:+ 19 % (436 ms to 520 ms)
> sparse qcow2 on tmpfs:  - 31 % (435 ms to 301 ms)
> sparse vmdk on tmpfs:   + 37 % (214 ms to 294 ms)
> 
> sparse raw on xfs:  + 69 % (452 ms to 762 ms)
> sparse qcow2 on xfs:- 34 % (462 ms to 304 ms)
> sparse vmdk on xfs: + 42 % (210 ms to 298 ms)
> 
> sparse raw on ext4: +360 % (144 ms to 655 ms)
> sparse qcow2 on ext4:   +120 % (147 ms to 330 ms)
> sparse vmdk on ext4:+ 16 % (253 ms to 293 ms)
> 
> 
> full raw on tmpfs:  -  9 % (437 ms to 398 ms)
> full qcow2 on tmpfs:- 75 % (1.63 s to 403 ms)
> full vmdk on tmpfs: -100 % (10 min to 767 ms)
> 
> full raw on xfs:-  1 % (407 ms to 404 ms, insignificant)
> full qcow2 on xfs:  -  1 % (410 ms to 404 ms, insignificant)
> full vmdk on xfs:   - 33 % (1.05 s to 695 ms)
> 
> 
> 
> 
> full raw on ext4:   -  2 % (308 ms to 301 ms, insignificant)
> full qcow2 on ext4: +  2 % (307 ms to 312 ms, insignificant)
> full vmdk on ext4:  - 74 % (3.53 s to 839 ms)
> 
> 
> So...  It's more extreme than I had hoped, that's for sure.  What I
> conclude from this is:
> 
> (1) This patch is generally good for nearly fully allocated images.  In
> the worst case (on well-behaving filesystems with well-optimized image
> formats) it changes nothing.  In the best case, conversion time is
> reduced drastically.
> 
> (2) For sparse raw images, this is absolutely devastating.  Reading them
> now takes more than (ext4) or nearly (xfs) twice as much time as reading
> a fully allocated image.  So much for "if a filesystem driver has any
> sense".
> 
> (2a) It might be worth noting that on xfs, reading the sparse file took
> longer even before this patch...
> 
> (3) qcow2 is different: It benefits from this patch on tmpfs and xfs
> (note that reading a sparse qcow2 file took longer than reading a full
> qcow2 file before this patch!), but it gets pretty much destroyed on
> ext4, too.
> 
> (4) As for sparse vmdk images...  Reading them takes longer, but it's
> still fasster than reading full vmdk images, so that's not horrible.
> 
> 
> So there we are.  I was wrong about filesystem drivers having any sense,
> so this patch can indeed have a hugely negative impact.
> 
> I would argue that conversion time for full images is more important,
> because that's probably the main use case; but the thing is that here
> this patch only helps for tmpfs and vmdk.  We don't care too much about
> vmdk, and the fact that tmpfs takes so long simply is a bug.
> 
> I guess the xfs/tmpfs results would still be in a range where they are
> barely acceptable (because it's mainly a qcow2 vs. raw tradeoff), but
> the ext4 horrors probably make this patch a no-go in its current form.
> 
> In any case it's interesting to see that even the current qemu-img
> convert takes longer to read sparsely allocated qcow2/raw files

Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-02-28 Thread Max Reitz
On 2018-02-28 21:11, Max Reitz wrote:
> On 2018-02-28 19:08, Max Reitz wrote:

[...]

> In any case it's interesting to see that even the current qemu-img
> convert takes longer to read sparsely allocated qcow2/raw files from xfs
> than fully allocated images...

(That's because I didn't drop the caches after the qemu-io run...  If I
do that, reading the full image takes its four seconds.  But that
doesn't make the full results better, and the sparse results don't
change much.)

Max



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-02-28 Thread Max Reitz
On 2018-02-28 19:08, Max Reitz wrote:
> On 2018-02-27 17:17, Stefan Hajnoczi wrote:
>> On Mon, Feb 26, 2018 at 06:03:13PM +0100, Max Reitz wrote:
>>> There are filesystems (among which is tmpfs) that have a hard time
>>> reporting allocation status.  That is definitely a bug in them.
>>>
>>> However, there is no good reason why qemu-img convert should query the
>>> allocation status in the first place.  It does zero detection by itself
>>> anyway, so we can detect unallocated areas ourselves.
>>>
>>> Furthermore, if a filesystem driver has any sense, reading unallocated
>>> data should take just as much time as lseek(SEEK_DATA) + memset().  So
>>> the only overhead we introduce by dropping the manual lseek() call is a
>>> memset() in the driver and a buffer_is_zero() in qemu-img, both of which
>>> should be relatively quick.
>>
>> This makes sense.  Which file systems did you test this patch on?
> 
> On tmpfs and xfs, so far.
> 
>> XFS, ext4, and tmpfs would be a good minimal test set to prove the
>> patch.  Perhaps with two input files:
>> 1. A file that is mostly filled with data.
>> 2. A file that is only sparsely populated with data.
> 
> And probably with vmdk, which (by default) forbids querying any areas
> larger than 64 kB.
> 
>> The time taken should be comparable with the time before this patch.
> 
> Yep, I'll do some benchmarks.

And the results are in.  I've created 2 GB images on various filesystems
in various formats, then I've either written 64 kB every 32 MB to them
("sparse"), or left out 64 kB every 32 MB ("full").  Then I've converted
them to null-co:// and took the (real) time through "time". (Script is
attached.)

I've attached the raw results before and after this patch.  Usually, I
did six runs for each case and dropped the most extreme outlier --
except for full vmdk images, where I've only done one run for each case
because creating these images can take a very long time.

Here are the differences from before to after:

sparse raw on tmpfs:+ 19 % (436 ms to 520 ms)
sparse qcow2 on tmpfs:  - 31 % (435 ms to 301 ms)
sparse vmdk on tmpfs:   + 37 % (214 ms to 294 ms)

sparse raw on xfs:  + 69 % (452 ms to 762 ms)
sparse qcow2 on xfs:- 34 % (462 ms to 304 ms)
sparse vmdk on xfs: + 42 % (210 ms to 298 ms)

sparse raw on ext4: +360 % (144 ms to 655 ms)
sparse qcow2 on ext4:   +120 % (147 ms to 330 ms)
sparse vmdk on ext4:+ 16 % (253 ms to 293 ms)


full raw on tmpfs:  -  9 % (437 ms to 398 ms)
full qcow2 on tmpfs:- 75 % (1.63 s to 403 ms)
full vmdk on tmpfs: -100 % (10 min to 767 ms)

full raw on xfs:-  1 % (407 ms to 404 ms, insignificant)
full qcow2 on xfs:  -  1 % (410 ms to 404 ms, insignificant)
full vmdk on xfs:   - 33 % (1.05 s to 695 ms)




full raw on ext4:   -  2 % (308 ms to 301 ms, insignificant)
full qcow2 on ext4: +  2 % (307 ms to 312 ms, insignificant)
full vmdk on ext4:  - 74 % (3.53 s to 839 ms)


So...  It's more extreme than I had hoped, that's for sure.  What I
conclude from this is:

(1) This patch is generally good for nearly fully allocated images.  In
the worst case (on well-behaving filesystems with well-optimized image
formats) it changes nothing.  In the best case, conversion time is
reduced drastically.

(2) For sparse raw images, this is absolutely devastating.  Reading them
now takes more than (ext4) or nearly (xfs) twice as much time as reading
a fully allocated image.  So much for "if a filesystem driver has any
sense".

(2a) It might be worth noting that on xfs, reading the sparse file took
longer even before this patch...

(3) qcow2 is different: It benefits from this patch on tmpfs and xfs
(note that reading a sparse qcow2 file took longer than reading a full
qcow2 file before this patch!), but it gets pretty much destroyed on
ext4, too.

(4) As for sparse vmdk images...  Reading them takes longer, but it's
still fasster than reading full vmdk images, so that's not horrible.


So there we are.  I was wrong about filesystem drivers having any sense,
so this patch can indeed have a hugely negative impact.

I would argue that conversion time for full images is more important,
because that's probably the main use case; but the thing is that here
this patch only helps for tmpfs and vmdk.  We don't care too much about
vmdk, and the fact that tmpfs takes so long simply is a bug.

I guess the xfs/tmpfs results would still be in a range where they are
barely acceptable (because it's mainly a qcow2 vs. raw tradeoff), but
the ext4 horrors probably make this patch a no-go in its current form.

In any case it's interesting to see that even the current qemu-img
convert takes longer to read sparsely allocated qcow2/raw files from xfs
than fully allocated images...


So I guess I'll re-send this patch where the change is done only for
-S 0.

Max


test.sh
Description: application/shellscript
Testing: raw on tmpfs (sparse): 0.436 ±0.012
real0.426 0.444 0.447 0.442 (0.500) 0.421

Testing: qcow2 on tmpfs

Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-02-28 Thread Max Reitz
On 2018-02-27 17:17, Stefan Hajnoczi wrote:
> On Mon, Feb 26, 2018 at 06:03:13PM +0100, Max Reitz wrote:
>> There are filesystems (among which is tmpfs) that have a hard time
>> reporting allocation status.  That is definitely a bug in them.
>>
>> However, there is no good reason why qemu-img convert should query the
>> allocation status in the first place.  It does zero detection by itself
>> anyway, so we can detect unallocated areas ourselves.
>>
>> Furthermore, if a filesystem driver has any sense, reading unallocated
>> data should take just as much time as lseek(SEEK_DATA) + memset().  So
>> the only overhead we introduce by dropping the manual lseek() call is a
>> memset() in the driver and a buffer_is_zero() in qemu-img, both of which
>> should be relatively quick.
> 
> This makes sense.  Which file systems did you test this patch on?

On tmpfs and xfs, so far.

> XFS, ext4, and tmpfs would be a good minimal test set to prove the
> patch.  Perhaps with two input files:
> 1. A file that is mostly filled with data.
> 2. A file that is only sparsely populated with data.

And probably with vmdk, which (by default) forbids querying any areas
larger than 64 kB.

> The time taken should be comparable with the time before this patch.

Yep, I'll do some benchmarks.

Max



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-block] [Qemu-devel] [RFC] qemu-img: Drop BLK_ZERO from convert

2018-02-27 Thread Stefan Hajnoczi
On Mon, Feb 26, 2018 at 06:03:13PM +0100, Max Reitz wrote:
> There are filesystems (among which is tmpfs) that have a hard time
> reporting allocation status.  That is definitely a bug in them.
> 
> However, there is no good reason why qemu-img convert should query the
> allocation status in the first place.  It does zero detection by itself
> anyway, so we can detect unallocated areas ourselves.
> 
> Furthermore, if a filesystem driver has any sense, reading unallocated
> data should take just as much time as lseek(SEEK_DATA) + memset().  So
> the only overhead we introduce by dropping the manual lseek() call is a
> memset() in the driver and a buffer_is_zero() in qemu-img, both of which
> should be relatively quick.

This makes sense.  Which file systems did you test this patch on?

XFS, ext4, and tmpfs would be a good minimal test set to prove the
patch.  Perhaps with two input files:
1. A file that is mostly filled with data.
2. A file that is only sparsely populated with data.

The time taken should be comparable with the time before this patch.


signature.asc
Description: PGP signature