Sample Header Ad - 728x90

To sync or not to sync in an embedded environment?

4 votes
1 answer
2373 views
I have a single board appliance that runs Debian 10 on a chunk of flash. UBIFS is used, and is split into two volumes: an ro roots, and an rw /var. I have found that under power cycling/reset conditions, that I can end up with 0 byte files. I keep my "settings" in /var/opt/myApp. Changing the mount option of /var to include sync seems to make those incidents go away. I know the usual advice is that async is preferred over sync, but it is usually caveated with "usually, but not always" with little explanation what the exceptions might be. The alternate solution, would be to modify any and all call sites where I write data to disk, to not only flush on file close, but sync as well (I do a lot of it with python). From a coding/completeness sake, mounting as sync seemed both less work, and avoided me missing adding the sync guards at places, iow it's universal. Additionally, I allow the appliance to save data to usb thumb drives. I think I should mount those sync too, to reduce loss when they are yanked out right after data is written to them. Is this a suitably exceptional configuration to justify using sync? Or should I use the alternate solution?
Asked by Travis Griggs (1681 rep)
Aug 28, 2019, 10:03 PM
Last activity: Oct 18, 2019, 02:39 PM