summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-12-21 02:41:45 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2022-12-21 16:13:32 -0700
commit3f88bf0926046b245844a72a2a0c97654a410f0a (patch)
treea6bdad6c5a049eb401088f012795035c3fa6242d /lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees
parentaf795797565e642a9e7fd2a962add8e8b4d5756b (diff)
rebuildnodes/btrees: Cache nodes
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go
index 28d93b9..dea7ec3 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go
@@ -85,7 +85,8 @@ type RebuiltTrees struct {
cbLookupUUID func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool)
// mutable
- trees map[btrfsprim.ObjID]*rebuiltTree
+ trees map[btrfsprim.ObjID]*rebuiltTree
+ nodeCache *containers.LRUCache[btrfsvol.LogicalAddr, *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]]
}
// NewRebuiltTrees returns a new RebuiltTrees instance. All of the
@@ -105,15 +106,21 @@ func NewRebuiltTrees(
cbLookupRoot: cbLookupRoot,
cbLookupUUID: cbLookupUUID,
- trees: make(map[btrfsprim.ObjID]*rebuiltTree),
+ trees: make(map[btrfsprim.ObjID]*rebuiltTree),
+ nodeCache: containers.NewLRUCache[btrfsvol.LogicalAddr, *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]](8),
}
}
func (ts *RebuiltTrees) readNode(laddr btrfsvol.LogicalAddr) *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node] {
+ if cached, ok := ts.nodeCache.Get(laddr); ok {
+ return cached
+ }
+
graphInfo, ok := ts.graph.Nodes[laddr]
if !ok {
panic(fmt.Errorf("should not happen: node@%v is not mentioned in the in-memory graph", laddr))
}
+
ref, err := btrfstree.ReadNode(ts.rawFile, ts.sb, laddr, btrfstree.NodeExpectations{
LAddr: containers.Optional[btrfsvol.LogicalAddr]{OK: true, Val: laddr},
Level: containers.Optional[uint8]{OK: true, Val: graphInfo.Level},
@@ -131,6 +138,9 @@ func (ts *RebuiltTrees) readNode(laddr btrfsvol.LogicalAddr) *diskio.Ref[btrfsvo
if err != nil {
panic(fmt.Errorf("should not happen: i/o error: %w", err))
}
+
+ ts.nodeCache.Add(laddr, ref)
+
return ref
}