Skip to content

Don't lock eviction parent set if it's likely empty - #1047

Open
FelixMcFelix wants to merge 2 commits into
bound-evictionfrom
evict-track-parents-ll
Open

Don't lock eviction parent set if it's likely empty#1047
FelixMcFelix wants to merge 2 commits into
bound-evictionfrom
evict-track-parents-ll

Conversation

@FelixMcFelix

@FelixMcFelix FelixMcFelix commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

By keeping a counter outside of the locked children list, we can avoid the cost of acquiring a readlock when an entry has nothing which depends on it. This is most relevant for UFT and TCP flow table entries, which should never have any children, but calculating the eviction score for an LFT entry benefits indirectly since they call eviction_priority for each child.

We also use this now to identify flows which have no children, and thus can be evicted because they are ready for expiry but are not cleaned up by the periodic task yet. When this occurs we can exit the eviction candidate scan early.

@FelixMcFelix
FelixMcFelix force-pushed the evict-track-parents-ll branch 2 times, most recently from 7d21d40 to fb1e1ed Compare September 1, 2026 13:25
@FelixMcFelix
FelixMcFelix marked this pull request as ready for review September 1, 2026 13:25
@FelixMcFelix
FelixMcFelix force-pushed the evict-track-parents-ll branch from fb1e1ed to d05b491 Compare September 2, 2026 11:29
@rcgoodfellow
rcgoodfellow self-requested a review September 2, 2026 15:24

/// An estimate of the number of elements in [`Self::children`], used
/// to avoid locking and querying consistently empty elements.
n_children: AtomicUsize,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to consider wrapping n_children and children up in a struct with an interface that makes it impossible for them to get out of sync. Seems like it'd be pretty easy to update children in some future PR and forget to update n_children.

This prevents us doing meaningless work when calculating eviction
priority of a UFT/TCP entry while evaluating LFT candidates.
The use of `n_children` makes it a little quicker for us to early exit
from eviction if we come across an entry which is genuinely expired.
@FelixMcFelix
FelixMcFelix force-pushed the evict-track-parents-ll branch from cbb091a to 96682a0 Compare September 3, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants