[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: How to generate a large file allocating space



On Sun, Oct 31, 2010 at 11:12:41AM +0100, Alex Bligh wrote:
> I want to generate or extend a large file in an ext4 filesystem allocating
> space (i.e. not creating a sparse file) but not actually writing any data.

Well, some metadata will have to be written, but not data.
shouldn't posix_fallocate(3) and/or fallocate(2) do that? 

I haven't got EXT4 around ATM, but IIRC it should work on it too. 
On XFS it seems to work too:

# time fallocate -l 3000000000 /stuff/tmp/bla
fallocate -l 3000000000 /stuff/tmp/bla  0,00s user 0,00s system 0% cpu 0,402 total
# du -h /stuff/tmp/bla
2,8G    /stuff/tmp/bla
# du -bh /stuff/tmp/bla
2,8G    /stuff/tmp/bla
# rm -f /stuff/tmp/bla

fallocate(1) is from util-linux on my Debian Squeeze

Oppose that to dramatically slower dd(1), which fills them with zeros explicitely:
# time dd if=/dev/zero of=/stuff/tmp/bla count=30000 bs=100000
time dd if=/dev/zero of=/stuff/tmp/bla count=30000 bs=100000
30000+0 records in
30000+0 records out
3000000000 bytes (3,0 GB) copied, 31,2581 s, 96,0 MB/s
dd if=/dev/zero of=/stuff/tmp/bla count=30000 bs=100000  0,00s user 3,41s system 10% cpu 31,341 total
# du -h /stuff/tmp/bla
2,8G    /stuff/tmp/bla


-- 
Opinions above are GNU-copylefted.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]