mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 02:54:13 +08:00
mdbx: use POSIX_MADV_DONTNEED
.
Change-Id: I2020eb8ec225a49331cf4dc6c5a24d6559916284
This commit is contained in:
parent
b3b6a48797
commit
7a0d6c6196
11
src/core.c
11
src/core.c
@ -10255,7 +10255,8 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
||||
pgno2bytes(env, edge - largest_pgno));
|
||||
}
|
||||
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
|
||||
#if MDBX_ENABLE_MADVISE && defined(MADV_DONTNEED)
|
||||
#if MDBX_ENABLE_MADVISE && \
|
||||
(defined(MADV_DONTNEED) || defined(POSIX_MADV_DONTNEED))
|
||||
const size_t largest_bytes = pgno2bytes(env, largest_pgno);
|
||||
/* threshold to avoid unreasonable frequent madvise() calls */
|
||||
const size_t madvise_threshold = mdbx_madvise_threshold(env, largest_bytes);
|
||||
@ -10275,6 +10276,7 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
||||
const size_t prev_discarded_bytes =
|
||||
ceil_powerof2(pgno2bytes(env, prev_discarded_pgno), env->me_os_psize);
|
||||
mdbx_ensure(env, prev_discarded_bytes > discard_edge_bytes);
|
||||
#if defined(MADV_DONTNEED)
|
||||
int advise = MADV_DONTNEED;
|
||||
#if defined(MADV_FREE) && \
|
||||
0 /* MADV_FREE works for only anonymous vma at the moment */
|
||||
@ -10286,10 +10288,15 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
||||
prev_discarded_bytes - discard_edge_bytes, advise)
|
||||
? ignore_enosys(errno)
|
||||
: MDBX_SUCCESS;
|
||||
#else
|
||||
int err = ignore_enosys(posix_madvise(
|
||||
env->me_map + discard_edge_bytes,
|
||||
prev_discarded_bytes - discard_edge_bytes, POSIX_MADV_DONTNEED));
|
||||
#endif
|
||||
if (unlikely(MDBX_IS_ERROR(err)))
|
||||
return err;
|
||||
}
|
||||
#endif /* MDBX_ENABLE_MADVISE && MADV_DONTNEED */
|
||||
#endif /* MDBX_ENABLE_MADVISE && (MADV_DONTNEED || POSIX_MADV_DONTNEED) */
|
||||
|
||||
/* LY: check conditions to shrink datafile */
|
||||
const pgno_t backlog_gap = 3 + pending->mm_dbs[FREE_DBI].md_depth * 3;
|
||||
|
Loading…
x
Reference in New Issue
Block a user