Skip to content

Backport(v1.19): supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files (#5469) - #5472

Merged
kenhys merged 1 commit into
v1.19from
backport-pr5469
Aug 17, 2026
Merged

Backport(v1.19): supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files (#5469)#5472
kenhys merged 1 commit into
v1.19from
backport-pr5469

Conversation

@Watson1978

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
Backport #5469
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

…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>
@Watson1978 Watson1978 changed the title supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files (#5469) Backport(v1.19): supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files (#5469) Aug 17, 2026
@Watson1978 Watson1978 added this to the v1.19.4 milestone Aug 17, 2026
@Watson1978
Watson1978 requested a review from kenhys August 17, 2026 00:39
@kenhys
kenhys merged commit 8ff5d3b into v1.19 Aug 17, 2026
20 of 22 checks passed
@kenhys
kenhys deleted the backport-pr5469 branch August 17, 2026 06:38
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