@ -88,6 +88,24 @@ int Fadvise(int fd, off_t offset, size_t len, int advice) {
# endif
# endif
}
}
int FadviseForHint ( int fd , FSRandomAccessFile : : AccessPattern pattern ) {
switch ( pattern ) {
case FSRandomAccessFile : : AccessPattern : : kNormal :
return Fadvise ( fd , 0 , 0 , POSIX_FADV_NORMAL ) ;
case FSRandomAccessFile : : AccessPattern : : kRandom :
return Fadvise ( fd , 0 , 0 , POSIX_FADV_RANDOM ) ;
case FSRandomAccessFile : : AccessPattern : : kSequential :
return Fadvise ( fd , 0 , 0 , POSIX_FADV_SEQUENTIAL ) ;
case FSRandomAccessFile : : AccessPattern : : kWillNeed :
return Fadvise ( fd , 0 , 0 , POSIX_FADV_WILLNEED ) ;
case FSRandomAccessFile : : AccessPattern : : kWontNeed :
return Fadvise ( fd , 0 , 0 , POSIX_FADV_DONTNEED ) ;
default :
assert ( false ) ;
return 1 ;
}
}
namespace {
namespace {
// On MacOS (and probably *BSD), the posix write and pwrite calls do not support
// On MacOS (and probably *BSD), the posix write and pwrite calls do not support
@ -821,26 +839,7 @@ void PosixRandomAccessFile::Hint(AccessPattern pattern) {
if ( use_direct_io ( ) ) {
if ( use_direct_io ( ) ) {
return ;
return ;
}
}
switch ( pattern ) {
FadviseForHint ( fd_ , pattern ) ;
case kNormal :
Fadvise ( fd_ , 0 , 0 , POSIX_FADV_NORMAL ) ;
break ;
case kRandom :
Fadvise ( fd_ , 0 , 0 , POSIX_FADV_RANDOM ) ;
break ;
case kSequential :
Fadvise ( fd_ , 0 , 0 , POSIX_FADV_SEQUENTIAL ) ;
break ;
case kWillNeed :
Fadvise ( fd_ , 0 , 0 , POSIX_FADV_WILLNEED ) ;
break ;
case kWontNeed :
Fadvise ( fd_ , 0 , 0 , POSIX_FADV_DONTNEED ) ;
break ;
default :
assert ( false ) ;
break ;
}
}
}
IOStatus PosixRandomAccessFile : : InvalidateCache ( size_t offset , size_t length ) {
IOStatus PosixRandomAccessFile : : InvalidateCache ( size_t offset , size_t length ) {
@ -982,6 +981,10 @@ IOStatus PosixMmapReadableFile::Read(uint64_t offset, size_t n,
return s ;
return s ;
}
}
void PosixMmapReadableFile : : Hint ( AccessPattern pattern ) {
FadviseForHint ( fd_ , pattern ) ;
}
IOStatus PosixMmapReadableFile : : InvalidateCache ( size_t offset , size_t length ) {
IOStatus PosixMmapReadableFile : : InvalidateCache ( size_t offset , size_t length ) {
# ifndef OS_LINUX
# ifndef OS_LINUX
( void ) offset ;
( void ) offset ;