From 658d73951fee8df1596132e85dca36b8ba159d56 Mon Sep 17 00:00:00 2001 From: selsta Date: Wed, 22 Jul 2026 13:40:50 +0200 Subject: [PATCH] lmdb: round map sizes up to page boundaries Round requested LMDB map sizes upward to the next page boundary. This avoids producing incorrectly aligned map sizes when the requested size is not already page-aligned. --- src/blockchain_db/lmdb/db_lmdb.cpp | 4 +++- src/blockchain_utilities/blockchain_prune.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index a7a4dc336..6d386378e 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -561,7 +561,9 @@ void BlockchainLMDB::do_resize(uint64_t increase_size) if (increase_size > 0) new_mapsize = mei.me_mapsize + increase_size; - new_mapsize += (new_mapsize % mst.ms_psize); + const uint64_t remainder = new_mapsize % mst.ms_psize; + if (remainder) + new_mapsize += mst.ms_psize - remainder; mdb_txn_safe::prevent_new_txns(); diff --git a/src/blockchain_utilities/blockchain_prune.cpp b/src/blockchain_utilities/blockchain_prune.cpp index 04217c938..bc912c884 100644 --- a/src/blockchain_utilities/blockchain_prune.cpp +++ b/src/blockchain_utilities/blockchain_prune.cpp @@ -123,7 +123,9 @@ static void add_size(MDB_env *env, uint64_t bytes) mdb_env_stat(env, &mst); uint64_t new_mapsize = (uint64_t)mei.me_mapsize + bytes; - new_mapsize += (new_mapsize % mst.ms_psize); + const uint64_t remainder = new_mapsize % mst.ms_psize; + if (remainder) + new_mapsize += mst.ms_psize - remainder; int result = mdb_env_set_mapsize(env, new_mapsize); if (result)