From 5d02265785d3767ffb954b213ba698c3b73d5f1c Mon Sep 17 00:00:00 2001 From: bert hubert Date: Wed, 10 Apr 2019 15:20:13 +0200 Subject: [PATCH] Reduce mmap size for lmdb on 32 bits plus restrict number of shards --- modules/lmdbbackend/lmdb-safe.cc | 6 ++++-- modules/lmdbbackend/lmdbbackend.cc | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/lmdbbackend/lmdb-safe.cc b/modules/lmdbbackend/lmdb-safe.cc index eea586455b..094303f253 100644 --- a/modules/lmdbbackend/lmdb-safe.cc +++ b/modules/lmdbbackend/lmdb-safe.cc @@ -26,8 +26,10 @@ MDBDbi::MDBDbi(MDB_env* env, MDB_txn* txn, const string_view dbname, int flags) MDBEnv::MDBEnv(const char* fname, int flags, int mode) { - mdb_env_create(&d_env); - if(mdb_env_set_mapsize(d_env, 16ULL*4096*244140ULL)) // 4GB + mdb_env_create(&d_env); + uint64_t mapsizeMB = (sizeof(long)==4) ? 100 : 16000; + // on 32 bit platforms, there is just no room for more + if(mdb_env_set_mapsize(d_env, mapsizeMB * 1048576)) throw std::runtime_error("setting map size"); /* Various other options may also need to be set before opening the handle, e.g. mdb_env_set_mapsize(), mdb_env_set_maxreaders(), mdb_env_set_maxdbs(), diff --git a/modules/lmdbbackend/lmdbbackend.cc b/modules/lmdbbackend/lmdbbackend.cc index 58c61e5c17..c4a48a5388 100644 --- a/modules/lmdbbackend/lmdbbackend.cc +++ b/modules/lmdbbackend/lmdbbackend.cc @@ -1592,7 +1592,8 @@ public: { declare(suffix,"filename","Filename for lmdb","./pdns.lmdb"); declare(suffix,"sync-mode","Synchronisation mode: nosync, nometasync, mapasync","mapasync"); - declare(suffix,"shards","Records database will be split into this number of shards","64"); + // there just is no room for more on 32 bit + declare(suffix,"shards","Records database will be split into this number of shards", (sizeof(long) == 4) ? "2" : "64"); } DNSBackend *make(const string &suffix="") { -- 2.47.2