Skip to contentSkip to conversation

callout to *file in bdrv_co_get_block_status

Qemu-devel Peter Lieven 3 participants 23 messages Mar 17, 2017 – Mar 31, 2017

lore
Share & tools
lore
#0 lore raw

Hi,

I tried to debug why qemu-img convert with a VMDK source laying on a tmpfs is horrible slow.

For some reason a lseek on a tmpfs is slow. Strictly speaking the lseek in find_allocation in file-posix.c

is slow.

When qemu-img convert iterates over all sectors of a VMDK file to check their allocation status it ends

up checking allocation status of all allocated sectors due to the following condition in bdrv_co_get_block_status:

    if (*file && *file != bs &&
        (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
        (ret & BDRV_BLOCK_OFFSET_VALID)) {
        BlockDriverState *file2;
        int file_pnum;
        ret2 = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
                                        *pnum, &file_pnum, &file2);
        if (ret2 >= 0) {
            /* Ignore errors.  This is just providing extra information, it
             * is useful but not necessary.
             */
            if (!file_pnum) {
                /* !file_pnum indicates an offset at or beyond the EOF; it is
                 * perfectly valid for the format block driver to point to such
                 * offsets, so catch it and mark everything as zero */
                ret |= BDRV_BLOCK_ZERO;
            } else {
                /* Limit request to the range reported by the protocol driver */
                *pnum = file_pnum;
                ret |= (ret2 & BDRV_BLOCK_ZERO);
            }
        }
    }

Does anybody remember for what circumstances this case this was added? In case of an container format

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

Thanks,

Peter

#1 lore raw
Quoted 40 lines · Peter Lieven

Hi,

I tried to debug why qemu-img convert with a VMDK source laying on a tmpfs is horrible slow.

For some reason a lseek on a tmpfs is slow. Strictly speaking the lseek in find_allocation in file-posix.c

is slow.

When qemu-img convert iterates over all sectors of a VMDK file to check their allocation status it ends

up checking allocation status of all allocated sectors due to the following condition in bdrv_co_get_block_status:

    if (*file && *file != bs &&
        (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
        (ret & BDRV_BLOCK_OFFSET_VALID)) {
        BlockDriverState *file2;
        int file_pnum;
        ret2 = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
                                        *pnum, &file_pnum, &file2);
        if (ret2 >= 0) {
            /* Ignore errors.  This is just providing extra information, it
             * is useful but not necessary.
             */
            if (!file_pnum) {
                /* !file_pnum indicates an offset at or beyond the EOF; it is
                 * perfectly valid for the format block driver to point to such
                 * offsets, so catch it and mark everything as zero */
                ret |= BDRV_BLOCK_ZERO;
            } else {
                /* Limit request to the range reported by the protocol driver */
                *pnum = file_pnum;
                ret |= (ret2 & BDRV_BLOCK_ZERO);
            }
        }
    }
Quoted 3 lines

Does anybody remember for what circumstances this case this was added? In case of an container format

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Paolo

#2 lore raw

Am 17.03.2017 um 11:59 schrieb Paolo Bonzini:

Quoted 42 lines · Peter Lieven
Quoted 40 lines

Hi,

I tried to debug why qemu-img convert with a VMDK source laying on a tmpfs is horrible slow.

For some reason a lseek on a tmpfs is slow. Strictly speaking the lseek in find_allocation in file-posix.c

is slow.

When qemu-img convert iterates over all sectors of a VMDK file to check their allocation status it ends

up checking allocation status of all allocated sectors due to the following condition in bdrv_co_get_block_status:

    if (*file && *file != bs &&
        (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
        (ret & BDRV_BLOCK_OFFSET_VALID)) {
        BlockDriverState *file2;
        int file_pnum;
        ret2 = bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS,
                                        *pnum, &file_pnum, &file2);
        if (ret2 >= 0) {
            /* Ignore errors.  This is just providing extra information, it
             * is useful but not necessary.
             */
            if (!file_pnum) {
                /* !file_pnum indicates an offset at or beyond the EOF; it is
                 * perfectly valid for the format block driver to point to such
                 * offsets, so catch it and mark everything as zero */
                ret |= BDRV_BLOCK_ZERO;
            } else {
                /* Limit request to the range reported by the protocol driver */
                *pnum = file_pnum;
                ret |= (ret2 & BDRV_BLOCK_ZERO);
            }
        }
    }
Quoted 5 lines
Quoted 3 lines

Does anybody remember for what circumstances this case this was added? In case of an container format

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

Peter

#3 lore raw
Quoted 6 lines · Peter Lieven
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Paolo

#4 lore raw

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 10 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

Peter

#5 lore raw
Quoted 15 lines · Peter Lieven

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 10 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

Quoted 6 lines

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

Fam

#6 lore raw
Quoted 18 lines · Fam Zheng
Quoted 17 lines · Peter Lieven

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 10 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

Quoted 8 lines
Quoted 4 lines

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Paolo

#7 lore raw
Quoted 24 lines · Paolo Bonzini
Quoted 21 lines · Fam Zheng
Quoted 20 lines · Peter Lieven

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 10 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Raw is a little special, it could have forwarded the call to *file in its BlockDriver callback. Most formats with metadata stores zero/nonzero information in L1/L2 tables. For qcow2 and VMDK I think it's okay to just trust meta data on zero/nonzero.

Fam

#8 lore raw

Am 20.03.2017 um 12:49 schrieb Fam Zheng:

Quoted 22 lines · Paolo Bonzini
Quoted 21 lines · Fam Zheng
Quoted 19 lines · Peter Lieven
Quoted 18 lines

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 9 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Raw is a little special, it could have forwarded the call to *file in its BlockDriver callback. Most formats with metadata stores zero/nonzero information

I thinks thats the check *file != bs for, right?

Quoted 2 lines

in L1/L2 tables. For qcow2 and VMDK I think it's okay to just trust meta data on zero/nonzero.

So what are the really Formats that we don't trust? And is it worth that we add this (maybe expensive) callout to lseek via find_allocation for any format altough we already know the answer from the metadata?

Peter

author Reviewed-by Eric Blake
#9 lore raw
In reply to Fam Zheng

Am 20.03.2017 um 12:49 schrieb Fam Zheng:

Quoted 26 lines · Paolo Bonzini
Quoted 25 lines · Fam Zheng
Quoted 23 lines · Peter Lieven
Quoted 13 lines

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 9 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

Quoted 6 lines

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

Quoted 8 lines
Quoted 2 lines

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Raw is a little special, it could have forwarded the call to *file in its BlockDriver callback. Most formats with metadata stores zero/nonzero information in L1/L2 tables. For qcow2 and VMDK I think it's okay to just trust meta data on zero/nonzero.

Fam

BTW, the extra check was added in

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Peter

#10 lore raw

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 44 lines

Am 20.03.2017 um 12:49 schrieb Fam Zheng:

Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Peter Lieven
Quoted 13 lines

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 9 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

Quoted 6 lines

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

Quoted 8 lines
Quoted 2 lines

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Raw is a little special, it could have forwarded the call to *file in its BlockDriver callback. Most formats with metadata stores zero/nonzero information in L1/L2 tables. For qcow2 and VMDK I think it's okay to just trust meta data on zero/nonzero.

Fam

BTW, the extra check was added in

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

Quoted 8 lines

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

Peter

#11 lore raw
Quoted 50 lines · Peter Lieven

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 49 lines

Am 20.03.2017 um 12:49 schrieb Fam Zheng:

Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Peter Lieven
Quoted 13 lines

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 9 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

Quoted 6 lines

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

Quoted 8 lines
Quoted 2 lines

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Raw is a little special, it could have forwarded the call to *file in its BlockDriver callback. Most formats with metadata stores zero/nonzero information in L1/L2 tables. For qcow2 and VMDK I think it's okay to just trust meta data on zero/nonzero.

Fam

BTW, the extra check was added in

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

Quoted 8 lines
Quoted 3 lines

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

It was meant for both raw and qcow2.

Paolo

#12 lore raw

Am 20.03.2017 um 14:23 schrieb Paolo Bonzini:

Quoted 51 lines · Peter Lieven
Quoted 49 lines

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 48 lines

Am 20.03.2017 um 12:49 schrieb Fam Zheng:

Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Fam Zheng
Quoted 23 lines · Peter Lieven
Quoted 13 lines

Am 17.03.2017 um 12:16 schrieb Paolo Bonzini:

Quoted 9 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

Okay, in this case the second call out to *file will not happen. It only happens if the metadata says it contains data. So where does it actually help?

Quoted 6 lines

The condition is: (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID))

So from my view it can only have any effect if the metadata returns BDRV_BLOCK_DATA, but the protocol driver returns BDRV_BLOCK_ZERO.

This can only happen if I partially write to a cluster, or am I wrong here?

I think you have a point. The metadata should have said BDRV_BLOCK_ZERO if protocol would say BDRV_BLOCK_ZERO - there is no reason the format driver cannot know.

Quoted 8 lines
Quoted 2 lines

That's true of qcow2, but many formats (including raw :)) don't know about BDRV_BLOCK_ZERO.

Raw is a little special, it could have forwarded the call to *file in its BlockDriver callback. Most formats with metadata stores zero/nonzero information in L1/L2 tables. For qcow2 and VMDK I think it's okay to just trust meta data on zero/nonzero.

Fam

BTW, the extra check was added in

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

It was meant for both raw and qcow2.

Okay, but as Fam mentioned qcow2 Metadata should know that a cluster is zero. Do you remember what the issue was?

Peter

#13 lore raw
Quoted 17 lines · Peter Lieven

Am 20.03.2017 um 14:23 schrieb Paolo Bonzini:

Quoted 16 lines · Peter Lieven
Quoted 15 lines

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 14 lines

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

It was meant for both raw and qcow2.

Okay, but as Fam mentioned qcow2 Metadata should know that a cluster is zero. Do you remember what the issue was?

I said that already---preallocated metadata. Also, at the time pre-qcow2v3 was more important.

Are you using libiscsi, block devices or files?

Paolo

#14 lore raw

Am 20.03.2017 um 15:05 schrieb Paolo Bonzini:

Quoted 23 lines · Peter Lieven
Quoted 21 lines

Am 20.03.2017 um 14:23 schrieb Paolo Bonzini:

Quoted 20 lines · Peter Lieven
Quoted 19 lines

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 6 lines

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

Quoted 8 lines

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It was meant for both raw and qcow2.

Okay, but as Fam mentioned qcow2 Metadata should know that a cluster is zero. Do you remember what the issue was?

I said that already---preallocated metadata. Also, at the time pre-qcow2v3 was more important.

Yes, but Fam said that with preallocated metadata the clusters should be zero, or was that not true before qcow2v3?

Quoted 2 lines

Are you using libiscsi, block devices or files?

Its a mixture. raw with libiscsi or lvm and qcow2 and vmdk either with libnfs or on local storage.

I stumbled across the issue with lseek on a tmpfs because in the build process for our templates I temporarily have vmdks on a tmpfs and it takes ages before qemu-img convert starts to run (it iterates over every 64kb cluster with that callout to find_allocation and for some reason lseek is very slow on tmpfs).

Peter

#15 lore raw
Quoted 24 lines · Peter Lieven

Am 20.03.2017 um 15:05 schrieb Paolo Bonzini:

Quoted 23 lines · Peter Lieven
Quoted 21 lines

Am 20.03.2017 um 14:23 schrieb Paolo Bonzini:

Quoted 20 lines · Peter Lieven
Quoted 19 lines

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 6 lines

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

Quoted 8 lines

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It was meant for both raw and qcow2.

Okay, but as Fam mentioned qcow2 Metadata should know that a cluster is zero. Do you remember what the issue was?

I said that already---preallocated metadata. Also, at the time pre-qcow2v3 was more important.

Yes, but Fam said that with preallocated metadata the clusters should be zero, or was that not true before qcow2v3?

Zero clusters didn't exist before qcow2v3 I think.

Quoted 7 lines
Quoted 1 line

Are you using libiscsi, block devices or files?

Its a mixture. raw with libiscsi or lvm and qcow2 and vmdk either with libnfs or on local storage.

I stumbled across the issue with lseek on a tmpfs because in the build process for our templates I temporarily have vmdks on a tmpfs and it takes ages before qemu-img convert starts to run (it iterates over every 64kb cluster with that callout to find_allocation and for some reason lseek is very slow on tmpfs).

Ok, thanks. Perhaps it's worth benchmarking tmpfs specifically. Apart from the system call overhead (which does not really matter if you're going to do a read), lseek on other filesystems should not be any slower than read.

Paolo

#16 lore raw

Am 20.03.2017 um 17:56 schrieb Paolo Bonzini:

Quoted 37 lines · Peter Lieven
Quoted 23 lines

Am 20.03.2017 um 15:05 schrieb Paolo Bonzini:

Quoted 22 lines · Peter Lieven
Quoted 21 lines

Am 20.03.2017 um 14:23 schrieb Paolo Bonzini:

Quoted 20 lines · Peter Lieven
Quoted 19 lines

Am 20.03.2017 um 13:47 schrieb Peter Lieven:

Quoted 6 lines

commit 5daa74a6ebce7543aaad178c4061dc087bb4c705

Author: Paolo Bonzini <[email protected]>
Date:   Wed Sep 4 19:00:38 2013 +0200

block: look for zero blocks in bs->file

Quoted 8 lines

It was introduced while introducing bdv_get_block_status. I don't know what the real

issue was that was addressed with this patch?

Is it possible that this optimization was added especially for RAW? I was believing that raw would forward the get_block_status call to bs->file, but it looks it doesn't. If this one here was for RAW would it be an option to move this callout to the raw-format driver and remove it from the generic code?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It was meant for both raw and qcow2.

Okay, but as Fam mentioned qcow2 Metadata should know that a cluster is zero. Do you remember what the issue was?

I said that already---preallocated metadata. Also, at the time pre-qcow2v3 was more important.

Yes, but Fam said that with preallocated metadata the clusters should be zero, or was that not true before qcow2v3?

Zero clusters didn't exist before qcow2v3 I think.

Quoted 3 lines
Quoted 1 line

Are you using libiscsi, block devices or files?

Its a mixture. raw with libiscsi or lvm and qcow2 and vmdk either with libnfs or on local storage.

Quoted 7 lines
Quoted 3 lines

I stumbled across the issue with lseek on a tmpfs because in the build process for our templates I temporarily have vmdks on a tmpfs and it takes ages before qemu-img convert starts to run (it iterates over every 64kb cluster with that callout to find_allocation and for some reason lseek is very slow on tmpfs).

Ok, thanks. Perhaps it's worth benchmarking tmpfs specifically. Apart from the system call overhead (which does not really matter if you're going to do a read), lseek on other filesystems should not be any slower than read.

Okay, but the even the read is not really necessary if the metadata is correct? Would it be an idea to introduce an inverse flag live BDRV_BLOCK_NOT_ZERO for cases where we know that there is really DATA and thus can avoid the second callout?

Peter

#17 lore raw
Quoted 7 lines · Peter Lieven
Quoted 7 lines
Quoted 7 lines

I stumbled across the issue with lseek on a tmpfs because in the build process for our templates
I temporarily have vmdks on a tmpfs and it takes ages before qemu-img convert starts to run (it iterates
over every 64kb cluster with that callout to find_allocation and for some reason lseek is very slow on tmpfs).

Quoted 7 lines
Quoted 4 lines

Ok, thanks. Perhaps it's worth benchmarking tmpfs specifically. Apart from the system call overhead (which does not really matter if you're going to do a read), lseek on other filesystems should not be any slower than read.

Okay, but the even the read is not really necessary if the metadata is correct?

Yeah, what I mean is:

- if you're going to do a read of non-zero blocks, the lseek you do before reading those blocks should not matter.

- if you're going to skip the read of non-zero blocks, the lseek you do is always going to be faster than reading them and then checking with buffer_is_nonzero.

Quoted 3 lines

Would it be an idea to introduce an inverse flag live BDRV_BLOCK_NOT_ZERO for cases where we know that there is really DATA and thus can avoid the second callout?

How would you know that a block is nonzero?

Paolo

#18 lore raw

Am 27.03.2017 um 17:06 schrieb Paolo Bonzini:

Quoted 19 lines · Peter Lieven
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

I stumbled across the issue with lseek on a tmpfs because in the build process for our templates
I temporarily have vmdks on a tmpfs and it takes ages before qemu-img convert starts to run (it iterates
over every 64kb cluster with that callout to find_allocation and for some reason lseek is very slow on tmpfs).

Quoted 6 lines
Quoted 4 lines

Ok, thanks. Perhaps it's worth benchmarking tmpfs specifically. Apart from the system call overhead (which does not really matter if you're going to do a read), lseek on other filesystems should not be any slower than read.

Okay, but the even the read is not really necessary if the metadata is correct?

Yeah, what I mean is:

- if you're going to do a read of non-zero blocks, the lseek you do before reading those blocks should not matter.

Quoted 8 lines

- if you're going to skip the read of non-zero blocks, the lseek you do is always going to be faster than reading them and then checking with buffer_is_nonzero.

Quoted 3 lines

Would it be an idea to introduce an inverse flag live BDRV_BLOCK_NOT_ZERO for cases where we know that there is really DATA and thus can avoid the second callout?

How would you know that a block is nonzero?

I would trust the metadata. At least for VMDK and QCOW2v3. Bad idea?

Peter

#19 lore raw
Quoted 6 lines · Peter Lieven
Quoted 4 lines
Quoted 3 lines

Would it be an idea to introduce an inverse flag live BDRV_BLOCK_NOT_ZERO for cases where we know that there is really DATA and thus can avoid the second callout?

How would you know that a block is nonzero?

I would trust the metadata. At least for VMDK and QCOW2v3. Bad idea?

The metadata only tells you that a block is zero, not that it's nonzero.
What you are suggesting is really the same as removing the recursion.
However, I still haven't understood clearly if it's a QEMU or tmpfs bug; if it's a tmpfs bug your suggestion would not fix tmpfs slowness on raw images.

Paolo

#20 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Peter Lieven
Quoted 1 line
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

I think from qemu-img convert's perspective, it doesn't care about the *file status if the metadata already speaks, because, like you said, the data shows up as zeroes.

In other words I think this can be optimized.

Fam

#21 lore raw
Quoted 11 lines · Fam Zheng
Quoted 10 lines · Paolo Bonzini
Quoted 6 lines · Peter Lieven
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

Quoted 6 lines
Quoted 2 lines

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

I think from qemu-img convert's perspective, it doesn't care about the *file status if the metadata already speaks, because, like you said, the data shows up as zeroes.

That's already the case: *file is only examined if the metadata says BDRV_BLOCK_DATA=1, BDRV_BLOCK_ZERO=0.

Paolo

#22 lore raw

Am 17.03.2017 um 15:51 schrieb Paolo Bonzini:

Quoted 11 lines · Fam Zheng
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Peter Lieven
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

like VMDK or QCOW2 shouldn't we trust the information from the l2 tables in the VMDK or QCOW2?

It provides additional information, for example it works better with prealloc=metadata.

Okay, understood. Can you imagine of a away to conditionally avoid this second callout? In my case we have an additional lseek for each cluster. For a 20GB file this are approx. 327k calls to lseek. And if the file has no preallocated metadata it will likely not improve anything. And even if the metadata is prealloced what is the allocation status of the clusters?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

If the metadata is preallocated, cluster will (or should) show up as zero, speeding up the copy.

I think from qemu-img convert's perspective, it doesn't care about the *file status if the metadata already speaks, because, like you said, the data shows up as zeroes.

That's already the case: *file is only examined if the metadata says BDRV_BLOCK_DATA=1, BDRV_BLOCK_ZERO=0.

Maybe Fam meant in qemu-img this info is not that necessary because it will skip zeroes inside a datablock anyway. I don't know why the lseek is soo slow, but the optimization could be to identify the case where this extra info of the *file containing zeroes is really useful and then only call out for it in those cases.

Peter

Quoted 2 lines

Paolo