Conversation
…ed-subtrees # Conflicts: # src/libxrpl/shamap/SHAMap.cpp # src/tests/libxrpl/shamap/SHAMap.cpp # src/xrpld/rpc/handlers/Handlers.h
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
High Level Overview of Change
A
SHAMapInnerNodeholds a strong pointer to every child that has been read into memory. On a backed immutable map there is no way to release those pointers, so the state map of a validated ledger keeps every node any reader has ever loaded for as long as the ledger is retained. On our perf network that resident tree, not theTreeNodeCache, is the term that grows with account count: about 13 million live nodes at 10 million accounts.This adds the reverse operation.
SHAMap::shedCold(minDepth)walks the resident tree of a backed immutable map and drops the child pointers of clean inner nodes at or belowminDepth, keeping the child hashes, sodescendreads a dropped node back from the NodeStore the next time a traversal needs it. The sweep calls it on the validated ledger's state map when[shed_cold_subtrees]is on. Default off.SHAMapInnerNode::dropChild(branch)resets the child pointer under the branch spinlock and leaves the hash array andisBranch_untouched, which is the state a freshly faulted inner node starts in.compare,belowHelper,visitDifferences,getMissingNodesandgetNodeFatwalk with bareSHAMapTreeNodepointers. Each now takes a shared lock on a process-wideshared_mutexwhile shedding is enabled, andshedColdtakes it exclusively. With the gate off the guard is one relaxed atomic load and no lock. The mutex is process-wide because immutable snapshots of one ledger are distinctSHAMapobjects sharing the same physical nodes, so a per-object lock would not cover a reader on another snapshot.cowid() == 0) are shed, since a dirty node's subtree may not be on disk yet. The root is never dropped. The sweep only sheds the ledger returned bygetValidatedLedger(), so the open and current ledgers are never touched.[shed_cold_subtrees](default false) and[shed_min_depth](default 3) are documented incfg/xrpld-example.cfg.shed {enable, run, min_depth}sets the gate at runtime and runs one pass, returning the dropped count and theTreeNodeCachesize and track counts before and after. A pass runs only if the gate was already on before the request: a descent that started with the gate off holds no lock, so enabling and shedding in one call could free a node under it.Context of Change
This is the follow-up to the tree cache work in #7965 and #7966.
memory_limitbounds the caches and removes the OOM cliff, but the memory versus accounts slope is the resident state tree, and no cache bound reaches it. This is the mechanism for that slope.It is a draft so it can be composed into the perf network image and measured before anything about it is called a result. The run should record, at the same account count with the gate on and off: resident memory,
treenode_track_size,shedColdpass duration (readers holding the guard are excluded while it runs, and a pass waits for in-flight guarded walks), and read latency after a pass. That run picks the default forshed_min_depth.API Impact
libxrplchange (any change that may affectlibxrplor dependents oflibxrpl)The new
shedcommand is admin only.SHAMapgainsshedCold,setShedEnabledandshedEnabled;SHAMapInnerNodegainsdropChild. No existing signature changes. develop is at 3.4.0-rc1 and this is not a 3.4.0 change, so the API-CHANGELOG entry follows once the target release is set.Test Plan
SHAMapShed.shed_cold_is_transparent(gtest): 3000 items into a backed map,flushDirty,setImmutable,shedCold(1)drops more than zero pointers, theTreeNodeCacheis cleared so re-reads must go to the NodeStore, then every sampled item reads back byte identical and the map hash is unchanged.On this branch merged with develop, Debug, macOS:
xrpl_tests --gtest_filter='SHAMap*'16 tests passed;xrpl.app.SHAMapStore12 cases, 965 tests, 0 failures;xrpl.rpc.RPCCall3 cases, 2085 tests, 0 failures;xrpl.rpc.LedgerData5548 tests, 0 failures. Pre-commit clean over every changed file.The behavioral proof is the perf network run described above. No measurement is claimed here.