mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 18:54:13 +08:00
mdbx: rework MADV_DONTNEED threshold.
Change-Id: I99058b96e9c54c56d37c6c963b01cf18458d37ba
This commit is contained in:
parent
f2fd2280e4
commit
53d5cb0151
@ -7465,21 +7465,29 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
|||||||
}
|
}
|
||||||
#endif /* MDBX_USE_VALGRIND */
|
#endif /* MDBX_USE_VALGRIND */
|
||||||
#if defined(MADV_DONTNEED)
|
#if defined(MADV_DONTNEED)
|
||||||
const size_t largest_aligned2os_bytes =
|
const size_t largest_bytes = pgno2bytes(env, largest_pgno);
|
||||||
pgno_align2os_bytes(env, largest_pgno);
|
const size_t madvise_gap = (largest_bytes < 65536 * 256)
|
||||||
const pgno_t largest_aligned2os_pgno =
|
? 65536
|
||||||
bytes2pgno(env, largest_aligned2os_bytes);
|
: (largest_bytes > MEGABYTE * 4 * 256)
|
||||||
|
? MEGABYTE * 4
|
||||||
|
: largest_bytes >> 8;
|
||||||
|
const size_t discard_edge_bytes = bytes_align2os_bytes(
|
||||||
|
env,
|
||||||
|
(MDBX_RDONLY & (env->me_lck ? env->me_lck->mti_envmode : env->me_flags))
|
||||||
|
? largest_bytes
|
||||||
|
: largest_bytes + madvise_gap);
|
||||||
|
const pgno_t discard_edge_pgno = bytes2pgno(env, discard_edge_bytes);
|
||||||
const pgno_t prev_discarded_pgno = *env->me_discarded_tail;
|
const pgno_t prev_discarded_pgno = *env->me_discarded_tail;
|
||||||
if (prev_discarded_pgno >
|
if (prev_discarded_pgno >
|
||||||
largest_aligned2os_pgno +
|
discard_edge_pgno +
|
||||||
/* 1M threshold to avoid unreasonable madvise() call */
|
/* threshold to avoid unreasonable frequent madvise() calls */
|
||||||
bytes2pgno(env, MEGABYTE)) {
|
bytes2pgno(env, madvise_gap)) {
|
||||||
mdbx_notice("open-MADV_%s %u..%u", "DONTNEED", *env->me_discarded_tail,
|
mdbx_notice("open-MADV_%s %u..%u", "DONTNEED", *env->me_discarded_tail,
|
||||||
largest_pgno);
|
largest_pgno);
|
||||||
*env->me_discarded_tail = largest_aligned2os_pgno;
|
*env->me_discarded_tail = discard_edge_pgno;
|
||||||
const size_t prev_discarded_bytes =
|
const size_t prev_discarded_bytes =
|
||||||
pgno2bytes(env, prev_discarded_pgno) & ~(env->me_os_psize - 1);
|
pgno2bytes(env, prev_discarded_pgno) & ~(env->me_os_psize - 1);
|
||||||
mdbx_ensure(env, prev_discarded_bytes > largest_aligned2os_bytes);
|
mdbx_ensure(env, prev_discarded_bytes > discard_edge_bytes);
|
||||||
int advise = MADV_DONTNEED;
|
int advise = MADV_DONTNEED;
|
||||||
#if defined(MADV_FREE) && \
|
#if defined(MADV_FREE) && \
|
||||||
0 /* MADV_FREE works for only anonymous vma at the moment */
|
0 /* MADV_FREE works for only anonymous vma at the moment */
|
||||||
@ -7487,8 +7495,8 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
|||||||
mdbx_linux_kernel_version > 0x04050000)
|
mdbx_linux_kernel_version > 0x04050000)
|
||||||
advise = MADV_FREE;
|
advise = MADV_FREE;
|
||||||
#endif /* MADV_FREE */
|
#endif /* MADV_FREE */
|
||||||
int err = madvise(env->me_map + largest_aligned2os_bytes,
|
int err = madvise(env->me_map + discard_edge_bytes,
|
||||||
prev_discarded_bytes - largest_aligned2os_bytes, advise)
|
prev_discarded_bytes - discard_edge_bytes, advise)
|
||||||
? ignore_enosys(errno)
|
? ignore_enosys(errno)
|
||||||
: MDBX_SUCCESS;
|
: MDBX_SUCCESS;
|
||||||
if (unlikely(MDBX_IS_ERROR(err)))
|
if (unlikely(MDBX_IS_ERROR(err)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user