Serial ATA (SATA) shutdown info
Hi there,
I'm the author of Upstart (the init system used by Ubuntu, and other distributions) and was directed to the following page in order to update compatibility with newer kernels and libata:
http://linux-ata.org/shutdown.html
Unfortunately after reading this, things still aren't entirely clear to me. Right now, Upstart is using roughly the same halt/reboot code as sysvinit -- this has rather a lot of baggage, so I've been trying to slim it down recently, and thus reading the same code paths you seem to have been.
If you could help me through my confusion, that would be greatly appreciated.
"In ATA, this is achieved by issuing FLUSH CACHE followed by
STANDBYNOW and the IDE drivers (drivers/ide/*) have always issued the sequence prior to powering off."
This is the code path I've been looking through, and I concur with your assessment. IDE drives using the IDE subsystem are powered down (by generic_ide_suspend() called by ide_device_shutdown)
The sysvinit in Debian (and Upstart in Ubuntu) use the following procedure during shutdown:
* sync()
* Open /proc/ide, iterate all hd* devices found there
* Check /proc/ide/*/media is "disk"
* Open the device in /dev
* Issue WIN_STANDBYNOW1
* Issue WIN_STANDBYNOW2
No attempt is made to flush the disk cache, other than calling sync().
Firstly, since it appears that the kernel already takes care of flushing the cache and standbying the disk, it would appear that this code in our halt/reboot binary is entirely useless. In some cases this would mean that the drive was placed into standby, before the kernel flushes its caches, bringing the drive out of standby with the clicking sound. (For the *IDE* subsystem, not libata).
Can we simply drop this code entirely? (I've been of the opinion we can, but it's nice to get expert confirmation).
Secondly, we've never attempted any workarounds for libata. Our halt/reboot only iterates /proc/ide, which should be empty for libata-based systems - therefore we've never issued FLUSH CACHE or STANDBYNOW on libata drives from userspace.
In this case, how should we proceed?
* Check whether /sys/modules/libata/parameters/spindown_compat exists. If it does, write 0 to it.
Since we've never been broken, can we not arrange for this to be always zero? Perhaps just writing to it on boot?
For each libata harddisk
* Check whether /sys/class/scsi_disk/h:c:i:l/manage_start_stop exists. If it doesn't, synchronize cache and spin the disk down as before. If it does, do nothing and continue to the next disk. The file is also accessible
as /sys/block/sdX/device/scsi_disk:*/manage_start_stop.
What's the reason for needing to flush the cache and standby the disk by hand? What are the circumstances where the manage_start_stop will not exist?
Obviously I'd rather our halt/reboot binary was literally a thin wrapper around the reboot() system call, without special logic. Since we're going to have to code the above logic, I'd like to make sure it's going in the right place.
Also what's the canon way to synchronise the cache and spin the disk down? How do we iterate libata harddisks, and map to the correct name in /dev ?
Scott
Signature · 3 lines
Scott James Remnant Ubuntu Development Manager [email protected]
Hello, Scott.
Quoted 11 lines · Scott James Remnant
The sysvinit in Debian (and Upstart in Ubuntu) use the following procedure during shutdown:
*
sync()
* Open/proc/ide, iterate all hd* devices found there
* Check/proc/ide/*/mediais "disk"
* Open the device in /dev
* IssueWIN_STANDBYNOW1
* IssueWIN_STANDBYNOW2No attempt is made to flush the disk cache, other than calling
sync().
Yes, that's exactly why we couldn't implement the workaround entirely contained in the kernel. As the userland shutdown issues STANDBYNOW without preceding FLUSH CACHE, the kernel cannot skip the kernel side of things. It's forced to issue FLUSH CACHE and this can spin some disks back up.
Quoted 6 lines
Firstly, since it appears that the kernel already takes care of flushing the cache and standbying the disk, it would appear that this code in our halt/reboot binary is entirely useless. In some cases this would mean that the drive was placed into standby, before the kernel flushes its caches, bringing the drive out of standby with the clicking sound. (For the *IDE* subsystem, not libata).
Yes.
Quoted 2 lines
Can we simply drop this code entirely? (I've been of the opinion we can, but it's nice to get expert confirmation).
Yes, please.
Quoted 5 lines
Secondly, we've never attempted any workarounds for libata. Our halt/reboot only iterates
/proc/ide, which should be empty for libata-based systems - therefore we've never issued FLUSH CACHE or STANDBYNOW on libata drives from userspace.
Quoted 7 lines
In this case, how should we proceed?
* Check whether
/sys/modules/libata/parameters/spindown_compatexists. If it does, write 0 to it.Since we've never been broken, can we not arrange for this to be always zero? Perhaps just writing to it on boot?
Yes, you can clear that node anytime you want and if your shutdown utilities don't issues FLUSH and STANDBY for libata disks on shutdown, that's the only thing you'll need to do. This is still in discussion but you might not have to do even that. Please read the following thread.
http://article.gmane.org/gmane.linux.ide/18846
I'll update you when things are determined. It might be that you don't have to do anything. Sorry about the fuss.
Quoted 11 lines
For each libata harddisk
* Check whether /sys/class/scsi_disk/h:c:i:l/manage_start_stop exists. If it doesn't, synchronize cache and spin the disk down as before. If it does, do nothing and continue to the next disk. The file is also accessible
as /sys/block/sdX/device/scsi_disk:*/manage_start_stop.What's the reason for needing to flush the cache and standby the disk by hand? What are the circumstances where the
manage_start_stopwill not exist?
On all kernels upto 2.6.21, libata doesn't issue STANDBYNOW on shutdown, so some distros including Debian do it during userland shutdown. This isn't a complete solution but most disks don't spin up on the following kernel FLUSH, so it's better than not doing anything which results in emergency unload for all disks.
Quoted 8 lines
Obviously I'd rather our halt/reboot binary was literally a thin wrapper around the
reboot()system call, without special logic. Since we're going to have to code the above logic, I'd like to make sure it's going in the right place.Also what's the canon way to synchronise the cache and spin the disk down? How do we iterate libata harddisks, and map to the correct name in /dev ?
I think the best way is to update the kernel and not to do anything in userspace - as you said, thin wrapper around the reboot() syscall.
Signature · 1 line
tejun
Quoted 2 lines · Tejun Heo
Hello, Scott.
Hi, Thanks for your quick reply!
Quoted 19 lines
Quoted 5 lines
Secondly, we've never attempted any workarounds for libata. Our halt/reboot only iterates
/proc/ide, which should be empty for libata-based systems - therefore we've never issued FLUSH CACHE or STANDBYNOW on libata drives from userspace.Quoted 7 lines
In this case, how should we proceed?
* Check whether
/sys/modules/libata/parameters/spindown_compatexists. If it does, write 0 to it.Since we've never been broken, can we not arrange for this to be always zero? Perhaps just writing to it on boot?
Yes, you can clear that node anytime you want and if your shutdown utilities don't issues FLUSH and STANDBY for libata disks on shutdown, that's the only thing you'll need to do. This is still in discussion but you might not have to do even that. Please read the following thread.
Quoted 5 lines
http://article.gmane.org/gmane.linux.ide/18846
I'll update you when things are determined. It might be that you don't have to do anything. Sorry about the fuss.
That's no problem, it's good to finally get this stuff cleaned up a little. We have an inherent preference for the cleanest and simplest implementation, obviously :-) If that means no userspace code, and just call reboot(), WIN!
Quoted 12 lines
Quoted 11 lines
For each libata harddisk
* Check whether /sys/class/scsi_disk/h:c:i:l/manage_start_stop exists. If it doesn't, synchronize cache and spin the disk down as before. If it does, do nothing and continue to the next disk. The file is also accessible
as /sys/block/sdX/device/scsi_disk:*/manage_start_stop.What's the reason for needing to flush the cache and standby the disk by hand? What are the circumstances where the
manage_start_stopwill not exist?
Quoted 6 lines
On all kernels upto 2.6.21, libata doesn't issue STANDBYNOW on shutdown, so some distros including Debian do it during userland shutdown. This isn't a complete solution but most disks don't spin up on the following kernel FLUSH, so it's better than not doing anything which results in emergency unload for all disks.
Since we've been running with 2.6.x and libata for a while, without bothering to do this, is there any harm in continuing to not do this?
It's obviously not a regression for us, and we can answer "upgrade to 7.10" quite cheerfully if it turns out there are people with bugs (which they will have always had).
I'll keep an eye on the thread you linked to, if we don't even need to write any zeros, we're definitely happy people :-)
Scott
Signature · 3 lines
Scott James Remnant Ubuntu Development Manager [email protected]
Hello, Scott.
Quoted 2 lines · Scott James Remnant
Since we've been running with 2.6.x and libata for a while, without bothering to do this, is there any harm in continuing to not do this?
No, I don't think so.
Quoted 3 lines
It's obviously not a regression for us, and we can answer "upgrade to 7.10" quite cheerfully if it turns out there are people with bugs (which they will have always had).
If that works for you and your userbase, you don't need to do anything.
Quoted 3 lines
I'll keep an eye on the thread you linked to, if we don't even need to write any zeros, we're definitely happy people :-)
Me happy too. :-)
Signature · 1 line
tejun
Quoted 5 lines · Tejun Heo
Quoted 2 lines
I'll keep an eye on the thread you linked to, if we don't even need to write any zeros, we're definitely happy people :-)
Me happy too. :-)
Out of interest, do you know there is a hysterical need to sync() before one calls reboot()?
I would have thought the kernel takes care of making sure it's own data structures are flushed to disk anyway, but I can't see the reference in the kernel code for where it might do this.
Scott
Signature · 3 lines
Scott James Remnant Ubuntu Development Manager [email protected]
Quoted 4 lines · Scott James Remnant
Quoted 2 lines · Tejun Heo
Quoted 2 lines
I'll keep an eye on the thread you linked to, if we don't even need to write any zeros, we're definitely happy people :-)
Quoted 8 lines
Quoted 2 lines
Me happy too. :-)
Out of interest, do you know there is a hysterical need to
sync()before one callsreboot()?I would have thought the kernel takes care of making sure it's own data structures are flushed to disk anyway, but I can't see the reference in the kernel code for where it might do this.
I dunno. I seem to recall there was discussion about disk driver not flushing cache or something like that years ago but I could be imagining things. With recent kernels, there's no reason for userland to do that before shutting down. Kernel always flushes caches during shutdown, but we can also afford some paranoia there as that doesn't cause any harm.
Signature · 1 line
tejun