linux-scalability-benchmarks / libowfat / io / iob_prefetch.c

The default branch has multiple heads

#include "iob_internal.h"

#ifdef __MINGW32__

/* not supported */
void iob_prefetch(io_batch* b,uint64 bytes) {
  (void)b;
  (void)bytes;
}

#else

#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>

void iob_prefetch(io_batch* b,uint64 bytes) {
  volatile char x;
  iob_entry* e,* last;
  if (b->bytesleft==0) return;
  last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b));
  e=(iob_entry*)array_start(&b->b);
  if (!e) return;
  for (; e<last; ++e) {
    if (e->type==FROMFILE) {
#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;
      if (e->n>=1000000) {
	long l=e->offset&4095;
	d=c=mmap(0,bytes,PROT_READ,MAP_SHARED,e->fd,(e->offset|4095)+1);
	bytes-=l;
	if (c!=MAP_FAILED) {
	  while (bytes>4095) {
	    x=*d;
	    bytes-=4096;
	    d+=4096;
	  }
	}
	munmap(c,before);
      }
#endif
      return;
    }
  }
  (void)x;
}

#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.