tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Spinning down sata disk before poweroff



On Fri, 17 Jun 2016, Anindya Mukherjee wrote:

Hi,

I'm running NetBSD 7.0.1_PATCH (GENERIC) amd64 on a Dell laptop. Almost everything is working perfectly, except the fact that every time I shutdown using the -p switch, the hard drive makes a loud click sound as the system powers off. I checked the SMART status (atactl and smartctl) and after every poweroff the Power_Off-Retract-Count parameter increases by 1.

I did some searching on the web and came across PR #21531 where this issue was discussed from 2003-2008 and finally a patch was committed which resolved the issue by sending the STANDBY_IMMEDIATE command to the disk before powering off. Since then the code has been refactored, but it is present in src/sys/dev/ata/wd.c line 1970 (wd_shutdown) which calls line 1848 (wd_standby). This seemed strange since the disk was definitely not being spun down.

I attached a remote gdb instance and stepped through the code during shutdown, breaking on wd_flushcache() which is always called. The code path taken is wdclose()->wdlastclose() (lines 1029, 1014). I can see that the cache is flushed but then the device is deleted in line 1023. Subsequently, power is cut off during shutdown, causing an emergency retract. So, it seems at least for newer sata disks the spindown code is not being called. I'm fairly new to NetBSD code so there is a chance I read this wrong, so feel free to correct me.

Well, I'm definitely not an expert on the disk drivers, so your analysis is likely as good as any I could give!


Ideally I'd like the disk to spin down during poweroff (-p) and halt (-h), perhaps settable using a sysctl, but not during a reboot (-r). I am planning to patch wdlastclose() as an experiment to run the spindown code to see if it stops the click. Is this a known issue, worthy of a PR? I can file one. I can also volunteer a patch once I have tested it on my laptop. Comments welcome!

I think that this would be the best possible behavior. Please submit a PR to document this change-request.

Also, it's not clear at the moment if this is only for ATA disks, or if similar issues (with perhaps similar fixes) exist for other disks, ie scsi and usb/umass.



+------------------+--------------------------+------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:      |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+


Home | Main Index | Thread Index | Old Index