Skip to contentSkip to conversation

qemu-img convert block alignment

Question Zhenyu Ye 2 participants 4 messages Apr 2, 2021 – Aug 4, 2021

lore
Share & tools
lore

Zhenyu Ye

author
#0 lore raw

Hi all,

commit 8dcd3c9b91 ("qemu-img: align result of is_allocated_sectors") introduces block alignment when doing qemu-img convert. However, the alignment is:

	s.alignment = MAX(pow2floor(s.min_sparse),
                      DIV_ROUND_UP(out_bs->bl.request_alignment,
                                   BDRV_SECTOR_SIZE));

(where the default s.min_sparse is 8)
When the target device's bl.request_alignment is smaller than 4K, this will cause additional write-zero overhead and makes the size of target file larger.

Is this as expected? Should we change the MAX() to MIN()?

Thanks,
zhenyu

author
#1 lore raw

ping?

Quoted 21 lines · Zhenyu Ye

Hi all,

commit 8dcd3c9b91 ("qemu-img: align result of is_allocated_sectors") introduces block alignment when doing qemu-img convert. However, the alignment is:

	s.alignment = MAX(pow2floor(s.min_sparse),
                      DIV_ROUND_UP(out_bs->bl.request_alignment,
                                   BDRV_SECTOR_SIZE));

(where the default s.min_sparse is 8)
When the target device's bl.request_alignment is smaller than 4K, this will cause additional write-zero overhead and makes the size of target file larger.

Is this as expected? Should we change the MAX() to MIN()?

Thanks,
zhenyu

#2 lore raw
In reply to Zhenyu Ye
Quoted 10 lines · Zhenyu Ye

Hi all,

commit 8dcd3c9b91 ("qemu-img: align result of is_allocated_sectors") introduces block alignment when doing qemu-img convert. However, the alignment is:

	s.alignment = MAX(pow2floor(s.min_sparse),
                      DIV_ROUND_UP(out_bs->bl.request_alignment,
                                   BDRV_SECTOR_SIZE));
Quoted 6 lines

(where the default s.min_sparse is 8)
When the target device's bl.request_alignment is smaller than 4K, this will cause additional write-zero overhead and makes the size of target file larger.

Is this as expected? Should we change the MAX() to MIN()?

Yes it is expected, and no we shouldn't change it. Even when a target advertises a bl.request_alignment of 512, our goal is to avoid needing read-modify-write cycles when that target is really on top of a 4k sector disk. Writing extra 0s out to the 4k boundaries does not change the fact that allocation is in 4k chunks anyways, regardless of whether the disk supports smaller 512-byte reads.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#3 lore raw
Quoted 16 lines · Eric Blake
Quoted 15 lines · Zhenyu Ye

Hi all,

commit 8dcd3c9b91 ("qemu-img: align result of is_allocated_sectors") introduces block alignment when doing qemu-img convert. However, the alignment is:

	s.alignment = MAX(pow2floor(s.min_sparse),
                      DIV_ROUND_UP(out_bs->bl.request_alignment,
                                   BDRV_SECTOR_SIZE));

(where the default s.min_sparse is 8)
When the target device's bl.request_alignment is smaller than 4K, this will cause additional write-zero overhead and makes the size of target file larger.

Quoted 9 lines
Quoted 1 line

Is this as expected? Should we change the MAX() to MIN()?

Yes it is expected, and no we shouldn't change it. Even when a target advertises a bl.request_alignment of 512, our goal is to avoid needing read-modify-write cycles when that target is really on top of a 4k sector disk. Writing extra 0s out to the 4k boundaries does not change the fact that allocation is in 4k chunks anyways, regardless of whether the disk supports smaller 512-byte reads.

Thanks for your reply.

Zhenyu