readahead * 4
版权声明: 允许非商业性转载,但转载时必须标明原作者 fcicq、原始链接 http://www.fcicq.net/wp/?p=493 及本声明。
readahead:
1 系统调用
2 实用程序
3 系统服务
4 内核补丁
千万别晕!
1 系统调用
无须解释.取自man.
NAME
readahead – perform file readahead into page cache
SYNOPSIS
#include <fcntl .h>
ssize_t readahead(int fd, off64_t *offset, size_t count);
DESCRIPTION
readahead() populates the page cache with data from a file so that subsequent reads from that file will not block on disk I/O. The fd argument is a file descriptor identifying the file which is to be read. The offset argument specifies the starting point from which data is to be read and count specifies the number of bytes to be read. I/O is performed in whole pages, so that offset is effectively rounded down to a page boundary and bytes are read up to the next page boundary greater than or equal to (offset+count). readahead() does not read beyond the end of the file. readahead() blocks until the specified data has been read. The current file offset of the open file referred to by fd is left unchanged.
2 实用程序
readahead(http://cvs.fedora.redhat.com/viewcvs/devel/readahead/):
readahead reads the contents of a list of files into memory, which causes them to be read from cache when they are actually needed. It’s goal is to speed up the boot process.
类似的居然还有readahead-list(不过这是一个长期未更新的项目了),preload
readahead-list:
Preloads files into the page cache to accelerate program loading.
preload(http://sourceforge.net/projects/preload):
preload is an adaptive readahead daemon. It monitors applications that users run, and by analyzing this data, predicts what applications users might run, and fetches those binaries and their dependencies into memory for faster startup times.
更为神奇的是busybox中也包括了简化版的readahead.
这些应用程序都调用了前面所说的,叫做readahead的系统调用.
3 系统服务
第一个: [HOWTO] Best boot speedup yet!!
稍微分析一下.
…
function collect_sample()
{
/usr/sbin/lsof -F n -f |grep “^n”|sed -e “s:^n::g” | grep -v “^$” | grep -v “^/dev”| grep -v “^/proc”| grep -v “^/tmp”| grep -v “^/var”| grep -v “/.mozilla”| grep “^/[a-z]” > $1
}
获取需要预读的文件列表,这样或许比较准.
cat `cat /etc/conf.d/sofile-list.load` > /dev/null 2>&1 &
这就是所谓的readahead.
当然也可以修改成busybox readahead …,效果差不多.
第二个: 严格讲,前面说的readahead-list,preload都属于这一类.
具体实现方式和这大同小异.
4 内核补丁
参见:Linux 核心大补:性能与危险同在
这部分不想详细说了
ps: hdparm中也有readahead
-a get/set fs readahead
-A set drive read-lookahead flag (0/1)
友情提示: 请注意文章的时效性与准确性, 作者不对文章的有效性负责.
Tags: reference
Permalink Bookmark on del.icio.us
Last Modified: June 7, 2007 at 9:39 pm