[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    fsync() madness
From:       Sami Liedes <sliedes () cc ! hut ! fi>
Date:       2008-04-19 14:44:48
Message-ID: 20080419144448.GF6012 () nun4 ! kyla ! fi
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Hi,

I did some investigation with latencytop and noticed that a lot of KDE
applications fsync() continuously. Is there *any* good reason to do
so? As far as I understand, doing this just defeats the write back
cache, and if I wanted to do that, I'd mount my file systems noasync.

Normal applications should pretty much never fsync(). It's not a
matter of "this data is important", which seems to be the rationale
for KDE fsync()ing. I trust cp to copy my configuration files, and it
doesn't fsync(). The passwd command doesn't fsync() either, and if it
did, I'd file a bug against it. I measured latencies of >9 seconds on
a moderately disk-loaded system with loads of memory which would
handle this kind of load easily were it not for KDE unnecessarily
fsync()ing.

For example, take a look at K3TempFile. It says:

 * The K3TempFile class creates and opens a unique file for temporary use.
 *
 * This is especially useful if you need to create a file in a world
 * writable directory like /tmp without being vulnerable to so called
 * symlink attacks.

The class supports sync()ing. Can anyone invent a single reason why a
_temporary_ file should ever be fsync()ed? After all nobody depends on
it after a system crash, which is the only case where fsync() is
useful.

In K3TempFile, the sync() method both fflush()es and fsync()s, the
former of which makes sense, and the latter of which I think is just
braindead.

fsync() is explicitly allowed to be a null operation, so by definition
nothing should break if all the calls to fsync() are removed. I guess
I'm going to try to disable fsync() for KDE (3.5.9) since I trust my
kernel to write the stuff to disk eventually, it should break nothing
and help a lot, and since I haven't yet figured out any reason for a
single KDE application to fsync() (though some very isolated cases
might exist, e.g. postgresql and syslogd do fsync() for a good reason,
although for the latter it can still be disabled and usually is
disabled for non-critical log files).

Another code with I believe high impact that fsync()s with absolutely
no reason, and *by default*, is KConfig. I couldn't figure out with a
brief look if this is still the case in KDE 4, but at least in KDE
3.5.9 it does.

On Linux, I believe fsync() on NFS is a null op. On some other systems
it is not. This also makes some things unexpectedly slow on those
other systems, again for no good reason.

Makes me wonder if the people who wrote this code actually understood
the difference between fflush() and fsync().

Related bugs:

http://bugs.kde.org/show_bug.cgi?id=110318
http://bugs.kde.org/show_bug.cgi?id=142462
http://bugs.kde.org/show_bug.cgi?id=90042
http://bugs.kde.org/show_bug.cgi?id=146789

	Sami

["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic