Home | History | Annotate | Download | only in other
      1 /* readahead.c - preload files into disk cache.
      2  *
      3  * Copyright 2013 Rob Landley <rob (at) landley.net>
      4  *
      5  * No standard.
      6 
      7 USE_READAHEAD(NEWTOY(readahead, NULL, TOYFLAG_BIN))
      8 
      9 config READAHEAD
     10   bool "readahead"
     11   default y
     12   help
     13     usage: readahead FILE...
     14 
     15     Preload files into disk cache.
     16 */
     17 
     18 #include "toys.h"
     19 
     20 #include <sys/syscall.h>
     21 
     22 static void do_readahead(int fd, char *name)
     23 {
     24   int rc;
     25 
     26   // Since including fcntl.h doesn't give us the wrapper, use the syscall.
     27   // 32 bits takes LO/HI offset (we don't care about endianness of 0).
     28   if (sizeof(long) == 4) rc = syscall(__NR_readahead, fd, 0, 0, INT_MAX);
     29   else rc = syscall(__NR_readahead, fd, 0, INT_MAX);
     30 
     31   if (rc) perror_msg("readahead: %s", name);
     32 }
     33 
     34 void readahead_main(void)
     35 {
     36   loopfiles(toys.optargs, do_readahead);
     37 }
     38