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. android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画

    ViewAnimationUtils.createCircularReveal()的简介: ViewAnimationUtils.createCircularReveal()是安卓5.0才引入的,快速 ...

  2. JavaScriptSerializer 序列化json 时间格式

    利用JavaScriptSerializer 序列化json 时间格式,得到的DateTime值值显示为“/Date(700000+0500)/”形式的JSON字符串,显然要进行转换 1.利用字符串直 ...

  3. 我有几个NUMA节点

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

  4. MathType应用:批量改变公式格式

    首先要安装好mathtype,一般装好后mathtype会嵌入到word里去(黄色和粉红的部分是今天的主角) 然后可以用带insert开头的选项(黄色部分)添加公式,但是添加公式后可能出现一下情况,即 ...

  5. CDH集群主节点宕机恢复

    1       情况概述 公司的开发集群在周末莫名其妙的主节点Hadoop-1的启动固态盘挂了,由于CM.HDFS的NameNode.HBase的Master都安装在Hadoop-1,导致了整个集群都 ...

  6. log4net的使用

    1.0 下载并引用 log4net.dll 2.0 修改Web.config <configuration> <configSections> <section name ...

  7. iOS面试题集锦

    一.前言部分 文中的问题多收集整理自网络,不保证100%准确,还望斟酌采纳. 1.怎样防止指针的越界使用问题? 答案: 1 .防止数组越界,必须让指针指向一个有效的内存地址, 2. 防止向一块内存中拷 ...

  8. EC笔记,第二部分:5.了解C++默默编写并调用哪些函数

    5.了解C++默默编写并调用哪些函数 1.C++空类 C++会为一个空类建立以下函数 (1).默认构造函数 (2).默认拷贝构造函数 (3).析构函数 (4).赋值运算符(如果成员包含引用类型或con ...

  9. [C/C++] DebugBreak

    在代码中直接调用DebugBreak()函数,可以使程序中断运行,和在IDE中设置断点中断运行的道理是一样的. 用这种方式,一些情况下比打断点更方便调试,如下,在test()函数返回0时激活断点 #i ...

  10. js 模块化的一些理解和es6模块化学习

    模块化 1 IIFE 2 commonjs 3 浏览器中js的模块化 4 简单理解模块加载器的原理  5 es6 之前在参加百度前端技术学院做的小题目的时候,自己写模块的时候 都是写成立即调用表达式( ...