[mythtv-users] Use of fsync

Rich Freeman r-mythtv at thefreemanclan.net
Tue Oct 22 15:18:14 UTC 2013


Does anybody know why MythTV uses fsync to force writes to disk when
recording (in ThreadedFileWriter)?

I just noticed that some of my recent recordings were getting
truncated (a recent behavior change - though I can see why it might
not be a bad strategy).  The use of fsync on a fairly busy drive
basically kills drive throughput and as a result the buffers overflow.

I used to have this problem years ago and disabling the fsyncs fixed
it, so I've done the same again (as well as increasing buffer size).

What I don't understand is why MythTV calls fsync in the first place.
Syncing files should really only be used in transactional systems
especially when coordination across multiple processes or systems is
necessary.  For normal writes the software should just write the data
and let the kernel manage the buffers/cache.  Doing so GREATLY
improves disk performance, especially on systems with plenty of RAM.

Sure, if there is a power failure instead of losing 15 minutes of my
program I might lose 15.5 minutes, but that seems less of an issue
than losing half of an HD program from time to time when I have three
programs recording in HD and the system is under load.

There seem to be a lot of myths perpetuated about the need to fsync
(the highest profile case seems to be by the ext4 maintainers - who
Linus disagreed with to the point where he modified their code against
their objections).  There is a risk of losing data in the cache if you
don't sync, but this is usually preferable to the huge performance
penalties of not having a write cache, which is basically what you get
when every application author does an fsync after every write.

Rich


More information about the mythtv-users mailing list