┌────────────────────────────────────────────────────────── RAW driver (/dev/raw/rawN)
│ CONFIG_RAW_DRIVER:
│ The raw driver permits block devices to be bound to /dev/raw/rawN.
│ Once bound, I/O against /dev/raw/rawN uses efficient zero-copy I/O.
│ See the raw(8) manpage for more details. │
│ Applications should preferably open the device (eg /dev/hda1)
│ with the O_DIRECT flag.
----------------------------------------------------------------
上面是在核心版本3.5.3中的RAW裝置相關的配置選項。
- 在一個塊裝置安裝到一個節點之前,對該裝置的訪問通常是作為一個線性無結構的位元組流來訪問的,
稱為“原始裝置(raw device)”。裝置上的檔案系統是不可訪問的。經過安裝以後,裝置上的檔案系統
就以訪問了。[1]
- Once bound to a block device, a raw device can be opened, read and
written, just like the block device it is bound to. However, the raw
device does not behave exactly like the block device. In particular,
access to the raw device bypasses the kernel's block buffer cache
entirely: all I/O is done directly to and from the address space of the
process performing the I/O. If the underlying block device driver can
support DMA, then no data copying at all is required to complete the
I/O.
Because raw I/O involves direct hardware access to a process's memory,
a few extra restrictions must be observed. All I/Os must be correctly
aligned in memory and on disk: they must start at a sector offset on
disk, they must be an exact number of sectors long, and the data buffer
in virtual memory must also be aligned to a multiple of the sector
size. The sector size is 512 bytes for most devices. [2]
- Starting with the Linux 2.6 kernel, raw devices are being phased out in favor
of O_DIRECT access to block devices.
- raw裝置使用
在核心配置CONFIG_RAW_DRIVER開啟的情況下。
#lsmod | grep raw
raw 3130 0
# ls /dev/raw/rawctl
/dev/raw/rawctl
RAW裝置綁定:
插入隨身碟
#fdisk -l
...
/dev/sdb1 1 983 7343962 b W95 FAT32
綁定
#raw /dev/raw/raw1 /dev/sdb1
/dev/raw/raw1: bound to major 8, minor 17
查看raw裝置的資訊
#ls -l /dev/raw/raw1
crw------- 1 root root 162, 1 Dec 24 15:23 /dev/raw/raw1
c表明raw裝置被映射為了字元裝置
# blockdev --report /dev/raw/raw1
RO RA SSZ BSZ StartSec Size Device
rw 256 512 512 14687986 275410944 /dev/raw/raw1
#cat /dev/raw/raw1
查看io狀況
#iostat -x
Linux 3.5.3 (Joseph) 12/24/2012
_x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
24.76 5.52 1.98 0.31 0.00 67.43
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
hdc 0.02 0.00 0.00 0.00 0.04 0.00 9.03 0.00 2.38 0.99 0.00
sda 0.01 4.18 1.59 1.16 31.47 42.37 26.85 0.07 26.10 3.47 0.95
sdb 0.00 0.00 0.02 0.00 0.29 0.00 15.25 0.00 14.22 13.58 0.03
解除綁定
#raw /dev/raw/raw1 0 0
----ref ----
[1] Linux 核心原始碼情景分析(上),毛德操。pg 492
[2] man raw