mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:54:13 +08:00
mdbx: fix ceiling/flooring madvise-edge inside mdbx_sync_locked().
Fixes https://github.com/erthink/libmdbx/issues/91 Change-Id: I17da72d9a53a2c7453d81488bd3297063de0b7d1
This commit is contained in:
parent
94e58d7acc
commit
921f43da6f
@ -8403,27 +8403,26 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
|||||||
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
|
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
|
||||||
#if defined(MADV_DONTNEED)
|
#if defined(MADV_DONTNEED)
|
||||||
const size_t largest_bytes = pgno2bytes(env, largest_pgno);
|
const size_t largest_bytes = pgno2bytes(env, largest_pgno);
|
||||||
const size_t madvise_gap = (largest_bytes < 65536 * 256)
|
/* threshold to avoid unreasonable frequent madvise() calls */
|
||||||
? 65536
|
const size_t madvise_treshold = (largest_bytes < 65536 * 256)
|
||||||
: (largest_bytes > MEGABYTE * 4 * 256)
|
? 65536
|
||||||
? MEGABYTE * 4
|
: (largest_bytes > MEGABYTE * 4 * 256)
|
||||||
: largest_bytes >> 8;
|
? MEGABYTE * 4
|
||||||
|
: largest_bytes >> 10;
|
||||||
const size_t discard_edge_bytes = bytes_align2os_bytes(
|
const size_t discard_edge_bytes = bytes_align2os_bytes(
|
||||||
env,
|
env, ((MDBX_RDONLY &
|
||||||
(MDBX_RDONLY & (env->me_lck ? env->me_lck->mti_envmode : env->me_flags))
|
(env->me_lck ? env->me_lck->mti_envmode : env->me_flags))
|
||||||
? largest_bytes
|
? largest_bytes
|
||||||
: largest_bytes + madvise_gap);
|
: largest_bytes + madvise_treshold));
|
||||||
const pgno_t discard_edge_pgno = bytes2pgno(env, discard_edge_bytes);
|
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 >=
|
||||||
discard_edge_pgno +
|
discard_edge_pgno + bytes2pgno(env, madvise_treshold)) {
|
||||||
/* threshold to avoid unreasonable frequent madvise() calls */
|
|
||||||
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 = discard_edge_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);
|
ceil_powerof2(pgno2bytes(env, prev_discarded_pgno), env->me_os_psize);
|
||||||
mdbx_ensure(env, prev_discarded_bytes > discard_edge_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) && \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user