Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fsync, sync: does it really do what its supposed to? [closed]

I would like to have more clarification on the functionality of sync(8) and fsync functions in Linux (2.6.31). Does it make sure the files are written to the respective storage?

like image 463
spitfire88 Avatar asked Sep 04 '12 11:09

spitfire88


People also ask

Does Close imply fsync?

No. A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. It is not common for a file system to flush the buffers when the stream is closed. If you need to be sure that the data is physically stored use fsync(2).

What does fsync do?

The fsync() function transfers all data for the file indicated by the open file descriptor file_descriptor to the storage device associated with file_descriptor. fsync() does not return until the transfer is complete, or until an error is detected.

Is fsync necessary?

The fsync call is very expensive, but it is essential to databases as it allows for durability (the “D” of the ACID acronym).

What is fsync system call?

DESCRIPTION. fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor fd to the disk device (or other permanent storage device) where that file resides. The call blocks until the device reports that the transfer has completed.


1 Answers

http://linux.die.net/man/8/sync

It does not make sure that files are written to respective storage. It only makes sure that cached/buffered data is flushed to the disk device. It doesn't matter if this is an SD Card or whatever.

like image 140
Oliver Avatar answered Sep 20 '22 19:09

Oliver