mirror of
https://github.com/isar/libmdbx.git
synced 2025-09-14 15:02:21 +08:00
mdbx: fix unexpected SIGBUS
is not enough space in a filesystem.
On a modern Linux the allocation of space for a file can be deferred and/or lazy, rather than when setting its length using `ftruncate()`. The actual allocation of space occurs when writing to the corresponding areas of the file, or when reading ones (in this case, the file system fills these areas with zeros). The specific behavior depends on the type of file system and the kernel version, but the main thing is that possibilities currently are, when setting the file size, just the instantaneous ability to allocate space is checked, without any booking. If the file system is running out of space, an `ENOSPC` error may occur when processing (inside a OS kernel) a page fault when accessing one of the added pages after the database has been enlarged. In this case, the OS kernel has no other alternative but to send a `SIGBUS` signal to the process. This commit fixes the problem by adding the use of system calls to explicitly allocate space for a given file size. Related-to https://github.com/erigontech/erigon/issues/16709 This is a simple improvement, however which is complicated by the need to take into account the availability of the appropriate system API and handle non-fatal errors from file systems that do not support the appropriate operations. Therefore, there is a risk of regressions in unusual/rare situations, including when hosting databases on network media.
This commit is contained in:
@@ -62,9 +62,9 @@ __cold static int lck_setup_locked(MDBX_env *env) {
|
||||
}
|
||||
env->max_readers = (maxreaders <= MDBX_READERS_LIMIT) ? (unsigned)maxreaders : (unsigned)MDBX_READERS_LIMIT;
|
||||
|
||||
err =
|
||||
osal_mmap((env->flags & MDBX_EXCLUSIVE) | MDBX_WRITEMAP, &env->lck_mmap, (size_t)size, (size_t)size,
|
||||
lck_seize_rc ? MMAP_OPTION_TRUNCATE | MMAP_OPTION_SEMAPHORE : MMAP_OPTION_SEMAPHORE, env->pathname.lck);
|
||||
err = osal_mmap((env->flags & MDBX_EXCLUSIVE) | MDBX_WRITEMAP, &env->lck_mmap, (size_t)size, (size_t)size,
|
||||
lck_seize_rc ? MMAP_OPTION_SETLENGTH | MMAP_OPTION_SEMAPHORE : MMAP_OPTION_SEMAPHORE,
|
||||
env->pathname.lck);
|
||||
if (unlikely(err != MDBX_SUCCESS))
|
||||
return err;
|
||||
|
||||
|
Reference in New Issue
Block a user