Linux的文件预读readahead,指Linux系统内核将指定文件的某区域预读进页缓存起来,便于接下来对该区域进行读取时,不会因缺页(page fault)而阻塞。因为从内存读取比从磁盘读取要快很多。预读可以有效的减少磁盘的寻道次数和应用程序的I/O等待时间,是改进磁盘读I/O性能的重要优化手段之一。

维基百科上关于readhead的介绍资料:

readahead is a system call of the Linux kernel that loads a file's contents into the page cache, providing that way a file prefetching technology. When a file is subsequently accessed, its contents are read from the main memory (RAM) rather than from a hard disk drive (HDD), resulting in much lower file access latencies due to much higher performance of the main memory.[1][2]

Many Linux distributions use readahead on a list of commonly used files to speed up booting. In such a setup, if the kernel is booted with the profile boot parameter, it will record all file accesses during bootup and write a new list of files to be read during later boot sequences. This will make additional installed services start faster, because they are not included in the default readahead list.[3]

In Linux distributions that use systemd, readahead binary (as part of the boot sequence) is replaced by systemd-readahead.[4][5] However, support for readahead was removed from systemd in its version 219, being described as unmaintained and unable to provide expected performance benefits.[6]

Certain experimental page-level prefetching systems have been developed to further improve performance.[7]

查看、设置readhead使用命令blockdev。如下所示:

[root@localhost ~]# /sbin/blockdev

 

Usage:

  blockdev -V

  blockdev --report [devices]

  blockdev [-v|-q] commands devices

 

Available commands:

        --getsz                        get size in 512-byte sectors

        --setro                        set read-only

        --setrw                        set read-write

        --getro                        get read-only

        --getss                        get logical block (sector) size

        --getpbsz                      get physical block (sector) size

        --getiomin                     get minimum I/O size

        --getioopt                     get optimal I/O size

        --getalignoff                  get alignment offset

        --getmaxsect                   get max sectors per request

        --getbsz                       get blocksize

        --setbsz BLOCKSIZE             set blocksize on file descriptor opening the block device

        --getsize                      get 32-bit sector count

        --getsize64                    get size in bytes

        --setra READAHEAD              set readahead

        --getra                        get readahead

        --setfra FSREADAHEAD           set filesystem readahead

        --getfra                       get filesystem readahead

        --flushbufs                    flush buffers

        --rereadpt                     reread partition table

查看磁盘的预读扇区

[root@localhost ~]# /sbin/blockdev --getra /dev/sda

 

256

 

[root@localhost ~]# /sbin/blockdev --getra /dev/sdb

 

256

 

[root@localhost ~]# 

设置磁盘的预读扇区

[root@localhost ~]# /sbin/blockdev --getra /dev/sda

256

[root@localhost ~]# /sbin/blockdev --setra 2048 /dev/sda

[root@localhost ~]# /sbin/blockdev --getra /dev/sda

2048

[root@localhost ~]# /sbin/blockdev --getra /dev/sdb

256

[root@localhost ~]# /sbin/blockdev --setra 2048 /dev/sdb

[root@localhost ~]# /sbin/blockdev --getra /dev/sdb

2048

[root@localhost ~]# 

必须将其写入配置文件/etc/rc.local,否则重启就会失效。

 

[root@localhost ~]# echo '/sbin/blockdev --setra 2048 /dev/sda' >> /etc/rc.local

[root@localhost ~]# more /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local

/sbin/blockdev --setra 2048 /dev/sda

[root@localhost ~]# echo '/sbin/blockdev --setra 2048 /dev/sdb' >> /etc/rc.local

[root@localhost ~]# more /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local

/sbin/blockdev --setra 2048 /dev/sda

/sbin/blockdev --setra 2048 /dev/sdb

 

参考资料:

https://en.wikipedia.org/wiki/Readahead

http://www.hustyx.com/cpp/96/

Linux内核的文件预读readahead的更多相关文章

  1. Linux 内核的文件 Cache 管理机制介绍

    Linux 内核的文件 Cache 管理机制介绍 http://www.ibm.com/developerworks/cn/linux/l-cache/ 1 前言 自从诞生以来,Linux 就被不断完 ...

  2. Linux 内核的文件 Cache 管理机制介绍-ibm

    https://www.ibm.com/developerworks/cn/linux/l-cache/ 1 前言 自从诞生以来,Linux 就被不断完善和普及,目前它已经成为主流通用操作系统之一,使 ...

  3. Linux内核头文件与内核与库的关系

    看上一篇文章中对buildroot的介绍,里面的文档第 3.1.1.1 Internal toolchain backend 节内容 C库会去访问Linux kernel headers(*.h)文件 ...

  4. linux内核initrd文件自定义方法

    linux内核initrd文件自定义方法 重新编译内核后,可能加入了自定义的模块,就有可能需要修改init文件,而init文件就在initrd中,这里记录下操作步骤,以防遗忘. 1.  cp  /bo ...

  5. Linux内核DTB文件启动的几种方式

      版权:  凌云物网智科实验室< www.iot-yun.com > 声明:  本文档由凌云物网智科实验室郭工编著! 作者:  郭文学< QQ: 281143292  guowen ...

  6. Linux内核Makefile文件(翻译自内核手册)

    --译自Linux3.9.5 Kernel Makefiles(内核目录documention/kbuild/makefiles.txt) kbuild(kernel build) 内核编译器 Thi ...

  7. linux 内核头文件 linux kernel header

    概述:在进行有关系统软件的安装的时候(编译一个新的驱动,或者安装一个系统级别的测试工具,例如systemtap),经常需要重新编译内核,相应的问题往往与内核头文件有关.那么,什么是内核头文件,为什么需 ...

  8. linux内核头文件 cdev.h 解析

    遇到一个内核API--cdev_init 就找到这里来了. #ifndef _LINUX_CDEV_H #define _LINUX_CDEV_H #include <linux/kobject ...

  9. 从 Linux 内核角度探秘 JDK NIO 文件读写本质

    1. 前言 笔者在 <从 Linux 内核角度看 IO 模型的演变>一文中曾对 Socket 文件在内核中的相关数据结构为大家做了详尽的阐述. 又在此基础之上介绍了针对 socket 文件 ...

随机推荐

  1. 1Z0-053 争议题目解析346

    1Z0-053 争议题目解析346 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 346.What is the impact of the results of the outp ...

  2. hibernate笔记--组合主键映射方法

    一个数据库表中其主键有可能不止一个属性,同样映射到实体类中,可能有两个或多个属性共同配置成为一个主键,假设一个实体类Score,其主键有两个属性stuId(学生编号)和subjectId(科目编号), ...

  3. iOS_UIImage_毛玻璃效果

    效果图: 核心方法: // 出入UIImage 和 blur模糊成度 (0-1) - (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CG ...

  4. Node.js、Express、Socket.io 入门

    前言 周末断断续续的写了第一个socket.io Demo.初次接触socket.io是从其官网看到的,看着get started做了一遍,根据官网的Demo能提供简单的服务端和客户端通讯. 这个De ...

  5. 我有几个NUMA节点

    在SQL Server交流会,经常被问到的一个问题,SQL Server在几个NUMA节点上运行.因此,在今天的文章里,我想向你展示下几个方法和技术,找出你的SQL Server有几个NUMA节点. ...

  6. 六、CsrfViewMiddleware

    CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSRF/XSRF. 你这可 ...

  7. js的stopPropagation()、cancelBubble、preventDefault()、return false的分析

    个人笔记,如有错误,望指出. 事件冒泡,举个列子: <li> <a href='http://www.baidu.com'>点击a</a> </li> ...

  8. JavaScript一词被《牛津大词典》收录了

    早上看VS Team的推特发了这个图片,以前总爱问Java怎么读,现在好了,有标准发音了. 确定是 扎瓦·死磕瑞普特 ,哈哈,以后不要再念加瓦了. …… Last month JavaScript r ...

  9. Java基本概念(2)J2EE里面的2是什么意思

    J2EE里面的2是什么意思 J2SE,J2SE,J2ME中2的含义要追溯要1998年.1998年Java 1.2版本发布,1999年发布Java 1.2的标准版,企业版,微型版三个版本,为了区分这三个 ...

  10. linux下的目录结构和内容

    用了这么长时间linux系统,有时候哪个文件应该在哪还是不知道的,所以对于根下的目录结构记下: /bin bin是Binary的缩写.这个目录存放着最经常使用的命令. /boot这里存放的是启动Lin ...