Skip to content

Commit d5456c8

Browse files
frankehdas
authored andcommitted
Linux support for readahead
Signed-off-by: Daniel A. Steffen <[email protected]>
1 parent 1b201fe commit d5456c8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/io.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -2066,9 +2066,14 @@ _dispatch_disk_perform(void *ctxt)
20662066
static void
20672067
_dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
20682068
{
2069-
#ifndef F_RDADVISE
2070-
LINUX_PORT_ERROR();
2071-
#else
2069+
#ifdef __linux__
2070+
// linux does not support fcntl (F_RDAVISE)
2071+
// define necessary datastructure and use readahead
2072+
struct radvisory {
2073+
off_t ra_offset;
2074+
int ra_count;
2075+
};
2076+
#endif
20722077
int err;
20732078
struct radvisory advise;
20742079
// No point in issuing a read advise for the next chunk if we are already
@@ -2088,6 +2093,13 @@ _dispatch_operation_advise(dispatch_operation_t op, size_t chunk_size)
20882093
}
20892094
advise.ra_offset = op->advise_offset;
20902095
op->advise_offset += advise.ra_count;
2096+
#ifdef __linux__
2097+
_dispatch_io_syscall_switch(err,
2098+
readahead(op->fd_entry->fd, advise.ra_offset, advise.ra_count),
2099+
case EINVAL: break; // fd does refer to a non-supported filetype
2100+
default: (void)dispatch_assume_zero(err); break;
2101+
);
2102+
#else
20912103
_dispatch_io_syscall_switch(err,
20922104
fcntl(op->fd_entry->fd, F_RDADVISE, &advise),
20932105
case EFBIG: break; // advised past the end of the file rdar://10415691

0 commit comments

Comments
 (0)