diff --git a/src/api-env.c b/src/api-env.c index 852d3394..4aa7bd2e 100644 --- a/src/api-env.c +++ b/src/api-env.c @@ -530,12 +530,7 @@ __cold int mdbx_env_openW(MDBX_env *env, const wchar_t *pathname, base + bitmap_bytes + env->max_dbi * (sizeof(txn->dbs[0]) + sizeof(txn->cursors[0]) + sizeof(txn->dbi_seqs[0]) + sizeof(txn->dbi_state[0])); - rc = env_page_auxbuffer(env); - if (unlikely(rc != MDBX_SUCCESS)) - goto bailout; - memset(env->page_auxbuf, -1, env->ps * (size_t)2); - memset(ptr_disp(env->page_auxbuf, env->ps * (size_t)2), 0, env->ps); txn = osal_calloc(1, size); if (unlikely(!txn)) { rc = MDBX_ENOMEM; diff --git a/src/dxb.c b/src/dxb.c index 401115d9..c91880fe 100644 --- a/src/dxb.c +++ b/src/dxb.c @@ -641,6 +641,12 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc, if (env->ps != header.pagesize) env_setup_pagesize(env, header.pagesize); + if ((env->flags & MDBX_RDONLY) == 0) { + err = env_page_auxbuffer(env); + if (unlikely(err != MDBX_SUCCESS)) + return err; + } + const size_t used_bytes = pgno2bytes(env, header.geometry.first_unallocated); const size_t used_aligned2os_bytes = ceil_powerof2(used_bytes, globals.sys_pagesize); diff --git a/src/env.c b/src/env.c index 2d5dadc5..c4902765 100644 --- a/src/env.c +++ b/src/env.c @@ -10,10 +10,16 @@ bool env_txn0_owned(const MDBX_env *env) { } int env_page_auxbuffer(MDBX_env *env) { - return env->page_auxbuf ? MDBX_SUCCESS - : osal_memalign_alloc(globals.sys_pagesize, - env->ps * (size_t)NUM_METAS, - &env->page_auxbuf); + const int err = + env->page_auxbuf + ? MDBX_SUCCESS + : osal_memalign_alloc(globals.sys_pagesize, + env->ps * (size_t)NUM_METAS, &env->page_auxbuf); + if (likely(err == MDBX_SUCCESS)) { + memset(env->page_auxbuf, -1, env->ps * (size_t)2); + memset(ptr_disp(env->page_auxbuf, env->ps * (size_t)2), 0, env->ps); + } + return err; } __cold unsigned env_setup_pagesize(MDBX_env *env, const size_t pagesize) { @@ -22,11 +28,8 @@ __cold unsigned env_setup_pagesize(MDBX_env *env, const size_t pagesize) { ENSURE(env, is_powerof2(pagesize)); ENSURE(env, pagesize >= MDBX_MIN_PAGESIZE); ENSURE(env, pagesize <= MDBX_MAX_PAGESIZE); + ENSURE(env, !env->page_auxbuf && env->ps != pagesize); env->ps = (unsigned)pagesize; - if (env->page_auxbuf) { - osal_memalign_free(env->page_auxbuf); - env->page_auxbuf = nullptr; - } STATIC_ASSERT(MAX_GC1OVPAGE(MDBX_MIN_PAGESIZE) > 4); STATIC_ASSERT(MAX_GC1OVPAGE(MDBX_MAX_PAGESIZE) < PAGELIST_LIMIT); diff --git a/src/meta.c b/src/meta.c index ee2a5aef..7214335b 100644 --- a/src/meta.c +++ b/src/meta.c @@ -392,9 +392,6 @@ __cold meta_t *meta_init_triplet(const MDBX_env *env, void *buffer) { __cold int __must_check_result meta_override(MDBX_env *env, size_t target, txnid_t txnid, const meta_t *shape) { - int rc = env_page_auxbuffer(env); - if (unlikely(rc != MDBX_SUCCESS)) - return rc; page_t *const page = env->page_auxbuf; meta_model(env, page, target, &((target == 0 && shape) ? shape : METAPAGE(env, 0))->dxbid); @@ -440,7 +437,7 @@ __cold int __must_check_result meta_override(MDBX_env *env, size_t target, } meta_sign_as_steady(model); - rc = meta_validate(env, model, page, (pgno_t)target, nullptr); + int rc = meta_validate(env, model, page, (pgno_t)target, nullptr); if (unlikely(MDBX_IS_ERROR(rc))) return MDBX_PROBLEM;