1 ========================== 1 ========================== 2 Hard disk shock protection 2 Hard disk shock protection 3 ========================== 3 ========================== 4 4 5 Author: Elias Oltmanns <eo@nebensachen.de> 5 Author: Elias Oltmanns <eo@nebensachen.de> 6 6 7 Last modified: 2008-10-03 7 Last modified: 2008-10-03 8 8 9 9 10 .. 0. Contents 10 .. 0. Contents 11 11 12 1. Intro 12 1. Intro 13 2. The interface 13 2. The interface 14 3. References 14 3. References 15 4. CREDITS 15 4. CREDITS 16 16 17 17 18 1. Intro 18 1. Intro 19 -------- 19 -------- 20 20 21 ATA/ATAPI-7 specifies the IDLE IMMEDIATE comma 21 ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature. 22 Issuing this command should cause the drive to 22 Issuing this command should cause the drive to switch to idle mode and 23 unload disk heads. This feature is being used 23 unload disk heads. This feature is being used in modern laptops in 24 conjunction with accelerometers and appropriat 24 conjunction with accelerometers and appropriate software to implement 25 a shock protection facility. The idea is to st 25 a shock protection facility. The idea is to stop all I/O operations on 26 the internal hard drive and park its heads on 26 the internal hard drive and park its heads on the ramp when critical 27 situations are anticipated. The desire to have 27 situations are anticipated. The desire to have such a feature 28 available on GNU/Linux systems has been the or 28 available on GNU/Linux systems has been the original motivation to 29 implement a generic disk head parking interfac 29 implement a generic disk head parking interface in the Linux kernel. 30 Please note, however, that other components ha 30 Please note, however, that other components have to be set up on your 31 system in order to get disk shock protection w 31 system in order to get disk shock protection working (see 32 section 3. References below for pointers to mo 32 section 3. References below for pointers to more information about 33 that). 33 that). 34 34 35 35 36 2. The interface 36 2. The interface 37 ---------------- 37 ---------------- 38 38 39 For each ATA device, the kernel exports the fi 39 For each ATA device, the kernel exports the file 40 `block/*/device/unload_heads` in sysfs (here a 40 `block/*/device/unload_heads` in sysfs (here assumed to be mounted under 41 /sys). Access to `/sys/block/*/device/unload_h 41 /sys). Access to `/sys/block/*/device/unload_heads` is denied with 42 -EOPNOTSUPP if the device does not support the 42 -EOPNOTSUPP if the device does not support the unload feature. 43 Otherwise, writing an integer value to this fi 43 Otherwise, writing an integer value to this file will take the heads 44 of the respective drive off the platter and bl 44 of the respective drive off the platter and block all I/O operations 45 for the specified number of milliseconds. When 45 for the specified number of milliseconds. When the timeout expires and 46 no further disk head park request has been iss 46 no further disk head park request has been issued in the meantime, 47 normal operation will be resumed. The maximal 47 normal operation will be resumed. The maximal value accepted for a 48 timeout is 30000 milliseconds. Exceeding this 48 timeout is 30000 milliseconds. Exceeding this limit will return 49 -EOVERFLOW, but heads will be parked anyway an 49 -EOVERFLOW, but heads will be parked anyway and the timeout will be 50 set to 30 seconds. However, you can always cha 50 set to 30 seconds. However, you can always change a timeout to any 51 value between 0 and 30000 by issuing a subsequ 51 value between 0 and 30000 by issuing a subsequent head park request 52 before the timeout of the previous one has exp 52 before the timeout of the previous one has expired. In particular, the 53 total timeout can exceed 30 seconds and, more 53 total timeout can exceed 30 seconds and, more importantly, you can 54 cancel a previously set timeout and resume nor 54 cancel a previously set timeout and resume normal operation 55 immediately by specifying a timeout of 0. Valu 55 immediately by specifying a timeout of 0. Values below -2 are rejected 56 with -EINVAL (see below for the special meanin 56 with -EINVAL (see below for the special meaning of -1 and -2). If the 57 timeout specified for a recent head park reque 57 timeout specified for a recent head park request has not yet expired, 58 reading from `/sys/block/*/device/unload_heads 58 reading from `/sys/block/*/device/unload_heads` will report the number 59 of milliseconds remaining until normal operati 59 of milliseconds remaining until normal operation will be resumed; 60 otherwise, reading the unload_heads attribute 60 otherwise, reading the unload_heads attribute will return 0. 61 61 62 For example, do the following in order to park 62 For example, do the following in order to park the heads of drive 63 /dev/sda and stop all I/O operations for five 63 /dev/sda and stop all I/O operations for five seconds:: 64 64 65 # echo 5000 > /sys/block/sda/device/un 65 # echo 5000 > /sys/block/sda/device/unload_heads 66 66 67 A simple:: 67 A simple:: 68 68 69 # cat /sys/block/sda/device/unload_hea 69 # cat /sys/block/sda/device/unload_heads 70 70 71 will show you how many milliseconds are left b 71 will show you how many milliseconds are left before normal operation 72 will be resumed. 72 will be resumed. 73 73 74 A word of caution: The fact that the interface 74 A word of caution: The fact that the interface operates on a basis of 75 milliseconds may raise expectations that canno 75 milliseconds may raise expectations that cannot be satisfied in 76 reality. In fact, the ATA specs clearly state 76 reality. In fact, the ATA specs clearly state that the time for an 77 unload operation to complete is vendor specifi 77 unload operation to complete is vendor specific. The hint in ATA-7 78 that this will typically be within 500 millise 78 that this will typically be within 500 milliseconds apparently has 79 been dropped in ATA-8. 79 been dropped in ATA-8. 80 80 81 There is a technical detail of this implementa 81 There is a technical detail of this implementation that may cause some 82 confusion and should be discussed here. When a 82 confusion and should be discussed here. When a head park request has 83 been issued to a device successfully, all I/O 83 been issued to a device successfully, all I/O operations on the 84 controller port this device is attached to wil 84 controller port this device is attached to will be deferred. That is 85 to say, any other device that may be connected 85 to say, any other device that may be connected to the same port will 86 be affected too. The only exception is that a 86 be affected too. The only exception is that a subsequent head unload 87 request to that other device will be executed 87 request to that other device will be executed immediately. Further 88 operations on that port will be deferred until 88 operations on that port will be deferred until the timeout specified 89 for either device on the port has expired. As 89 for either device on the port has expired. As far as PATA (old style 90 IDE) configurations are concerned, there can o 90 IDE) configurations are concerned, there can only be two devices 91 attached to any single port. In SATA world we 91 attached to any single port. In SATA world we have port multipliers 92 which means that a user-issued head parking re 92 which means that a user-issued head parking request to one device may 93 actually result in stopping I/O to a whole bun 93 actually result in stopping I/O to a whole bunch of devices. However, 94 since this feature is supposed to be used on l 94 since this feature is supposed to be used on laptops and does not seem 95 to be very useful in any other environment, th 95 to be very useful in any other environment, there will be mostly one 96 device per port. Even if the CD/DVD writer hap 96 device per port. Even if the CD/DVD writer happens to be connected to 97 the same port as the hard drive, it generally 97 the same port as the hard drive, it generally *should* recover just 98 fine from the occasional buffer under-run incu 98 fine from the occasional buffer under-run incurred by a head park 99 request to the HD. Actually, when you are usin 99 request to the HD. Actually, when you are using an ide driver rather 100 than its libata counterpart (i.e. your disk is 100 than its libata counterpart (i.e. your disk is called /dev/hda 101 instead of /dev/sda), then parking the heads o 101 instead of /dev/sda), then parking the heads of one drive (drive X) 102 will generally not affect the mode of operatio 102 will generally not affect the mode of operation of another drive 103 (drive Y) on the same port as described above. 103 (drive Y) on the same port as described above. It is only when a port 104 reset is required to recover from an exception 104 reset is required to recover from an exception on drive Y that further 105 I/O operations on that drive (and the reset it 105 I/O operations on that drive (and the reset itself) will be delayed 106 until drive X is no longer in the parked state 106 until drive X is no longer in the parked state. 107 107 108 Finally, there are some hard drives that only 108 Finally, there are some hard drives that only comply with an earlier 109 version of the ATA standard than ATA-7, but do 109 version of the ATA standard than ATA-7, but do support the unload 110 feature nonetheless. Unfortunately, there is n 110 feature nonetheless. Unfortunately, there is no safe way Linux can 111 detect these devices, so you won't be able to 111 detect these devices, so you won't be able to write to the 112 unload_heads attribute. If you know that your 112 unload_heads attribute. If you know that your device really does 113 support the unload feature (for instance, beca 113 support the unload feature (for instance, because the vendor of your 114 laptop or the hard drive itself told you so), 114 laptop or the hard drive itself told you so), then you can tell the 115 kernel to enable the usage of this feature for 115 kernel to enable the usage of this feature for that drive by writing 116 the special value -1 to the unload_heads attri 116 the special value -1 to the unload_heads attribute:: 117 117 118 # echo -1 > /sys/block/sda/device/unlo 118 # echo -1 > /sys/block/sda/device/unload_heads 119 119 120 will enable the feature for /dev/sda, and givi 120 will enable the feature for /dev/sda, and giving -2 instead of -1 will 121 disable it again. 121 disable it again. 122 122 123 123 124 3. References 124 3. References 125 ------------- 125 ------------- 126 126 127 There are several laptops from different vendo 127 There are several laptops from different vendors featuring shock 128 protection capabilities. As manufacturers have 128 protection capabilities. As manufacturers have refused to support open 129 source development of the required software co 129 source development of the required software components so far, Linux 130 support for shock protection varies considerab 130 support for shock protection varies considerably between different 131 hardware implementations. Ideally, this sectio 131 hardware implementations. Ideally, this section should contain a list 132 of pointers at different projects aiming at an 132 of pointers at different projects aiming at an implementation of shock 133 protection on different systems. Unfortunately 133 protection on different systems. Unfortunately, I only know of a 134 single project which, although still considere 134 single project which, although still considered experimental, is fit 135 for use. Please feel free to add projects that 135 for use. Please feel free to add projects that have been the victims 136 of my ignorance. 136 of my ignorance. 137 137 138 - https://www.thinkwiki.org/wiki/HDAPS !! 138 - http://www.thinkwiki.org/wiki/HDAPS 139 139 140 See this page for information about Linux su 140 See this page for information about Linux support of the hard disk 141 active protection system as implemented in I 141 active protection system as implemented in IBM/Lenovo Thinkpads. 142 142 143 143 144 4. CREDITS 144 4. CREDITS 145 ---------- 145 ---------- 146 146 147 This implementation of disk head parking has b 147 This implementation of disk head parking has been inspired by a patch 148 originally published by Jon Escombe <lists@dres 148 originally published by Jon Escombe <lists@dresco.co.uk>. My efforts 149 to develop an implementation of this feature t 149 to develop an implementation of this feature that is fit to be merged 150 into mainline have been aided by various kerne 150 into mainline have been aided by various kernel developers, in 151 particular by Tejun Heo and Bartlomiej Zolnier 151 particular by Tejun Heo and Bartlomiej Zolnierkiewicz.
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.