Skip to content

Commit 90e07e0

Browse files
committed
Support for file readahead under linux using readahead
1 parent b647aee commit 90e07e0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/io.c

Lines changed: 16 additions & 3 deletions
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+
// radvisory and F_RDAVICE is not support, to reuse code
2071+
// define structure here 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,14 @@ _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 EBADF: break; // bad file desciptor
2100+
case EINVAL: break; // wrong file type to apply
2101+
default: (void)dispatch_assume_zero(err); break;
2102+
);
2103+
#else
20912104
_dispatch_io_syscall_switch(err,
20922105
fcntl(op->fd_entry->fd, F_RDADVISE, &advise),
20932106
case EFBIG: break; // advised past the end of the file rdar://10415691

0 commit comments

Comments
 (0)