curaga
Group: Members
Posts: 2163
Joined: Feb. 2007 |
|
Posted: Sep. 27 2007,14:33 |
|
Quote | #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/syscall.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sched.h>
void process_file(char *filename) { int fd; struct stat buf; if (!filename) return; fd = open(filename,O_RDONLY); if (fd<0) return; if (fstat(fd, &buf)<0) return; #if 0 /* don't readahead on nfs */ if (!gnu_dev_major(buf.st_dev)) return; #endif readahead(fd, (loff_t)0, (size_t)buf.st_size); /* posix_fadvise(fd, (off_t) 0, (off_t) 0, POSIX_FADV_NORMAL|POSIX_FADV_WILLNEED); */ close(fd); /* be nice to other processes now */ sched_yield(); }
int main(int argc, char **argv) { int i; for (i=1; i<argc; i++) process_file(argv[i]); return 0; } |
Here's the c code of the most recent version of readahead I found (1.01-2 - ubuntu1), from Ubuntu's Gutsy repository. It takes only 3kb when compiled with -Os and stripped, and needs only glibc and the kernel headers.
I can't right now compile it on DSL, and the ones compiled on my Aero are most certainly not DSL compatible..
Readahead is commonly used to speed up the boot, by using it in the background during a cpu-headed process (like the hwconfig with the green bar, it doesn't read anything and takes some time that could be used) to load the files needed by the next part of the boot into cache.
It works, I tested with Mplayer (reading that 8mb binary takes some seconds, but when I loaded it into cache with readahead, surprise it started instantly) and remembered to clean the cache between tests.
-------------- There's no such thing as life. Those mean little jocks invented it ;) - Windows is not a virus. A virus does something!
|