From 3ba5bebec4f4ac8e8f239db1c7db666ea838e838 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 23 Jul 2017 15:48:34 +0300 Subject: [PATCH] mdbx: refine mdbx_txl_alloc(). Change-Id: I624a92c8a845ab563f13619b3638227d012a780b --- src/mdbx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index ac12cec6..134ee36a 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -176,10 +176,14 @@ static MDBX_IDL mdbx_midl_alloc(size_t size) { return ids; } -static MDBX_TXL mdbx_txl_alloc(size_t size) { - MDBX_TXL ptr = malloc((size + 2) * sizeof(txnid_t)); +static MDBX_TXL mdbx_txl_alloc(void) { + const size_t malloc_overhead = sizeof(void *) * 2; + const size_t bytes = mdbx_roundup2(malloc_overhead + sizeof(txnid_t) * 61, + MDBX_CACHELINE_SIZE) - + malloc_overhead; + MDBX_TXL ptr = malloc(bytes); if (likely(ptr)) { - *ptr++ = size; + *ptr++ = bytes / sizeof(txnid_t) - 2; *ptr = 0; } return ptr; @@ -1774,7 +1778,7 @@ static int mdbx_page_alloc(MDBX_cursor *mc, unsigned num, MDBX_page **mp, goto fail; if ((flags & MDBX_LIFORECLAIM) && !txn->mt_lifo_reclaimed) { - txn->mt_lifo_reclaimed = mdbx_txl_alloc(env->me_maxfree_1pg); + txn->mt_lifo_reclaimed = mdbx_txl_alloc(); if (unlikely(!txn->mt_lifo_reclaimed)) { rc = MDBX_ENOMEM; goto fail; @@ -3045,7 +3049,7 @@ again: } if (unlikely(!txn->mt_lifo_reclaimed)) { - txn->mt_lifo_reclaimed = mdbx_txl_alloc(env->me_maxfree_1pg); + txn->mt_lifo_reclaimed = mdbx_txl_alloc(); if (unlikely(!txn->mt_lifo_reclaimed)) { rc = MDBX_ENOMEM; goto bailout;