Linux raw device 裸设备

  ┌────────────────────────────────────────────────────────── 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设备绑定:
   插入U盘
   #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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值