mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 18:14:14 +08:00
mdbx: refine mdbx_txl_alloc().
Change-Id: I624a92c8a845ab563f13619b3638227d012a780b
This commit is contained in:
parent
d5a8bcebbf
commit
3ba5bebec4
14
src/mdbx.c
14
src/mdbx.c
@ -176,10 +176,14 @@ static MDBX_IDL mdbx_midl_alloc(size_t size) {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MDBX_TXL mdbx_txl_alloc(size_t size) {
|
static MDBX_TXL mdbx_txl_alloc(void) {
|
||||||
MDBX_TXL ptr = malloc((size + 2) * sizeof(txnid_t));
|
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)) {
|
if (likely(ptr)) {
|
||||||
*ptr++ = size;
|
*ptr++ = bytes / sizeof(txnid_t) - 2;
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
@ -1774,7 +1778,7 @@ static int mdbx_page_alloc(MDBX_cursor *mc, unsigned num, MDBX_page **mp,
|
|||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if ((flags & MDBX_LIFORECLAIM) && !txn->mt_lifo_reclaimed) {
|
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)) {
|
if (unlikely(!txn->mt_lifo_reclaimed)) {
|
||||||
rc = MDBX_ENOMEM;
|
rc = MDBX_ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -3045,7 +3049,7 @@ again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(!txn->mt_lifo_reclaimed)) {
|
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)) {
|
if (unlikely(!txn->mt_lifo_reclaimed)) {
|
||||||
rc = MDBX_ENOMEM;
|
rc = MDBX_ENOMEM;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user