depgraph: add memory usage control (feature)
Co-Authored-By: Lőrinc <pap.lorinc@gmail.com>
This commit is contained in:
1 parent
b1637a90de
commit
bb5cb222ae
2 files changed
+32
-11
No files matched your search
@@ -12,6 +12,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <memusage.h>
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
#include <util/feefrac.h>
|
#include <util/feefrac.h>
|
||||||
@@ -332,6 +333,17 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Reduce memory usage if possible. No observable effect. */
|
||||||
|
void Compact() noexcept
|
||||||
|
{
|
||||||
|
entries.shrink_to_fit();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t DynamicMemoryUsage() const noexcept
|
||||||
|
{
|
||||||
|
return memusage::DynamicUsage(entries);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A set of transactions together with their aggregate feerate. */
|
/** A set of transactions together with their aggregate feerate. */
|
||||||
|
|||||||
@@ -452,9 +452,13 @@ FUZZ_TARGET(clusterlin_depgraph_sim)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto last_compaction_pos{real.PositionRange()};
|
||||||
|
|
||||||
LIMITED_WHILE(provider.remaining_bytes() > 0, 1000) {
|
LIMITED_WHILE(provider.remaining_bytes() > 0, 1000) {
|
||||||
uint8_t command = provider.ConsumeIntegral<uint8_t>();
|
int command = provider.ConsumeIntegral<uint8_t>() % 4;
|
||||||
if (num_tx_sim == 0 || ((command % 3) <= 0 && num_tx_sim < TestBitSet::Size())) {
|
while (true) {
|
||||||
|
// Iterate decreasing command until an applicable branch is found.
|
||||||
|
if (num_tx_sim < TestBitSet::Size() && command-- == 0) {
|
||||||
// AddTransaction.
|
// AddTransaction.
|
||||||
auto fee = provider.ConsumeIntegralInRange<int64_t>(-0x8000000000000, 0x7ffffffffffff);
|
auto fee = provider.ConsumeIntegralInRange<int64_t>(-0x8000000000000, 0x7ffffffffffff);
|
||||||
auto size = provider.ConsumeIntegralInRange<int32_t>(1, 0x3fffff);
|
auto size = provider.ConsumeIntegralInRange<int32_t>(1, 0x3fffff);
|
||||||
@@ -472,9 +476,8 @@ FUZZ_TARGET(clusterlin_depgraph_sim)
|
|||||||
// Update sim.
|
// Update sim.
|
||||||
sim[idx] = {feerate, TestBitSet::Singleton(idx)};
|
sim[idx] = {feerate, TestBitSet::Singleton(idx)};
|
||||||
++num_tx_sim;
|
++num_tx_sim;
|
||||||
continue;
|
break;
|
||||||
}
|
} else if (num_tx_sim > 0 && command-- == 0) {
|
||||||
if ((command % 3) <= 1 && num_tx_sim > 0) {
|
|
||||||
// AddDependencies.
|
// AddDependencies.
|
||||||
DepGraphIndex child = idx_fn();
|
DepGraphIndex child = idx_fn();
|
||||||
auto parents = subset_fn();
|
auto parents = subset_fn();
|
||||||
@@ -482,9 +485,8 @@ FUZZ_TARGET(clusterlin_depgraph_sim)
|
|||||||
real.AddDependencies(parents, child);
|
real.AddDependencies(parents, child);
|
||||||
// Apply to sim.
|
// Apply to sim.
|
||||||
sim[child]->second |= parents;
|
sim[child]->second |= parents;
|
||||||
continue;
|
break;
|
||||||
}
|
} else if (num_tx_sim > 0 && command-- == 0) {
|
||||||
if (num_tx_sim > 0) {
|
|
||||||
// Remove transactions.
|
// Remove transactions.
|
||||||
auto del = set_fn();
|
auto del = set_fn();
|
||||||
// Propagate all ancestry information before deleting anything in the simulation (as
|
// Propagate all ancestry information before deleting anything in the simulation (as
|
||||||
@@ -505,10 +507,17 @@ FUZZ_TARGET(clusterlin_depgraph_sim)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
break;
|
||||||
|
} else if (command-- == 0) {
|
||||||
|
// Compact.
|
||||||
|
const size_t mem_before{real.DynamicMemoryUsage()};
|
||||||
|
real.Compact();
|
||||||
|
const size_t mem_after{real.DynamicMemoryUsage()};
|
||||||
|
assert(real.PositionRange() < last_compaction_pos ? mem_after < mem_before : mem_after <= mem_before);
|
||||||
|
last_compaction_pos = real.PositionRange();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// This should be unreachable (one of the 3 above actions should always be possible).
|
|
||||||
assert(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare the real obtained depgraph against the simulation.
|
// Compare the real obtained depgraph against the simulation.
|
||||||
|
|||||||
Reference in new issue
Block a user