diff --git a/dom/system/OSFileConstants.cpp b/dom/system/OSFileConstants.cpp index 58e010b1e311..d39a01616d7b 100644 --- a/dom/system/OSFileConstants.cpp +++ b/dom/system/OSFileConstants.cpp @@ -15,6 +15,10 @@ #include "sys/stat.h" #endif // defined(XP_UNIX) +#if defined(XP_LINUX) +#include +#endif // defined(XP_LINUX) + #if defined(XP_MACOSX) #include "copyfile.h" #endif // defined(XP_MACOSX) @@ -320,6 +324,10 @@ static const dom::ConstantSpec gLibcProperties[] = INT_CONSTANT(AT_SYMLINK_NOFOLLOW), #endif //defined(AT_SYMLINK_NOFOLLOW) +#if defined(POSIX_FADV_SEQUENTIAL) + INT_CONSTANT(POSIX_FADV_SEQUENTIAL), +#endif //defined(POSIX_FADV_SEQUENTIAL) + // access #if defined(F_OK) INT_CONSTANT(F_OK), diff --git a/toolkit/components/osfile/modules/osfile_unix_back.jsm b/toolkit/components/osfile/modules/osfile_unix_back.jsm index 38a8e30c9353..a4166e5aeda5 100644 --- a/toolkit/components/osfile/modules/osfile_unix_back.jsm +++ b/toolkit/components/osfile/modules/osfile_unix_back.jsm @@ -447,6 +447,14 @@ /*buf*/ Types.void_t.out_ptr, /*nbytes*/Types.size_t); + UnixFile.posix_fadvise = + declareFFI("posix_fadvise", ctypes.default_abi, + /*return*/ Types.int, + /*fd*/ Types.fd, + /*offset*/ Types.off_t, + /*len*/ Types.off_t, + /*advise*/ Types.int); + if (OS.Constants.libc._DARWIN_FEATURE_64_BIT_INODE) { // Special case for MacOS X 10.5+ // Symbol name "readdir" still exists but is used for a diff --git a/toolkit/components/osfile/modules/osfile_unix_front.jsm b/toolkit/components/osfile/modules/osfile_unix_front.jsm index 430f8c89b142..7afb4b29eaa3 100644 --- a/toolkit/components/osfile/modules/osfile_unix_front.jsm +++ b/toolkit/components/osfile/modules/osfile_unix_front.jsm @@ -92,6 +92,13 @@ * @throws {OS.File.Error} In case of I/O error. */ File.prototype._read = function _read(buffer, nbytes, options) { + // Populate the page cache with data from a file so the subsequent reads + // from that file will not block on disk I/O. + if ((UnixFile.posix_fadvise && + options.sequential || !("sequential" in options))) { + UnixFile.posix_fadvise(this.fd, 0, nbytes, + OS.Constants.libc.POSIX_FADV_SEQUENTIAL); + } return throw_on_negative("read", UnixFile.read(this.fd, buffer, nbytes) );