Linux内核的文件预读readahead
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
Linux内核的文件预读readahead的更多相关文章
- Linux 内核的文件 Cache 管理机制介绍
Linux 内核的文件 Cache 管理机制介绍 http://www.ibm.com/developerworks/cn/linux/l-cache/ 1 前言 自从诞生以来,Linux 就被不断完 ...
- Linux 内核的文件 Cache 管理机制介绍-ibm
https://www.ibm.com/developerworks/cn/linux/l-cache/ 1 前言 自从诞生以来,Linux 就被不断完善和普及,目前它已经成为主流通用操作系统之一,使 ...
- Linux内核头文件与内核与库的关系
看上一篇文章中对buildroot的介绍,里面的文档第 3.1.1.1 Internal toolchain backend 节内容 C库会去访问Linux kernel headers(*.h)文件 ...
- linux内核initrd文件自定义方法
linux内核initrd文件自定义方法 重新编译内核后,可能加入了自定义的模块,就有可能需要修改init文件,而init文件就在initrd中,这里记录下操作步骤,以防遗忘. 1. cp /bo ...
- Linux内核DTB文件启动的几种方式
版权: 凌云物网智科实验室< www.iot-yun.com > 声明: 本文档由凌云物网智科实验室郭工编著! 作者: 郭文学< QQ: 281143292 guowen ...
- Linux内核Makefile文件(翻译自内核手册)
--译自Linux3.9.5 Kernel Makefiles(内核目录documention/kbuild/makefiles.txt) kbuild(kernel build) 内核编译器 Thi ...
- linux 内核头文件 linux kernel header
概述:在进行有关系统软件的安装的时候(编译一个新的驱动,或者安装一个系统级别的测试工具,例如systemtap),经常需要重新编译内核,相应的问题往往与内核头文件有关.那么,什么是内核头文件,为什么需 ...
- linux内核头文件 cdev.h 解析
遇到一个内核API--cdev_init 就找到这里来了. #ifndef _LINUX_CDEV_H #define _LINUX_CDEV_H #include <linux/kobject ...
- 从 Linux 内核角度探秘 JDK NIO 文件读写本质
1. 前言 笔者在 <从 Linux 内核角度看 IO 模型的演变>一文中曾对 Socket 文件在内核中的相关数据结构为大家做了详尽的阐述. 又在此基础之上介绍了针对 socket 文件 ...
随机推荐
- Git代码管理工具
Git代码管理工具 Git 是分布式的源代码管理工具,这点区别于svn -让源代码可以被追溯,主要是记录了每次的更新了什么,如果新版本不想用,那么则可以退回之前的版本 -Git 是Linux之父当年为 ...
- ZOJ Problem Set - 1350 The Drunk Jailer ac代码 memset
这是一道很简单的题目,题目大概意思说下:就是有n个监狱(编号从1到n),第一次全部打开,第二次打开编号为2的倍数的,第三次打开编号为3的倍数的,以此类推...最后问你有几个监狱是打开的 题目中我使用了 ...
- Hibernate之加载策略(延迟加载与即时加载)和抓取策略(fetch)
假设现在有Book和Category两张表,表的关系为双向的一对多,表结构如下: 假设现在我想查询id为2的那本书的书名,使用session.get(...)方法: Session session=H ...
- hibernate笔记--cascade级联以及inverse属性
cascade : 不管是单向多对一还是一对多,或者是双向的一对多关系,在一的一端映射文件中有一个set标签,在多的一端有many-to-one标签,拿前几篇笔记里讲的Grade和Student举例, ...
- 探秘Tomcat——连接篇
前两篇我们分别粗线条和细粒度的讲解了tomcat的服务是如何启动以及连接器Connector和容器Container又分别是如何被启动的. 本篇我们主要侧重tomcat中server.service以 ...
- DotNet处理服务器路径的方法
项目中需要使用到路径处理的地方比较多,对于路径的解析和匹配有时较为繁琐,现在提供一个对路径进行解析的方法: 1.验证设置路径字符串: /// <summary> /// 验证设置路径字符串 ...
- WebSocket 学习(三)--用nodejs搭建服务器
前面已经学习了WebSocket API,包括事件.方法和属性.详情:WebSocket(二)--API WebSocket是基于事件驱动,支持全双工通信.下面通过三个简单例子体验一下. 简单开始 ...
- phpStorm入门
首先在官网上下载并安装:http://www.jetbrains.com/phpstorm/; 安装成功后需要激活: IntelliJ IDEA开源社区 提供了如下通用激活方法: 注册时选择Licen ...
- maven全局配置文件settings.xml详解
概要 settings.xml有什么用? 如果在Eclipse中使用过Maven插件,想必会有这个经验:配置settings.xml文件的路径. settings.xml文件是干什么的,为什么要配置它 ...
- 在C#中,Json的序列化和反序列化的几种方式总结
在这篇文章中,我们将会学到如何使用C#,来序列化对象成为Json格式的数据,以及如何反序列化Json数据到对象. 什么是JSON? JSON (JavaScript Object Notation) ...

