mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:24:13 +08:00
mdbx: add & use floor_powerof2().
Change-Id: Ib5be7d5a68dc7944e208d75094050383ccdfa6d0
This commit is contained in:
parent
a846fb0d21
commit
bf0cff9a8a
@ -5349,7 +5349,7 @@ __hot static void mdbx_page_copy(MDBX_page *dst, MDBX_page *src, size_t psize) {
|
||||
* alignment so memcpy may copy words instead of bytes. */
|
||||
if (unused >= MDBX_CACHELINE_SIZE * 2) {
|
||||
lower = ceil_powerof2(lower + PAGEHDRSZ, sizeof(void *));
|
||||
upper = (upper + PAGEHDRSZ) & ~(sizeof(void *) - 1);
|
||||
upper = floor_powerof2(upper + PAGEHDRSZ, sizeof(void *));
|
||||
memcpy(dst, src, lower);
|
||||
dst = (void *)((char *)dst + upper);
|
||||
src = (void *)((char *)src + upper);
|
||||
@ -8478,7 +8478,8 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
||||
mdbx_assert(env, ((flags ^ env->me_flags) & MDBX_WRITEMAP) == 0);
|
||||
MDBX_meta *const recent_steady_meta = mdbx_meta_steady(env);
|
||||
if (flags & MDBX_WRITEMAP) {
|
||||
const size_t begin = pgno2bytes(env, NUM_METAS) & ~(env->me_os_psize - 1);
|
||||
const size_t begin =
|
||||
floor_powerof2(pgno2bytes(env, NUM_METAS), env->me_os_psize);
|
||||
const size_t end = pgno_align2os_bytes(env, pending->mm_geo.next);
|
||||
if (end > begin) {
|
||||
rc = mdbx_msync(&env->me_dxb_mmap, begin, end - begin,
|
||||
@ -9430,7 +9431,7 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
|
||||
head->mm_datasync_sign = MDBX_DATASIGN_WEAK;
|
||||
head->mm_txnid_b.inconsistent = undo_txnid;
|
||||
const size_t offset = (uint8_t *)data_page(head) - env->me_dxb_mmap.dxb;
|
||||
const size_t paged_offset = offset & ~(env->me_os_psize - 1);
|
||||
const size_t paged_offset = floor_powerof2(offset, env->me_os_psize);
|
||||
const size_t paged_length = ceil_powerof2(
|
||||
env->me_psize + offset - paged_offset, env->me_os_psize);
|
||||
err = mdbx_msync(&env->me_dxb_mmap, paged_offset, paged_length, false);
|
||||
|
@ -1325,7 +1325,12 @@ is_powerof2(size_t x) {
|
||||
}
|
||||
|
||||
static __pure_function __always_inline __maybe_unused size_t
|
||||
ceil_powerof2(size_t value, size_t granularity) {
|
||||
floor_powerof2(size_t value, size_t granularity) {
|
||||
assert(is_powerof2(granularity));
|
||||
return (value + granularity - 1) & ~(granularity - 1);
|
||||
return value & ~(granularity - 1);
|
||||
}
|
||||
|
||||
static __pure_function __always_inline __maybe_unused size_t
|
||||
ceil_powerof2(size_t value, size_t granularity) {
|
||||
return floor_powerof2(value + granularity - 1, granularity);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user