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. DEBIAN下中文显示

    转:http://www.cppblog.com/colorful/archive/2012/05/28/176516.aspx 一.首先检查LOCALE情况 说明:DEBIAN因为基于GNU所以,对 ...

  2. DOM 节点的克隆与删除

    无奈的开头 关于DOM节点操作,如果仅仅是根据标准API来操作,那是最简单不过的了.但是现实中却哪有这么容易的问题让我们解决,其实不仅仅是节点的克隆与删除,节点的添加也是如此,而且添加节点需要考虑的情 ...

  3. 重温Servlet学习笔记--编码问题

    在说编码问题之前,首先先了解一下常见的字符编码: ISO-8859-1:  拉丁编码,不支持中文 gbk,gb2312,gb18030:系统默认编码,是中国的国标码 utf-8: 支持几乎所有语言的编 ...

  4. Cesium原理篇:3最长的一帧之地形(1)

    前面我们从宏观上分析了Cesium的整体调度以及网格方面的内容,通过前两篇,读者应该可以比较清楚的明白一个Tile是怎么来的吧(如果还不明白全是我的错).接下来,在前两篇的基础上,我们着重讨论一下地形 ...

  5. 大型网站提速关键技术(页面静态化,memcached,MySql优化)(三)

    页面静态化的技术实现有两种方式 使用PHP自己的缓存机制 先说明一下OB缓存的机制. ob1.php 代码:说明的ob的各个用法->项目中 ☞ 如何打开ob缓存 ①     配置php.ini ...

  6. 通过 WebSocket 实现 WebGL 3D 拓扑图实时数据通讯同步(二)

    我们上一篇<基于 WebSocket 实现 WebGL 3D 拓扑图实时数据通讯同步(一)>主要讲解了如何搭建一个实时数据通讯服务器,客户端与服务端是如何通讯的,相信通过上一篇的讲解,再配 ...

  7. 初学Python遇到的问题一二

    这篇文章只是学Python最最最基础的部分知识,如果你已经有过python经验,哪怕就一点点经验,或许你都遇到过,但相信这些问题对你来说早已不算问题了,所以请跳过吧,用你的时间去学习更多其他的知识就好 ...

  8. CSS垂直居中和水平居中

    前言 CSS居中一直是一个比较敏感的话题,为了以后开发的方便,楼主觉得确实需要总结一下了,总的来说,居中问题分为垂直居中和水平居中,实际上水平居中是很简单的,但垂直居中的方式和方法就千奇百怪了. 内联 ...

  9. 设计模式(四)抽象工厂模式(Abstract Factory Pattern)

    一.引言 在上一专题中介绍了工厂方法模式,工厂方法模式是为了克服简单工厂模式的缺点而设计出来的,简单工厂模式的工厂类随着产品类的增加需要增加额外的代码,而工厂方法模式每个具体工厂类只完成单个实例的创建 ...

  10. 向上弹出菜单jQuery插件

    插件名:柯乐义英文名:Keleyijs文件名称:jquery.keleyi.js插件功能:该插件可以让你轻易地在页面上构建一个向上弹出的二级菜单. 示例查看:http://keleyi.com/kel ...