Fast creation of large files under Linux fallocate

Source: Internet
Author: User

Previously created files I usually use DD to create, for example, create a 512M file:

The DD command can be easily implemented to create a file of the specified size, such as

DD If=/dev/zero of=test bs=1m count=1000

Generates a 1000M test file with a file content of 0 (read from/dev/zero,/dev/zero as 0 source)

However, to actually write to the hard disk, the file production speed depends on the hard disk read and write speed, if you want to produce large files, slow

In some scenario, we just want the file system to think that there is a huge file here, but it's not actually written to the hard disk

Then you can

DD If=/dev/zero of=test bs=1m count=0 seek=100000

The file created at this time has a 100000MB display size in the file system, but does not actually occupy block, so the creation speed is comparable to the memory speed

Seek is the function of skipping over the specified size in the output file, which achieves the purpose of creating large files, but not actually writing

Of course, because it is not actually written to the hard disk, the (www.111cn.net) can be used to create 100G on your hard drive with a capacity of only 10G.


Remember when you used to do Windows development, there is an API called SetEndOfFile, can be used to set the file inside the cursor location to the end of the file, can be used to intercept or extend the file, which is essentially equivalent to directly manipulate the structure of the file partition table, It is not necessary to use it for file extensions, and there must be a corresponding thing in Linux, namely, ftrunc/truncate these two functions.

So the tool that uses this feature directly to create large files must have been done, and the search found two commands for fallocate and truncate, and the seek extension of the GNU DD:

Code to copy code as follows
# fallocate-l 10G Bigfile
# truncate-s 10G Bigfile
# dd Of=bigfile Bs=1 seek=10g count=0

File system for such created files have special processing, called sparse files, now create large files speed of light, no longer have to tangle for half a day.
From:http://www.111cn.net/sys/linux/55537.htm

Fast creation of large files under Linux fallocate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.