|
|
@@ -10,6 +10,10 @@
|
|
|
#include <systemd/sd-daemon.h>
|
|
|
#endif
|
|
|
|
|
|
+#if defined(__GLIBC__) && !defined(__APPLE__)
|
|
|
+#include <malloc.h>
|
|
|
+#endif
|
|
|
+
|
|
|
namespace smartbotic::database {
|
|
|
|
|
|
DatabaseService::DatabaseService(Config config)
|
|
|
@@ -66,6 +70,20 @@ bool DatabaseService::initialize() {
|
|
|
// Recover from persistence
|
|
|
recovery_outcome_ = persistence_->recover(*store_);
|
|
|
|
|
|
+#if defined(__GLIBC__) && !defined(__APPLE__)
|
|
|
+ // v1.9.3 — release freelist pages accumulated during recovery. v1.9.1
|
|
|
+ // added trim at end of loadSnapshot, but the WAL replay phase that
|
|
|
+ // runs afterward (`persistence_->recover`'s `replayWal` step) also
|
|
|
+ // burns through GBs of small Document JSON allocations whose pages
|
|
|
+ // sit on the per-thread freelist with no subsequent allocation to
|
|
|
+ // shake them loose. On Zoe (BUG-memory-leak-zoe.md update 15:05)
|
|
|
+ // this was 5.7 GB at 23 min uptime — fully reclaimable via
|
|
|
+ // malloc_trim, just nothing called it. Paired with the periodic
|
|
|
+ // every-5-minute trim in MemoryStore::logMemoryCheck, so any
|
|
|
+ // post-boot bloat that escapes this trim gets cleaned up shortly.
|
|
|
+ ::malloc_trim(0);
|
|
|
+#endif
|
|
|
+
|
|
|
if (recovery_outcome_.isFailure()) {
|
|
|
const std::string modeStr =
|
|
|
recoveryModeToString(config_.persistenceConfig.recoveryMode);
|