Linux内核的文件预读readahead
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux内核的文件预读readahead,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3710字,纯文字阅读大概需要6分钟。
内容图文
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.cnblogs.com/kerrycode/p/4743015.html
内容总结
以上是互联网集市为您收集整理的Linux内核的文件预读readahead全部内容,希望文章能够帮你解决Linux内核的文件预读readahead所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。