Warning: The direct value for I/O flag of the dd command may cause problems in Red Hat Linux 5. Only use it in Red Hat Linux 6. Direct I/O without a DIO filesystem If you ever paid attention to system memory when you ran cp or gzip or cross-filesystem mv on a very big file on Linux, you would notice free memory gradually drops to about 20 MB and the kswapd kernel daemon kicks in to flush memory, and the cycle repeats, until the command completes. One solution would be to install a filesystem that supports direct I/O mount option. But Linux ext[234] filesystems do not support Direct I/O (DIO) mount option.[note] If you don't change the filesystem, you can still get the benefit of DIO by passing O_DIRECT to the open() call in your program. But if you don't want to rewrite the standard programs such as cp or gzip to add the open() flag, there's still one way to do it, making use of the powerful dd program: #cp dd if=the_big_file bs=1048576 of=the_big_file.bak iflag=direct oflag=direct #gzip dd if=the_big_file bs=1048576 iflag=direct | gzip -c | dd bs=1048576 of=the_big_file.gz oflag=direct (A cross-filesystem mv can simply be cp followed by rm. The bs number for dd can be larger if you want). Note the two flags for input and output, which tell dd to open the input and output files in direct I/O mode. Opening a file in DIO mode is supported by Linux since a long time ago, irrelevant to the filesystem's support. To test, run the above commands and watch free memory with `free' or `top'. You'll see the free memory no longer drops and goes up upon swapping and again and again. ______________ [note] Partly due to Linus's opinion. Cf. the first paragraph of BUG of manpage of open().