Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -44,10 +44,17 @@ ** plus implementations of sqlite3_os_init() and sqlite3_os_end(). */ #include "sqliteInt.h" #if SQLITE_OS_UNIX /* This file is used on unix only */ +/* Use posix_fallocate() if it is available +*/ +#if !defined(HAVE_POSIX_FALLOCATE) \ + && (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L) +# define HAVE_POSIX_FALLOCATE 1 +#endif + /* ** There are various methods for file locking used for concurrency ** control: ** ** 1. POSIX locking (the default), @@ -4166,15 +4173,23 @@ ** ** Alternatively, if bExtend is true, use ftruncate() to allocate ** the requested memory region. */ if( !bExtend ) goto shmpage_out; +#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE + if( osFallocate(pShmNode->h, sStat.st_size, nByte)!=0 ){ + rc = unixLogError(SQLITE_IOERR_SHMSIZE, "fallocate", + pShmNode->zFilename); + goto shmpage_out; + } +#else if( robust_ftruncate(pShmNode->h, nByte) ){ rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate", pShmNode->zFilename); goto shmpage_out; } +#endif } } /* Map the requested memory region into this processes address space. */ apNew = (char **)sqlite3_realloc( Index: test/wal9.test ================================================================== --- test/wal9.test +++ test/wal9.test @@ -60,11 +60,11 @@ # Check file sizes are as expected. The real requirement here is that # the *shm file is now more than one chunk (>32KiB). do_test 1.3 { file size test.db } {1024} do_test 1.4 { file size test.db-wal } {15421352} -do_test 1.5 { file size test.db-shm } {131072} +do_test 1.5 { expr {[file size test.db-shm]>32768} } {1} do_execsql_test 1.6 { PRAGMA wal_checkpoint } {0 14715 14715} # At this point connection [db2] has mapped the first 32KB of the *shm file # only. Because the entire WAL file has been checkpointed, it is not @@ -85,6 +85,5 @@ } db2 } {} db2 close finish_test -