요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
sysfs ABI
disk-shock-protection.rst:36-80timeout 범위, error code, 취소와 남은 시간 조회 방법을 정리합니다.
port 영향 범위
disk-shock-protection.rst:81-123PATA·SATA port 공유 장치와 구형 ATA drive 강제 enable의 영향을 설명합니다.
자료와 기여
disk-shock-protection.rst:124-151HDAPS project와 disk head parking 구현 기여자를 기록합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
==========================
Hard disk shock protection
==========================
Author: Elias Oltmanns <[email protected]>
Last modified: 2008-10-03
.. 0. Contents
1. Intro
2. The interface
3. References
4. CREDITS
1. Intro
--------
ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature.
Issuing this command should cause the drive to switch to idle mode and
unload disk heads. This feature is being used in modern laptops in
conjunction with accelerometers and appropriate software to implement
a shock protection facility. The idea is to stop all I/O operations on
the internal hard drive and park its heads on the ramp when critical
situations are anticipated. The desire to have such a feature
available on GNU/Linux systems has been the original motivation to
implement a generic disk head parking interface in the Linux kernel.
Please note, however, that other components have to be set up on your
system in order to get disk shock protection working (see
section 3. References below for pointers to more information about
that).
2. The interface
----------------
For each ATA device, the kernel exports the file
`block/*/device/unload_heads` in sysfs (here assumed to be mounted under
/sys). Access to `/sys/block/*/device/unload_heads` is denied with
-EOPNOTSUPP if the device does not support the unload feature.
Otherwise, writing an integer value to this file will take the heads
of the respective drive off the platter and block all I/O operations
for the specified number of milliseconds. When the timeout expires and
no further disk head park request has been issued in the meantime,
normal operation will be resumed. The maximal value accepted for a
timeout is 30000 milliseconds. Exceeding this limit will return
-EOVERFLOW, but heads will be parked anyway and the timeout will be
set to 30 seconds. However, you can always change a timeout to any
value between 0 and 30000 by issuing a subsequent head park request
before the timeout of the previous one has expired. In particular, the
total timeout can exceed 30 seconds and, more importantly, you can
cancel a previously set timeout and resume normal operation
immediately by specifying a timeout of 0. Values below -2 are rejected
with -EINVAL (see below for the special meaning of -1 and -2). If the
timeout specified for a recent head park request has not yet expired,
reading from `/sys/block/*/device/unload_heads` will report the number
of milliseconds remaining until normal operation will be resumed;
otherwise, reading the unload_heads attribute will return 0.
For example, do the following in order to park the heads of drive
/dev/sda and stop all I/O operations for five seconds::
# echo 5000 > /sys/block/sda/device/unload_heads
A simple::
# cat /sys/block/sda/device/unload_heads
will show you how many milliseconds are left before normal operation
will be resumed.
A word of caution: The fact that the interface operates on a basis of
milliseconds may raise expectations that cannot be satisfied in
reality. In fact, the ATA specs clearly state that the time for an
unload operation to complete is vendor specific. The hint in ATA-7
that this will typically be within 500 milliseconds apparently has
been dropped in ATA-8.
There is a technical detail of this implementation that may cause some
confusion and should be discussed here. When a head park request has
been issued to a device successfully, all I/O operations on the
controller port this device is attached to will be deferred. That is
to say, any other device that may be connected to the same port will
be affected too. The only exception is that a subsequent head unload
request to that other device will be executed immediately. Further
operations on that port will be deferred until the timeout specified
for either device on the port has expired. As far as PATA (old style
IDE) configurations are concerned, there can only be two devices
attached to any single port. In SATA world we have port multipliers
which means that a user-issued head parking request to one device may
actually result in stopping I/O to a whole bunch of devices. However,
since this feature is supposed to be used on laptops and does not seem
to be very useful in any other environment, there will be mostly one
device per port. Even if the CD/DVD writer happens to be connected to
the same port as the hard drive, it generally *should* recover just
fine from the occasional buffer under-run incurred by a head park
request to the HD. Actually, when you are using an ide driver rather
than its libata counterpart (i.e. your disk is called /dev/hda
instead of /dev/sda), then parking the heads of one drive (drive X)
will generally not affect the mode of operation of another drive
(drive Y) on the same port as described above. It is only when a port
reset is required to recover from an exception on drive Y that further
I/O operations on that drive (and the reset itself) will be delayed
until drive X is no longer in the parked state.
Finally, there are some hard drives that only comply with an earlier
version of the ATA standard than ATA-7, but do support the unload
feature nonetheless. Unfortunately, there is no safe way Linux can
detect these devices, so you won't be able to write to the
unload_heads attribute. If you know that your device really does
support the unload feature (for instance, because the vendor of your
laptop or the hard drive itself told you so), then you can tell the
kernel to enable the usage of this feature for that drive by writing
the special value -1 to the unload_heads attribute::
# echo -1 > /sys/block/sda/device/unload_heads
will enable the feature for /dev/sda, and giving -2 instead of -1 will
disable it again.
3. References
-------------
There are several laptops from different vendors featuring shock
protection capabilities. As manufacturers have refused to support open
source development of the required software components so far, Linux
support for shock protection varies considerably between different
hardware implementations. Ideally, this section should contain a list
of pointers at different projects aiming at an implementation of shock
protection on different systems. Unfortunately, I only know of a
single project which, although still considered experimental, is fit
for use. Please feel free to add projects that have been the victims
of my ignorance.
- https://www.thinkwiki.org/wiki/HDAPS
See this page for information about Linux support of the hard disk
active protection system as implemented in IBM/Lenovo Thinkpads.
4. CREDITS
----------
This implementation of disk head parking has been inspired by a patch
originally published by Jon Escombe <[email protected]>. My efforts
to develop an implementation of this feature that is fit to be merged
into mainline have been aided by various kernel developers, in
particular by Tejun Heo and Bartlomiej Zolnierkiewicz.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
하드 디스크 충격 보호 문서 정보
1-17작성자: Elias Oltmanns <[email protected]>
마지막 수정: 2008-10-03
목차: 1. 소개, 2. interface, 3. 참고 자료, 4. 기여자
충격 보호의 원리
18-35ATA/ATAPI-7은 unload 기능을 갖춘 `IDLE IMMEDIATE` command를 정의합니다. 이 command를 내리면 drive가 idle mode로 전환되고 disk head가 unload되어야 합니다.
현대 laptop에서는 이 기능을 accelerometer와 적절한 software에 결합하여 충격 보호 기능을 구현합니다. 위험 상황이 예상될 때 내부 hard drive의 모든 I/O operation을 멈추고 head를 ramp에 park하는 방식입니다.
GNU/Linux에서도 이 기능을 제공하려는 요구가 Linux kernel에 generic disk head parking interface를 구현한 최초 동기였습니다. 다만 disk shock protection을 실제로 동작시키려면 시스템에 다른 component도 설정해야 합니다. 자세한 정보는 아래의 3절 참고 자료를 보십시오.
unload_heads sysfs interface
36-60kernel은 각 ATA device에 대해 sysfs의 `block/*/device/unload_heads` 파일을 export합니다. 여기서는 sysfs가 `/sys` 아래에 mount되어 있다고 가정합니다.
device가 unload 기능을 지원하지 않으면 `/sys/block/*/device/unload_heads` 접근은 `-EOPNOTSUPP`로 거부됩니다. 지원한다면 이 파일에 정수 값을 쓰는 순간 해당 drive head가 platter에서 벗어나고, 지정한 millisecond 동안 모든 I/O operation이 block됩니다.
timeout이 만료될 때까지 추가 disk head park 요청이 없으면 정상 동작을 재개합니다. 허용하는 최대 timeout은 30000ms입니다. 이 제한을 넘으면 `-EOVERFLOW`를 반환하지만 head는 park되고 timeout은 30초로 설정됩니다.
이전 요청의 timeout이 만료되기 전에 후속 head park 요청을 보내면 timeout을 0부터 30000 사이의 어떤 값으로든 바꿀 수 있습니다. 따라서 전체 timeout은 30초를 넘을 수 있으며, 특히 timeout 0을 지정하면 기존 timeout을 취소하고 정상 동작을 즉시 재개할 수 있습니다.
-2보다 작은 값은 `-EINVAL`로 거부됩니다. `-1`과 `-2`의 특수 의미는 아래에서 설명합니다. 최근 head park 요청의 timeout이 아직 만료되지 않았다면 `/sys/block/*/device/unload_heads`를 읽을 때 정상 동작 재개까지 남은 millisecond 수를 반환하고, 그렇지 않으면 0을 반환합니다.
park 요청 예제와 시간 정밀도
61-80`/dev/sda`의 head를 park하고 모든 I/O operation을 5초 동안 멈추려면 다음을 실행합니다.
# echo 5000 > /sys/block/sda/device/unload_heads
남은 millisecond를 확인하려면 다음을 실행합니다.
# cat /sys/block/sda/device/unload_heads
주의: interface가 millisecond 단위로 동작한다는 사실이 현실적으로 충족할 수 없는 기대를 만들 수 있습니다. ATA specification은 unload operation 완료 시간이 vendor마다 다르다고 명시합니다. 보통 500ms 이내일 것이라는 ATA-7의 언급은 ATA-8에서 삭제된 것으로 보입니다.
controller port 단위의 I/O 지연
81-106구현 세부 사항 때문에 혼동할 수 있습니다. device에 head park 요청을 성공적으로 보내면 그 device가 연결된 controller port의 모든 I/O operation이 연기됩니다. 즉, 같은 port에 연결된 다른 device도 영향을 받습니다.
유일한 예외는 그 다른 device에 보내는 후속 head unload 요청으로, 이는 즉시 실행됩니다. 그 뒤 해당 port의 operation은 port에 연결된 어느 device든 지정된 timeout이 만료될 때까지 연기됩니다.
PATA(구형 IDE) 구성에서는 port 하나에 device를 최대 두 개만 연결할 수 있습니다. SATA에는 port multiplier가 있으므로 사용자가 device 하나에 head parking을 요청해도 실제로는 많은 device의 I/O가 멈출 수 있습니다.
그러나 이 기능은 laptop용이며 다른 환경에서는 그다지 유용하지 않으므로 대개 port마다 device가 하나뿐입니다. CD/DVD writer가 hard drive와 같은 port에 연결되어 있더라도 HD head park 요청으로 가끔 발생하는 buffer under-run에서 일반적으로 문제없이 복구해야 합니다.
libata 대신 `ide` driver를 사용하여 disk 이름이 `/dev/sda`가 아니라 `/dev/hda`라면, 한 drive(drive X)의 head를 park해도 보통 앞서 설명한 것처럼 같은 port의 다른 drive(drive Y) 동작 mode에는 영향을 주지 않습니다. drive Y의 exception에서 복구하기 위해 port reset이 필요할 때만 drive X가 parked 상태를 벗어날 때까지 drive Y의 추가 I/O와 reset 자체가 지연됩니다.
구형 ATA drive의 강제 enable
107-123일부 hard drive는 ATA-7보다 이전 ATA 표준만 준수하지만 unload 기능을 지원합니다. Linux가 이런 device를 안전하게 감지할 방법이 없으므로 기본적으로 `unload_heads` attribute에 쓸 수 없습니다.
laptop 또는 hard drive vendor의 확인 등으로 device가 unload 기능을 실제 지원한다는 사실을 안다면 `unload_heads` attribute에 특수값 `-1`을 써서 kernel이 해당 drive에서 이 기능을 사용하게 할 수 있습니다.
# echo -1 > /sys/block/sda/device/unload_heads
이 명령은 `/dev/sda`에서 기능을 enable합니다. `-1` 대신 `-2`를 쓰면 다시 disable합니다.
참고 자료와 기여자
124-151참고 자료
여러 vendor의 laptop이 충격 보호 기능을 제공합니다. 제조사가 필요한 software component의 open source 개발을 지원하지 않았기 때문에 Linux 충격 보호 지원 수준은 hardware 구현마다 크게 다릅니다.
이 절에는 이상적으로 여러 시스템의 충격 보호 구현 project를 가리키는 목록이 있어야 합니다. 원문 작성자가 알고 있는 것은 아직 experimental로 간주되지만 실제 사용할 수 있는 project 하나뿐입니다. 빠진 project가 있다면 추가해도 좋습니다.
이 페이지는 IBM/Lenovo ThinkPad에 구현된 hard disk active protection system의 Linux 지원 정보를 제공합니다.
기여자
disk head parking 구현은 Jon Escombe <[email protected]>가 처음 공개한 patch에서 영감을 받았습니다. mainline merge에 적합한 구현을 개발하는 작업에는 여러 kernel developer, 특히 Tejun Heo와 Bartlomiej Zolnierkiewicz가 도움을 주었습니다.
충격 보호 원리
disk-shock-protection.rst:1-35accelerometer 감지와 ATA head unload를 결합하는 목적을 설명합니다.