Sync (Unix)
sync is a standard system call in the Unix operating system, which commits all data from the kernel filesystem buffers to non-volatile storage, i.e., data which has been scheduled for writing via low-level I/O system calls. Higher-level I/O layers such as stdio may maintain separate buffers of their own. As a function in C, the sync() call is typically declared as void sync(void) in . The system call is also available via a command line utility also called sync, and similarly named functions in other languages such as Perl and Node.js (in the fs module). The related system call fsync() commits just the buffered data relating to a specified file descriptor. fdatasync() is also available to... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
sync is a standard system call in the Unix operating system, which commits all data from the kernel filesystem buffers to non-volatile storage, i.e., data which has been scheduled for writing via low-level I/O system calls. Higher-level I/O layers such as stdio may maintain separate buffers of their own. As a function in C, the sync() call is typically declared as void sync(void) in . The system call is also available via a command line utility also called sync, and similarly named functions in other languages such as Perl and Node.js (in the fs module). The related system call fsync() commits just the buffered data relating to a specified file descriptor. fdatasync() is also available to write out just the changes made to the data in the file, and not necessarily the file's related metadata. Some Unix systems run a kind of flush or update daemon, which calls the sync function on a regular basis. On some systems, the cron daemon does this, and on Linux it was handled by the pdflush daemon which was replaced by a new implementation and finally removed from the Linux kernel in 2012. Buffers are also flushed when filesystems are unmounted or remounted read-only, for example prior to system shutdown. Some applications, such as LibreOffice, also call the sync function to save recovery information in an interval. ==Database use== In order to provide proper durability, databases need to use some form of sync in order to make sure the information written has made it to non-volatile storage rather than just being stored in a memory-based write cache that would be lost if power failed. PostgreSQL for example may use a variety of different sync calls, including fsync() and fdatasync() , in order for commits to be durable. Unfortunately, for any single client writing a series of records, a rotating hard drive can only commit once per rotation, which makes for at best a few hundred such commits per second. Turning off the fsync requirement can therefore greatly improve commit performance, but at the expense of potentially introducing database corruption after a crash. Databases also employ transaction log files (typically much smaller than the main data files) that have information about recent changes, such that changes can be reliably redone in case of crash; then the main data files can be synced less often. ==Performance controversies== More specifically, the user interface thread calls SQLite for every new page visited and the library calls fsync . On ext3's data=ordered mode, which is a fairly common setup of the time, calling fsync means that the entire filesytem's write cache is flushed, which can take a long time if the cache contains a lot of other pending operations (e.g. in the middle of copying a large file). This event inspired a lot of finger-pointing against the use of fsync , claiming performance problems, unnecessary HDD spinups, and/or needing only atomicity and not durability. Linux Foundation chief technical officer Theodore Ts'o provided an analysis of the problem: He responds that there is no need to "fear fsync " when used properly, and emphasizes that fsync is the only POSIX way to request that a data is written to non-volatile storage. He retorts to the three criticisms of fsync stating that (1) the performance impact should be minimal in a typical use case (downloading a file while browsing the web), that fsync does not create extra I/O (it only waits for it), and that Firefox was wrong to make so much disk writes when browsing a webpage anyways; (2) that spinup could be avoided by a tweak of the existing laptop_mode ; and (3) that "atomicity not durability" is a bad security comprise compared to spawning of an I/O thread to run fsync . Stewart Smith happened to have made a presentation on the use, misuse, and underuse of fsync in applications just the year before (2007). Although his talk was mostly about practices detrimental to data integrity (and ways to take care of both speed and safety), the "eatmydata" tool for disabling all sync-type calls for a program ended up seeing wider distribution. It is mainly used in "throwaway" tasks where data loss is acceptable, for example in a temporary environment to speed up package installs. ==See also== Page cache inode ==References== ==External links== sync(8) - Linux man page http://austingroupbugs.net/view.php?id=672
References
- [http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html fsync specification] . · 1781046000.0
- Improved block-layer error handling [LWN.net] . · 1781046000.0
- Always report a writeback error once - Patchwork . · 1781046000.0
- [http://www.jasonbrome.com/blog/archives/2004/04/03/writecache_enabled.html Write-Cache Enabled?] . · 1781046000.0
- [http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/configtuning-disk.html#AEN16830 FreeBSD Handbook — Tuning Disks] . · 1781046000.0
- Marshall Kirk McKusick. Disks from the Perspective of a File System - ACM Queue . Que . · 1781046000.0
- Enabling FUA for SATA drives (Was Re: [RFC][PATCH] libata: Enable SATA disk fua detection on default) (Linu . · 1781046000.0
- Linux-Kernel Archive: [PATCH RFC] libata: FUA updates . · 1781046000.0
- Shaver » fsyncers and curveballs . · 1781046000.0
- Mike Shaver: On some rather common Linux configurations, especially using the ext3 filesystem in the "data=ordered" mode, calling fsync doesn't just flush out the data for the file it's called . · 1781046000.0
- Linux Foundation chief technical officer Theodore Ts'o provided an analysis of the problem: He responds that there is no need to "fear fsync " when used properly, and emphasizes that fsync . · 1781046000.0
- [http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html fdatasync specification] . · 1781046000.0
- Smith, Stewart. eat my data: how everybody gets file IO wrong . 2007. · 1781046000.0
- eatmydata (1) transparently disable fsync() and other data-to-disk synchronization calls . · 1781046000.0
- libeatmydata - disable fsync and SAVE! . www.flamingspork.com . · 1781046000.0
- Package: apt-eatmydata (1) - Disable fsync and friends for APT's dpkg calls . packages.debian.org . · 1781046000.0
- R.I.P. Pdflush [LWN.net] . · 1781046000.0
- mount - Does umount calls sync to complete any pending writes . · 1781046000.0
- PostgreSQL vs. fsync . · 1781046000.0
- [http://www.postgresql.org/docs/current/static/wal.html PostgreSQL Reliability and the Write-Ahead Log] . · 1781046000.0
- [http://www.westnet.com/~gsmith/content/postgresql/TuningPGWAL.htm Tuning PostgreSQL WAL Synchronization] Webarchive|url=https://web.archive.org/web/20091125043111/http://www.westnet.com/~gsmith/con . · 1781046000.0
- Ensuring data reaches disk [LWN.net] . · 1781046000.0
- PostgreSQL's fsync() surprise [LWN.net] . · 1781046000.0
Cite this
"Sync (Unix)". 1781076645. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1358692539 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy