compute more structures in mempool DynamicMemoryUsage

This commit is contained in:
Alfredo Garcia 2020-03-21 10:50:34 -03:00
parent c3df71a8e9
commit 6f3ad1c496
2 changed files with 33 additions and 4 deletions

View File

@ -88,8 +88,8 @@ static inline size_t DynamicUsage(const std::set<X>& s)
return MallocUsage(sizeof(stl_tree_node<X>)) * s.size();
}
template<typename X, typename Y>
static inline size_t DynamicUsage(const std::map<X, Y>& m)
template<typename X, typename Y, typename C>
static inline size_t DynamicUsage(const std::map<X, Y, C>& m)
{
return MallocUsage(sizeof(stl_tree_node<std::pair<const X, Y> >)) * m.size();
}

View File

@ -790,8 +790,37 @@ bool CCoinsViewMemPool::HaveCoins(const uint256 &txid) const {
size_t CTxMemPool::DynamicMemoryUsage() const {
LOCK(cs);
// Estimate the overhead of mapTx to be 6 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 6 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + cachedInnerUsage;
size_t total = 0;
// Estimate the overhead of mapTx to be 6 pointers + an allocation, as no exact formula for
// boost::multi_index_contained is implemented.
total += memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 6 * sizeof(void*)) * mapTx.size();
// Two metadata maps inherited from Bitcoin Core
total += memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas);
// Saves iterating over the full map
total += cachedInnerUsage;
// Wallet notification
total += memusage::DynamicUsage(mapRecentlyAddedTx);
// Nullifier set tracking
total += memusage::DynamicUsage(mapSproutNullifiers) + memusage::DynamicUsage(mapSaplingNullifiers);
// DoS mitigation
total += memusage::DynamicUsage(recentlyEvicted) + memusage::DynamicUsage(weightedTxTree);
// Insight-related structures
size_t insight;
insight += memusage::DynamicUsage(mapAddress);
insight += memusage::DynamicUsage(mapAddressInserted);
insight += memusage::DynamicUsage(mapSpent);
insight += memusage::DynamicUsage(mapSpentInserted);
total += insight;
return total;
}
void CTxMemPool::SetMempoolCostLimit(int64_t totalCostLimit, int64_t evictionMemorySeconds) {