diff options
author | Rob Landley <rob@landley.net> | 2006-08-20 22:12:18 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-08-20 22:12:18 +0000 |
commit | 0e4690d4ef9fe55ccf6db371c826112809e162f9 (patch) | |
tree | 1eac13023c328f3956a00f3e741eb1cda45696d0 /miscutils | |
parent | 289e86a0a5b2482fc1b6a442d3acd749639e4d64 (diff) | |
download | busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.tar.gz busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.tar.bz2 busybox-w32-0e4690d4ef9fe55ccf6db371c826112809e162f9.zip |
Michael Opdenacker contributed a readahead applet.
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/Config.in | 16 | ||||
-rw-r--r-- | miscutils/Makefile.in | 1 | ||||
-rw-r--r-- | miscutils/readahead.c | 36 |
3 files changed, 53 insertions, 0 deletions
diff --git a/miscutils/Config.in b/miscutils/Config.in index 4296b54ea..9ad342151 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -276,6 +276,22 @@ config CONFIG_MT | |||
276 | to advance or rewind a tape past a specified number of archive | 276 | to advance or rewind a tape past a specified number of archive |
277 | files on the tape. | 277 | files on the tape. |
278 | 278 | ||
279 | config CONFIG_READAHEAD | ||
280 | bool "readahead" | ||
281 | default n | ||
282 | help | ||
283 | Preload the files listed on the command line into RAM cache so that | ||
284 | subsequent reads on these files will not block on disk I/O. | ||
285 | |||
286 | This applet just calls the readahead(2) system call on each file. | ||
287 | It is mainly useful in system startup scripts to preload files | ||
288 | or executables before they are used. When used at the right time | ||
289 | (in particular when a CPU boundprocess is running) it can | ||
290 | significantly speed up system startup. | ||
291 | |||
292 | As readahead(2) blocks until each file has been read, it is best to | ||
293 | run this applet as a background job. | ||
294 | |||
279 | config CONFIG_RUNLEVEL | 295 | config CONFIG_RUNLEVEL |
280 | bool "runlevel" | 296 | bool "runlevel" |
281 | default n | 297 | default n |
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in index a0b6b7233..25143c10b 100644 --- a/miscutils/Makefile.in +++ b/miscutils/Makefile.in | |||
@@ -24,6 +24,7 @@ MISCUTILS-${CONFIG_LESS} += less.o | |||
24 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o | 24 | MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o |
25 | MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o | 25 | MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o |
26 | MISCUTILS-$(CONFIG_MT) += mt.o | 26 | MISCUTILS-$(CONFIG_MT) += mt.o |
27 | MISCUTILS-$(CONFIG_READAHEAD) += readahead.o | ||
27 | MISCUTILS-$(CONFIG_RUNLEVEL) += runlevel.o | 28 | MISCUTILS-$(CONFIG_RUNLEVEL) += runlevel.o |
28 | MISCUTILS-$(CONFIG_RX) += rx.o | 29 | MISCUTILS-$(CONFIG_RX) += rx.o |
29 | MISCUTILS-$(CONFIG_SETSID) += setsid.o | 30 | MISCUTILS-$(CONFIG_SETSID) += setsid.o |
diff --git a/miscutils/readahead.c b/miscutils/readahead.c new file mode 100644 index 000000000..9f1bb47be --- /dev/null +++ b/miscutils/readahead.c | |||
@@ -0,0 +1,36 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * readahead implementation for busybox | ||
4 | * | ||
5 | * Preloads the given files in RAM, to reduce access time. | ||
6 | * Does this by calling the readahead(2) system call. | ||
7 | * | ||
8 | * Copyright (C) 2006 Michael Opdenacker <michael@free-electrons.com> | ||
9 | * | ||
10 | * Licensed under GPLv2 or later, see file License in this tarball for details. | ||
11 | */ | ||
12 | |||
13 | #include "busybox.h" | ||
14 | |||
15 | int readahead_main(int argc, char **argv) | ||
16 | { | ||
17 | FILE *f; | ||
18 | struct stat stat_buf; | ||
19 | int retval = EXIT_SUCCESS; | ||
20 | |||
21 | if (argc == 1) bb_show_usage(); | ||
22 | |||
23 | while (*++argv) { | ||
24 | if ((f = bb_wfopen(*argv, "r")) != NULL) { | ||
25 | int r, fd=fileno(f); | ||
26 | |||
27 | xstat(*argv, &stat_buf); | ||
28 | r = readahead(fd, 0, fdlength(fd)); | ||
29 | fclose(f); | ||
30 | if (r >= 0) continue; | ||
31 | } | ||
32 | retval = EXIT_FAILURE; | ||
33 | } | ||
34 | |||
35 | return retval; | ||
36 | } | ||