supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files - #5469
Merged
kenhys merged 2 commits intoAug 13, 2026
Merged
Conversation
…of lock files A long-running multi-worker aggregator with /tmp aging disabled accumulated about 20 million lock files. Dir.glob materializes the whole path list at shutdown, which causes a multi-GB memory spike. Use Dir.each_child to stream directory entries instead. Removing 1,000,000 lock files grows RSS by 884.5 MB with Dir.glob but only by 1.8 MB with Dir.each_child. The elapsed time is unchanged. No behavior change. Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
kenhys
requested changes
Aug 13, 2026
Co-authored-by: Kentaro Hayashi <kenhys@gmail.com> Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Watson1978
force-pushed
the
improve-cleanup-lock-dir-memory
branch
from
August 13, 2026 03:13
7cc99e5 to
0e5010e
Compare
kenhys
approved these changes
Aug 13, 2026
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.
Which issue(s) this PR fixes:
Fixes #
What this PR does / why we need it:
cleanup_lock_dircollects all lock file paths withDir.globat shutdown, which materializes the whole path list in memory.With that many files, the
Dir.globarray causes a multi-GB memory spike during shutdown,which increases the risk of hitting systemd's
TimeoutStopSecand getting SIGKILLed in the middle of cleanup.This PR switches to
Dir.each_childto stream directory entries one by one.Measurement (removing 1,000,000 lock files, RSS):
Dir.globDir.each_childDocs Changes:
N/A
Release Note: