diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index bad58b0470..558198883c 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -2,7 +2,6 @@ #define XRPL_BASICS_TAGGEDCACHE_IPP_INCLUDED #include -#include #include namespace ripple { @@ -327,8 +326,6 @@ TaggedCache< std::chrono::steady_clock::now() - start) .count() << "ms"; - - mallocTrim(std::optional(m_name), m_journal); } template < diff --git a/src/libxrpl/basics/MallocTrim.cpp b/src/libxrpl/basics/MallocTrim.cpp index b2d2303f22..aee036863f 100644 --- a/src/libxrpl/basics/MallocTrim.cpp +++ b/src/libxrpl/basics/MallocTrim.cpp @@ -3,27 +3,20 @@ #include -#include -#include #include #include #if defined(__GLIBC__) && BOOST_OS_LINUX #include #include + +namespace { +pid_t const cachedPid = ::getpid(); +} // namespace #endif namespace ripple { -namespace { -#if defined(__GLIBC__) && BOOST_OS_LINUX -std::atomic isTrimming{false}; -std::atomic lastTrimTimeMs{0}; -constexpr int64_t minTrimIntervalMs = 5000; // TODO: derive from somewhere -pid_t const cachedPid = ::getpid(); -#endif -} // namespace - namespace detail { #if defined(__GLIBC__) && BOOST_OS_LINUX @@ -73,38 +66,6 @@ mallocTrim( report.supported = true; - auto nowMs = std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()) - .count(); - - if (nowMs - lastTrimTimeMs.load(std::memory_order_relaxed) < - minTrimIntervalMs) - { - JLOG(journal.debug()) << "malloc_trim skipped - rate limited"; - return report; - } - - bool expected = false; - if (!isTrimming.compare_exchange_strong( - expected, true, std::memory_order_acquire)) - { - JLOG(journal.debug()) << "malloc_trim skipped - already in progress"; - return report; - } - - nowMs = std::chrono::duration_cast( - std::chrono::steady_clock::now().time_since_epoch()) - .count(); - - if (nowMs - lastTrimTimeMs.load(std::memory_order_relaxed) < - minTrimIntervalMs) - { - isTrimming.store(false, std::memory_order_release); - JLOG(journal.debug()) - << "malloc_trim skipped - rate limited (double check)"; - return report; - } - if (journal.debug()) { std::string const tagStr = tag.value_or("default"); @@ -130,9 +91,6 @@ mallocTrim( report.trimResult = ::malloc_trim(0); } - lastTrimTimeMs.store(nowMs, std::memory_order_relaxed); - isTrimming.store(false, std::memory_order_release); - return report; #endif } diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 2ba6630945..1b6886ae32 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -1106,6 +1107,8 @@ public: << "; size after: " << cachedSLEs_.size(); } + mallocTrim(std::optional("doSweep"), m_journal); + // Set timer to do another sweep later. setSweepTimer(); } diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index d771145540..ed45b0adb9 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -545,6 +546,8 @@ SHAMapStoreImp::clearCaches(LedgerIndex validatedSeq) { ledgerMaster_->clearLedgerCachePrior(validatedSeq); fullBelowCache_->clear(); + + mallocTrim(std::optional("clearCaches"), journal_); } void @@ -610,6 +613,8 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated) }); if (healthWait() == stopping) return; + + mallocTrim(std::optional("clearPrior"), journal_); } SHAMapStoreImp::HealthResult