@ -351,6 +351,7 @@ class PosixMmapFile : public WritableFile {
char * dst_ ; // Where to write next (in range [base_,limit_])
char * dst_ ; // Where to write next (in range [base_,limit_])
char * last_sync_ ; // Where have we synced up to
char * last_sync_ ; // Where have we synced up to
uint64_t file_offset_ ; // Offset of base_ in file
uint64_t file_offset_ ; // Offset of base_ in file
bool allow_fallocate_ ; // If false, fallocate calls are bypassed
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
bool fallocate_with_keep_size_ ;
bool fallocate_with_keep_size_ ;
# endif
# endif
@ -393,7 +394,7 @@ class PosixMmapFile : public WritableFile {
TEST_KILL_RANDOM ( rocksdb_kill_odds ) ;
TEST_KILL_RANDOM ( rocksdb_kill_odds ) ;
// we can't fallocate with FALLOC_FL_KEEP_SIZE here
// we can't fallocate with FALLOC_FL_KEEP_SIZE here
{
if ( allow_fallocate_ ) {
IOSTATS_TIMER_GUARD ( allocate_nanos ) ;
IOSTATS_TIMER_GUARD ( allocate_nanos ) ;
int alloc_status = fallocate ( fd_ , 0 , file_offset_ , map_size_ ) ;
int alloc_status = fallocate ( fd_ , 0 , file_offset_ , map_size_ ) ;
if ( alloc_status ! = 0 ) {
if ( alloc_status ! = 0 ) {
@ -451,7 +452,8 @@ class PosixMmapFile : public WritableFile {
limit_ ( nullptr ) ,
limit_ ( nullptr ) ,
dst_ ( nullptr ) ,
dst_ ( nullptr ) ,
last_sync_ ( nullptr ) ,
last_sync_ ( nullptr ) ,
file_offset_ ( 0 ) {
file_offset_ ( 0 ) ,
allow_fallocate_ ( options . allow_fallocate ) {
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
fallocate_with_keep_size_ = options . fallocate_with_keep_size ;
fallocate_with_keep_size_ = options . fallocate_with_keep_size ;
# endif
# endif
@ -575,8 +577,12 @@ class PosixMmapFile : public WritableFile {
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
virtual Status Allocate ( off_t offset , off_t len ) override {
virtual Status Allocate ( off_t offset , off_t len ) override {
TEST_KILL_RANDOM ( rocksdb_kill_odds ) ;
TEST_KILL_RANDOM ( rocksdb_kill_odds ) ;
int alloc_status = fallocate (
int alloc_status = 0 ;
fd_ , fallocate_with_keep_size_ ? FALLOC_FL_KEEP_SIZE : 0 , offset , len ) ;
if ( allow_fallocate_ ) {
alloc_status =
fallocate ( fd_ , fallocate_with_keep_size_ ? FALLOC_FL_KEEP_SIZE : 0 ,
offset , len ) ;
}
if ( alloc_status = = 0 ) {
if ( alloc_status = = 0 ) {
return Status : : OK ( ) ;
return Status : : OK ( ) ;
} else {
} else {
@ -592,13 +598,17 @@ class PosixWritableFile : public WritableFile {
const std : : string filename_ ;
const std : : string filename_ ;
int fd_ ;
int fd_ ;
uint64_t filesize_ ;
uint64_t filesize_ ;
bool allow_fallocate_ ;
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
bool fallocate_with_keep_size_ ;
bool fallocate_with_keep_size_ ;
# endif
# endif
public :
public :
PosixWritableFile ( const std : : string & fname , int fd , const EnvOptions & options )
PosixWritableFile ( const std : : string & fname , int fd , const EnvOptions & options )
: filename_ ( fname ) , fd_ ( fd ) , filesize_ ( 0 ) {
: filename_ ( fname ) ,
fd_ ( fd ) ,
filesize_ ( 0 ) ,
allow_fallocate_ ( options . allow_fallocate ) {
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
fallocate_with_keep_size_ = options . fallocate_with_keep_size ;
fallocate_with_keep_size_ = options . fallocate_with_keep_size ;
# endif
# endif
@ -660,8 +670,10 @@ class PosixWritableFile : public WritableFile {
// We ignore error since failure of this operation does not affect
// We ignore error since failure of this operation does not affect
// correctness.
// correctness.
IOSTATS_TIMER_GUARD ( allocate_nanos ) ;
IOSTATS_TIMER_GUARD ( allocate_nanos ) ;
fallocate ( fd_ , FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE ,
if ( allow_fallocate_ ) {
filesize_ , block_size * last_allocated_block - filesize_ ) ;
fallocate ( fd_ , FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE , filesize_ ,
block_size * last_allocated_block - filesize_ ) ;
}
# endif
# endif
}
}
@ -714,9 +726,12 @@ class PosixWritableFile : public WritableFile {
virtual Status Allocate ( off_t offset , off_t len ) override {
virtual Status Allocate ( off_t offset , off_t len ) override {
TEST_KILL_RANDOM ( rocksdb_kill_odds ) ;
TEST_KILL_RANDOM ( rocksdb_kill_odds ) ;
IOSTATS_TIMER_GUARD ( allocate_nanos ) ;
IOSTATS_TIMER_GUARD ( allocate_nanos ) ;
int alloc_status ;
int alloc_status = 0 ;
alloc_status = fallocate (
if ( allow_fallocate_ ) {
fd_ , fallocate_with_keep_size_ ? FALLOC_FL_KEEP_SIZE : 0 , offset , len ) ;
alloc_status =
fallocate ( fd_ , fallocate_with_keep_size_ ? FALLOC_FL_KEEP_SIZE : 0 ,
offset , len ) ;
}
if ( alloc_status = = 0 ) {
if ( alloc_status = = 0 ) {
return Status : : OK ( ) ;
return Status : : OK ( ) ;
} else {
} else {
@ -1146,7 +1161,7 @@ class PosixEnv : public Env {
} else {
} else {
int fd = fileno ( f ) ;
int fd = fileno ( f ) ;
# ifdef ROCKSDB_FALLOCATE_PRESENT
# ifdef ROCKSDB_FALLOCATE_PRESENT
fallocate ( fd , FALLOC_FL_KEEP_SIZE , 0 , 4 * 1024 * 1024 ) ;
fallocate ( fd , FALLOC_FL_KEEP_SIZE , 0 , 4 * 1024 ) ;
# endif
# endif
SetFD_CLOEXEC ( fd , nullptr ) ;
SetFD_CLOEXEC ( fd , nullptr ) ;
result - > reset ( new PosixLogger ( f , & PosixEnv : : gettid , this ) ) ;
result - > reset ( new PosixLogger ( f , & PosixEnv : : gettid , this ) ) ;
@ -1609,10 +1624,11 @@ class PosixEnv : public Env {
} ;
} ;
PosixEnv : : PosixEnv ( ) : checkedDiskForMmap_ ( false ) ,
PosixEnv : : PosixEnv ( )
forceMmapOff ( false ) ,
: checkedDiskForMmap_ ( false ) ,
page_size_ ( getpagesize ( ) ) ,
forceMmapOff ( false ) ,
thread_pools_ ( Priority : : TOTAL ) {
page_size_ ( getpagesize ( ) ) ,
thread_pools_ ( Priority : : TOTAL ) {
PthreadCall ( " mutex_init " , pthread_mutex_init ( & mu_ , nullptr ) ) ;
PthreadCall ( " mutex_init " , pthread_mutex_init ( & mu_ , nullptr ) ) ;
for ( int pool_id = 0 ; pool_id < Env : : Priority : : TOTAL ; + + pool_id ) {
for ( int pool_id = 0 ; pool_id < Env : : Priority : : TOTAL ; + + pool_id ) {
thread_pools_ [ pool_id ] . SetThreadPriority (
thread_pools_ [ pool_id ] . SetThreadPriority (