@ -364,34 +364,24 @@ dsm_impl_posix_resize(int fd, off_t size)
*/
*/
PG_SETMASK ( & BlockSig ) ;
PG_SETMASK ( & BlockSig ) ;
/* Truncate (or extend) the file to the requested size. */
pgstat_report_wait_start ( WAIT_EVENT_DSM_FILL_ZERO_WRITE ) ;
do
# if defined(HAVE_POSIX_FALLOCATE) && defined(__linux__)
{
rc = ftruncate ( fd , size ) ;
} while ( rc < 0 & & errno = = EINTR ) ;
/*
/*
* On Linux , a shm_open fd is backed by a tmpfs file . After resizing with
* On Linux , a shm_open fd is backed by a tmpfs file . If we were to use
* ftruncate , the file may contain a hole . Accessing memory backed by a
* ftruncate , the file would contain a hole . Accessing memory backed by a
* hole causes tmpfs to allocate pages , which fails with SIGBUS if there
* hole causes tmpfs to allocate pages , which fails with SIGBUS if there
* is no more tmpfs space available . So we ask tmpfs to allocate pages
* is no more tmpfs space available . So we ask tmpfs to allocate pages
* here , so we can fail gracefully with ENOSPC now rather than risking
* here , so we can fail gracefully with ENOSPC now rather than risking
* SIGBUS later .
* SIGBUS later .
*/
*
# if defined(HAVE_POSIX_FALLOCATE) && defined(__linux__)
if ( rc = = 0 )
{
/*
* We still use a traditional EINTR retry loop to handle SIGCONT .
* We still use a traditional EINTR retry loop to handle SIGCONT .
* posix_fallocate ( ) doesn ' t restart automatically , and we don ' t want
* posix_fallocate ( ) doesn ' t restart automatically , and we don ' t want
* this to fail if you attach a debugger .
* this to fail if you attach a debugger .
*/
*/
pgstat_report_wait_start ( WAIT_EVENT_DSM_FILL_ZERO_WRITE ) ;
do
do
{
{
rc = posix_fallocate ( fd , 0 , size ) ;
rc = posix_fallocate ( fd , 0 , size ) ;
} while ( rc = = EINTR ) ;
} while ( rc = = EINTR ) ;
pgstat_report_wait_end ( ) ;
/*
/*
* The caller expects errno to be set , but posix_fallocate ( ) doesn ' t
* The caller expects errno to be set , but posix_fallocate ( ) doesn ' t
@ -399,8 +389,14 @@ dsm_impl_posix_resize(int fd, off_t size)
* even though we ' ll also return rc to indicate success or failure .
* even though we ' ll also return rc to indicate success or failure .
*/
*/
errno = rc ;
errno = rc ;
}
# else
# endif /* HAVE_POSIX_FALLOCATE && __linux__ */
/* Extend the file to the requested size. */
do
{
rc = ftruncate ( fd , size ) ;
} while ( rc < 0 & & errno = = EINTR ) ;
# endif
pgstat_report_wait_end ( ) ;
save_errno = errno ;
save_errno = errno ;
PG_SETMASK ( & UnBlockSig ) ;
PG_SETMASK ( & UnBlockSig ) ;