Trading off safety and performance in the kernel
Trading off safety and performance in the kernel
Posted May 16, 2015 15:52 UTC (Sat) by ghane (guest, #1805)In reply to: Trading off safety and performance in the kernel by neilbrown
Parent article: Trading off safety and performance in the kernel
> But the point isn't really how long it takes. The point is that the 'sync' call really doesn't belong there. The benefit it provides is much more superstitious than scientific.
Back on the late 80s, I was taught to type:
sync ; sync ; sync
before a shutdown or reboot. I assume this was so that the SVR5 kernel would know I really wanted to sync.
Posted May 16, 2015 20:14 UTC (Sat)
by dlang (guest, #313)
[Link] (2 responses)
that still doesn't justify three invocations, but would justify two.
Posted May 16, 2015 20:42 UTC (Sat)
by neilbrown (subscriber, #359)
[Link] (1 responses)
http://pubs.opengroup.org/onlinepubs/7908799/xsh/sync.html
This is part of why calling sys_sync() once in the suspend path is wrong (twice has been suggested), though I'm not certain if the Linux implementation exactly matches the specification.
Posted May 17, 2015 4:21 UTC (Sun)
by neilbrown (subscriber, #359)
[Link]
Actually, I'll have to backtrack on this.
I can find no evidence in historical Unix, all the way up to 4.3BSD, to suggest that the 'sync' system call would wait. It just initiated IO. So maybe calling it 3 times makes sense.
Linux (roughly) followed that approach until Linux 1.3.20. That version introduced the change:
Exactly what is waited for when is hard to track. I'd need to read a lot more code to see what things sys_sync waits for today. But it does wait for something, but before 1.3.20, and all through "Unix", it certainly didn't wait for everything.
Trading off safety and performance in the kernel
Trading off safety and performance in the kernel
> Yes, the "sync" semantics are "wait for any pending writeout to complete, then start writeout on any dirty data",
Trading off safety and performance in the kernel
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -228,7 +228,7 @@ int fsync_dev(dev_t dev)
asmlinkage int sys_sync(void)
{
- sync_dev(0);
+ fsync_dev(0);
return 0;
}
To give the fuller context:
void sync_dev(dev_t dev)
{
sync_buffers(dev, 0);
sync_supers(dev);
sync_inodes(dev);
sync_buffers(dev, 0);
}
int fsync_dev(dev_t dev)
{
sync_buffers(dev, 0);
sync_supers(dev);
sync_inodes(dev);
return sync_buffers(dev, 1);
}
asmlinkage int sys_sync(void)
{
fsync_dev(0);
return 0;
}
The second arg to sync_buffers() says whether it should 'wait'. So fsync_dev() waits, sync_dev() doesn't.