Browse Source

use madvise MADV_PREFETCH to implement iob_prefetch

master
Felix von Leitner 16 years ago
parent
commit
017557490a
2 changed files with 8 additions and 0 deletions
  1. +1
    -0
      CHANGES
  2. +7
    -0
      io/iob_prefetch.c

+ 1
- 0
CHANGES View File

@ -1,5 +1,6 @@
0.21:
errno cleanup and man page updates (Rolf Eike Beer)
implement iob_prefetch with madvise MADV_WILLNEED if it's defined
0.20:
add errmsg API


+ 7
- 0
io/iob_prefetch.c View File

@ -12,6 +12,12 @@ void iob_prefetch(io_batch* b,uint64 bytes) {
if (!e) return;
for (; e<last; ++e) {
if (e->type==FROMFILE || e->type==FROMFILE_CLOSE) {
#ifdef MADV_WILLNEED
char* c;
c=mmap(0,bytes,PROT_READ,MAP_SHARED,e->fd,(e->offset|4095)+1);
madvise(c,bytes,MADV_WILLNEED);
munmap(c,bytes);
#else
char* c,* d;
uint64 before=bytes;
if (e->n<bytes) bytes=e->n;
@ -28,6 +34,7 @@ void iob_prefetch(io_batch* b,uint64 bytes) {
}
munmap(c,before);
}
#endif
return;
}
}


Loading…
Cancel
Save