Do time-driven purge of expired cache entries#6
Merged
Merged
Conversation
An idle mount only reclaimed expired TTL-cache entries when a later read happened to sweep them (the opportunistic sweep in dnsfs_cache_lookup) or under memory pressure. The timer callback runs in softirq context and does the I6 minimum: it sets an atomic purge_pending flag and wakes the resolver kthread, with no cache walk, allocation, or sleeping. The kthread reaps every entry whose TTL has elapsed and that is not mid-refresh, under query_lock in process context, then re-arms while entries remain. Arming happens from the cache-store paths, guarded on the kthread's existence and made idempotent via timer_pending. The sweep skips refreshing entries, and DNSFS_PURGE_INTERVAL_SEC (5s) sits above the gap between an entry's expiry and a demand read, so an entry read soon after expiry is still served stale; entries idle past the interval are reclaimed. A bounded stale window, documented at the constant. Teardown is ordered: dnsfs_free_config calls timer_shutdown_sync after kthread_stop (the only side that re-arms), so no sweep can fire or re-arm before the cache it walks is drained. timer_setup runs in dnsfs_cache_init. The softirq/process split uses an atomic flag rather than taking the process-context query_queue_lock in the timer, avoiding a lock-context inversion.
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.
An idle mount only reclaimed expired TTL-cache entries when a later read happened to sweep them (the opportunistic sweep in dnsfs_cache_lookup) or under memory pressure.
The timer callback runs in softirq context and does the I6 minimum: it sets an atomic purge_pending flag and wakes the resolver kthread, with no cache walk, allocation, or sleeping. The kthread reaps every entry whose TTL has
elapsed and that is not mid-refresh, under query_lock in process context, then re-arms while entries remain. Arming happens from the cache-store paths, guarded on the kthread's existence and made idempotent via timer_pending.
The sweep skips refreshing entries, and DNSFS_PURGE_INTERVAL_SEC (5s) sits above the gap between an entry's expiry and a demand read, so an entry read soon after expiry is still served stale; entries idle past the interval are reclaimed. A bounded stale window, documented at the constant.
Teardown is ordered: dnsfs_free_config calls timer_shutdown_sync after kthread_stop (the only side that re-arms), so no sweep can fire or re-arm before the cache it walks is drained. timer_setup runs in dnsfs_cache_init.
The softirq/process split uses an atomic flag rather than taking the process-context query_queue_lock in the timer, avoiding a lock-context inversion.
Summary by cubic
Add a time-driven purge for expired cache entries so idle mounts don’t retain dead records. This bounds staleness and reduces memory use without relying on reads or memory pressure.
purge_pendingflag in softirq and wakes the resolver thread; the kthread purges expired, non-refreshing entries under lock, then re-arms while the cache is non-empty (arming happens on store paths; idempotent viatimer_pending).DNSFS_PURGE_INTERVAL_SEC=5: reads shortly after expiry are still served stale; idle entries past the interval are reclaimed.timer_shutdown_syncruns afterkthread_stop, ensuring no purge fires while the cache is being drained.test_purge_timervalidates that an expired entry is purged without a read and that the next read incurs resolver latency (real miss).Written for commit e4835d8. Summary will update on new commits.