Skip to content

supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files - #5469

Merged
kenhys merged 2 commits into
fluent:masterfrom
Watson1978:improve-cleanup-lock-dir-memory
Aug 13, 2026
Merged

supervisor: reduce memory usage of cleanup_lock_dir with huge number of lock files#5469
kenhys merged 2 commits into
fluent:masterfrom
Watson1978:improve-cleanup-lock-dir-memory

Conversation

@Watson1978

@Watson1978 Watson1978 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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

…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>
@Watson1978
Watson1978 requested a review from kenhys August 12, 2026 08:58
@Watson1978 Watson1978 added this to the v1.20.0 milestone Aug 12, 2026
@Watson1978 Watson1978 added the backport to v1.19 We will backport this fix to the LTS branch label Aug 12, 2026
Comment thread lib/fluent/supervisor.rb Outdated
Co-authored-by: Kentaro Hayashi <kenhys@gmail.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978
Watson1978 force-pushed the improve-cleanup-lock-dir-memory branch from 7cc99e5 to 0e5010e Compare August 13, 2026 03:13
@Watson1978
Watson1978 requested a review from kenhys August 13, 2026 03:14
@kenhys
kenhys merged commit 8d9987f into fluent:master Aug 13, 2026
19 of 20 checks passed
@Watson1978
Watson1978 deleted the improve-cleanup-lock-dir-memory branch August 13, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport to v1.19 We will backport this fix to the LTS branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants