In Linux, when you write a file to a disk, it actually stay at cache buffer for a while (5 seconds by default in /proc/sys/vm/dirty_writeback_centisecs). The sync just issues a command to flush the cache, but when to do it still depends on the O.S. In Redhat 2.6 Kernel, you can use /proc/sys/vm/drop_caches to force the cache wrote back to the disk, but it is a system-wide settings.
If an application, like database, want to know that the file is actually written to the storage, it can use fsync system call. This system call will block until the device reported the operation completed. Another option is to open file using O_DIRECT flag, so the file buffer cache will be bypassed.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment