LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-04-2012, 06:07 AM   #1
sanrio alvares
LQ Newbie
 
Registered: Apr 2010
Location: Mumbai, India
Distribution: ubuntu, fedora, android
Posts: 12

Rep: Reputation: 0
Unhappy fsync, sync: does it really do what its supposed to?


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?
 
Old 09-04-2012, 09:51 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
It attempts to do so but there are caveats in the man and info pages. To read more documentation on your system you can run the commands:

man 8 sync

man 2 sync

info sync

man fsync

You will see the sync command (man section 8/info sync) just invokes the sync system call (man section 2).

One note seen for sync is:
Quote:
According to the standard specification (e.g., POSIX.1-2001), sync()
schedules the writes, but may return before the actual writing is done.
However, since version 1.3.20 Linux does actually wait. (This still
does not guarantee data integrity: modern disks have large caches.)
It depends much on where the write is going. As noted above disks themselves have cache. Additionally if you're using a SCSI/RAID disk controller it might have its own cache. If you're writing to an external disk array via fibre or iSCSI it is likely the disk array itself has caching of its own. The key point to remember is that when it says it flushes or writes it what it really means is it has told the memory of the server itself to immediately send it to the storage. How quickly it actually gets physically on the disk depends on the storage itself. In some cases it doesn't really matter (e.g. the external disk array - once the sync has sent the command to the HBA and the HBA has sent to the array then it doesn't matter if the host goes down as the actual write to disk is handled by the array).

Also this is why journaling filesystems such as ext3/vxfs were created. They create intent logs that are more frequently updated than actual writes to disk so in the event of a crash when you run fsck after a boot it will find uncommited extents and update the disk.

Although you CAN lose data in a system crash in practice it doesn't really happen very often. However, ideally you should have redundant power to allow for orderly shutdowns on loss of power because losing data writes especially in DBMS setups CAN cause corruption so you want to avoid it if at all possible.
 
1 members found this post helpful.
Old 09-05-2012, 01:10 AM   #3
sanrio alvares
LQ Newbie
 
Registered: Apr 2010
Location: Mumbai, India
Distribution: ubuntu, fedora, android
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the reply. That explains a lot to me.
One more thing id like to know, does the MMC/SD controller on a mobile chipset have the ability to cache data? I can see the SD host driver sending the data when there is a write to the SD card. Does this imply that the data is written to the SD card immediately or is there caching done by the SD controller before finally writing to the SD card?
The Chipset Specification does not say that the SD Controller has caching capability though.
 
Old 09-05-2012, 09:26 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Since SD is essentially memory itself I'd think there'd be little benefit to having a write cache to it but again your best bet is knowing exactly what it is and looking on line for details about what it has. Mobile chipsets are designed for very cramped conditions so I think it unlikely they'd waste space on write caches.

Just looking generically for MMC/SD cache in a web search I found a controller that has read cache built into it. However, this isn't for a mobile device.
http://www.hitechglobal.com/ipcores/sdio.htm
Notice that it does NOT say it has write cache so presumably it doesn't and a sync would therefore write directly to it.

Again you'd have to know specifically what it is (vendor/model) and look for the features of same in a web search.

Last edited by MensaWater; 09-05-2012 at 09:27 AM.
 
1 members found this post helpful.
  


Reply

Tags
devicedrivers, filesystem, kernel, mmc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
E667: Fsync failed scotty2024 Debian 3 06-25-2010 07:01 PM
E667 Fsync failed Entwicklung Linux - Newbie 2 06-21-2010 02:02 PM
LXer: ext4 vs fsync, my take LXer Syndicated Linux News 0 03-17-2009 01:50 AM
fflush and fsync? power123 Programming 6 11-02-2005 11:04 PM
fsync() is slow on some systems brian_p_sully Linux - General 0 05-06-2004 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration