> On 19 Jun 2024, at 8:54, Justin <just...@safe-mbox.com> wrote:
> 
>>    I've run strace and I see calls to fallocate with these flags:
>>    FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE
>> 
>>    I've tried passing these options: discard=off,detect-zeroes=off but
>>    this does not help. This is the full set of relevant options I'm
>>    using:
>> 
>>    -drive file=/vms/vm0/drive,format=raw,if=virtio,discard=off,detect-zeroes=
>>    off
>> 
>> You don't need to disable detect-zeros - in my tests it makes dd if=/dev/zero
>> 5 times faster (770 MiB/s -> 3 GiB/s) since zero writes are converted to
>> fallocate(FALLOC_FL_KEEP_SIZE|FALLOC_FL_ZERO_RANGE).
>> 
>> The issue seems to be ignoring the discard option when opening the image,
>> and is fixed by this:
>> https://lists.nongnu.org/archive/html/qemu-block/2024-06/msg00198.html
> 
> Thanks. When might this patch (or something similar) be merged?

The patch need more work, when the work is done and qemu maintainers are happy 
it is a good estimate :-)

> 
>> I think the change needs more work to keep the default behavior
>> since most users want sparse images, but it seems to do what you
>> want - keeping images thick.
> 
> It seems that this patch is making the code align more closely with
> the documentation? To, me, it appeared fairly clear that discard=unmap
> would punch holes, and thus the inverse setting would stop hole
> punching.

Punching holes is used both for discard (e.g. fstrim in the guest) and for 
writing zeros.

I think that discard should work only when you set discard=unmap or 
disacard=on, but writing zeros should always punch holes unless you set 
discard=off. I don’t think this behavior is documented now but it should be, at 
least the intent to keep images sparse when possible.

Nir

Reply via email to