Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create image by truncate or fallocate, instead of dd #3589

Open
qiankehan opened this issue Dec 14, 2022 · 0 comments
Open

Create image by truncate or fallocate, instead of dd #3589

qiankehan opened this issue Dec 14, 2022 · 0 comments

Comments

@qiankehan
Copy link
Contributor

For avocado-vt and it providers(tp-libvirt, tp-qemu), most of us create image by dd. It creates a image file and formating it with 0. However, most of time we don't need to format the file, then we can replace dd with fallocate to save time. Sometimes, sparse image also works(e.g. targetcli backstore file), we can use truncate to save the fs free space.
Here is the comparision of time and space spent for truncate, allocate and dd:

➜  ~ time dd if=/dev/zero of=file-dd bs=1G count=20 
20+0 records in
20+0 records out
21474836480 bytes (21 GB, 20 GiB) copied, 25.9644 s, 827 MB/s
dd if=/dev/zero of=file-dd bs=1G count=20  0.00s user 16.59s system 63% cpu 25.971 total

➜  ~ time fallocate -l 20G file-falloc
fallocate -l 20G file-falloc  0.00s user 0.00s system 45% cpu 0.007 total

➜  ~ time truncate -s 20G file-truncate
truncate -s 20G file-truncate  0.00s user 0.00s system 54% cpu 0.004 total

➜  ~ ls -sh file-*                     
21G file-dd  21G file-falloc    0 file-truncate

Luckily, qemu-img has implemented this 3 modes into the option preallocation(not so sure if preallocation=full equals to zeroing, to be confirmed at this mail):

qemu-img create -o preallocation=off FILENAME SIZE   ### sparse
qemu-img create -o preallocation=falloc FILENAME SIZE   ### allocate
qemu-img create -o preallocation=full FILENAME SIZE   ### zeroing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant