Backport(v1.19): supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files (#5469) - #5472
Merged
Merged
Conversation
…of lock files (#5469) **Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: `cleanup_lock_dir` collects all lock file paths with `Dir.glob` at shutdown, which materializes the whole path list in memory. With that many files, the `Dir.glob` array causes a multi-GB memory spike during shutdown, which increases the risk of hitting systemd's `TimeoutStopSec` and getting SIGKILLed in the middle of cleanup. This PR switches to `Dir.each_child` to stream directory entries one by one. Measurement (removing 1,000,000 lock files, RSS): | | RSS growth | elapsed | |----------------|-----------:|--------:| | `Dir.glob` | 884.5 MiB | 26.0 s | | `Dir.each_child` | 1.8 MiB | 25.4 s | **Docs Changes**: N/A **Release Note**: * supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files --------- Signed-off-by: Shizuo Fujita <fujita@clear-code.com> Co-authored-by: Kentaro Hayashi <kenhys@gmail.com>
kenhys
approved these changes
Aug 17, 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:
Backport #5469
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: