Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Speeding boot with readahead, Or just including for those that wish :)< Next Oldest | Next Newest >
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Sep. 27 2007,14:33 QUOTE

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!
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Oct. 04 2007,17:38 QUOTE

Here's a compiled version

I will see how this could be best used during DSL boot. Comments anyone?


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Oct. 05 2007,14:54 QUOTE

I'll tell the Ubuntu philosophy of using it:

They have a list of files accessed during boot. They generated it with the boot watcher program, the one that also creates graphs of cpu usage per process etc.
Then they ordered it to the order they are on the disk, for faster reading.

They then launch it as a background process near the very start of booting. While this still has a nice effect on boot speed, it's not ideal.

Because it continuously accesses the media, other processes will have to wait or they go first and it slows down. Also if the process that needs a file is run before readahead reads the file, there will be no effect.

So, with DSL I plan to use it in carefully selected parts, like during cpu-using processes. And in pieces, not in one long run. This will make it more effective.


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
vda Offline





Group: Members
Posts: 2
Joined: Oct. 2007
Posted: Oct. 25 2007,17:33 QUOTE

[shameless plug]

Readahead is available in busybox.

>It takes only 3kb when compiled with -Os and stripped

In busybox, it takes 104 bytes - 3.5% of 3 Kb. Not bad, eh? :)

By including busybox, DSL will get readahead and ~200 other programs in 700kb of code.

[end shameless plug]
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Oct. 26 2007,13:06 QUOTE

DSL already has busybox, and readahead was added in 1.7 I think.

--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
4 replies since Sep. 27 2007,14:33 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: Speeding boot with readahead

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code