Filesystems and block I/O (devb-*) drivers
Here are the basic steps to improving the performance of your filesystems and block I/O (devb-*) drivers.
- Optimize the filesystem options:
- Determine how you want to balance system robustness and performance (see below).
- Concentrate on the cache and vnode (filesystem-independent inodes) options; the other sizes scale themselves to these.
- Set the commit option (either globally or as a mount option) to force or disable synchronous writes.
- Consider using a RAM disk for temporary files (e.g., /tmp).
- Optimize application code:
- Read and write in large chunks (16–32 KB is optimal).
- Read and write in multiples of a disk block on block boundaries (typically 512 bytes, but you can use stat() or statvfs() to determine the value at runtime).
- Avoid standard I/O where possible; use open(), read(), and write(), instead of fopen(), fread(), and fwrite(). The f* functions use an extra layer of buffering. The default size is given by BUFSIZ; you can use setvbuf() to specify a different buffer size.
- Pregrow files, if you know their ultimate sizes.
- Use direct I/O (DMA to user space).
- Use filenames that are no longer than 16 characters.
If you do this, the filesystem won't use the .inodes
file, so there won't be any inter-block references.
In addition, there will be one less disk write, and hence, one less
chance of corruption if the power fails.
Long filenames (i.e., longer than 48 characters) especially slow down the filesystem.
- Big directories are slower that small ones, because the filesystem uses a linear search.