Pregrowing a file

This example illustrates the effect of pregrowing a data file on an x86 PIII-725 machine with a UDMA-4 EIDE disk, using the QNX 4 filesystem.

The table shows the times, in milliseconds, required to create and write a 256 MB file in 8 KB records:

Scenario: Creation Write Total
write() 0 15073 15073 (15 seconds)
ftruncate() 13908 8510 22418 (22 seconds)
devctl() 55 8479 8534 (8.5 seconds)

Note how extending the file incrementally as a result of each write() call is slower than growing it with a single ftruncate() call, as the filesystem can allocate larger/contiguous data extents, and needs to update the inode metadata attributes only once. Note also how the time to overwrite already allocated data blocks is much less than that for allocating the blocks dynamically (the sequential writes aren't interrupted by the periodic need to synchronously update the bitmap).

Although the total time to pregrow and overwrite is worse than growing, the pregrowth could be performed during an initialization phase where speed isn't critical, allowing for better write performance later.

The optimal case is to pregrow the file without zero-filling it (using a DCMD_FSYS_PREGROW_FILE devctl() command) and then overwrite with the real data contents.