efficient call from doSweep and online delete

This commit is contained in:
Valentin Balaschenko
2025-11-11 16:53:02 +00:00
parent a1ed175b66
commit 72b34e6615
4 changed files with 12 additions and 49 deletions

View File

@@ -2,7 +2,6 @@
#define XRPL_BASICS_TAGGEDCACHE_IPP_INCLUDED
#include <xrpl/basics/IntrusivePointer.ipp>
#include <xrpl/basics/MallocTrim.h>
#include <xrpl/basics/TaggedCache.h>
namespace ripple {
@@ -327,8 +326,6 @@ TaggedCache<
std::chrono::steady_clock::now() - start)
.count()
<< "ms";
mallocTrim(std::optional<std::string>(m_name), m_journal);
}
template <

View File

@@ -3,27 +3,20 @@
#include <boost/predef.h>
#include <atomic>
#include <chrono>
#include <cstdio>
#include <fstream>
#if defined(__GLIBC__) && BOOST_OS_LINUX
#include <malloc.h>
#include <unistd.h>
namespace {
pid_t const cachedPid = ::getpid();
} // namespace
#endif
namespace ripple {
namespace {
#if defined(__GLIBC__) && BOOST_OS_LINUX
std::atomic<bool> isTrimming{false};
std::atomic<int64_t> 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::milliseconds>(
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::milliseconds>(
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
}

View File

@@ -37,6 +37,7 @@
#include <xrpld/shamap/NodeFamily.h>
#include <xrpl/basics/ByteUtilities.h>
#include <xrpl/basics/MallocTrim.h>
#include <xrpl/basics/ResolverAsio.h>
#include <xrpl/basics/random.h>
#include <xrpl/beast/asio/io_latency_probe.h>
@@ -1106,6 +1107,8 @@ public:
<< "; size after: " << cachedSLEs_.size();
}
mallocTrim(std::optional<std::string>("doSweep"), m_journal);
// Set timer to do another sweep later.
setSweepTimer();
}

View File

@@ -5,6 +5,7 @@
#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
#include <xrpld/core/ConfigSections.h>
#include <xrpl/basics/MallocTrim.h>
#include <xrpl/beast/core/CurrentThreadName.h>
#include <xrpl/nodestore/Scheduler.h>
#include <xrpl/nodestore/detail/DatabaseRotatingImp.h>
@@ -545,6 +546,8 @@ SHAMapStoreImp::clearCaches(LedgerIndex validatedSeq)
{
ledgerMaster_->clearLedgerCachePrior(validatedSeq);
fullBelowCache_->clear();
mallocTrim(std::optional<std::string>("clearCaches"), journal_);
}
void
@@ -610,6 +613,8 @@ SHAMapStoreImp::clearPrior(LedgerIndex lastRotated)
});
if (healthWait() == stopping)
return;
mallocTrim(std::optional<std::string>("clearPrior"), journal_);
}
SHAMapStoreImp::HealthResult