Skip to content

Fix excessive reads of /proc/mounts - #620

Merged
corporate-gadfly merged 1 commit into
OpenVoxProject:mainfrom
jenxie:fix-excessive-reads
Aug 24, 2026
Merged

Fix excessive reads of /proc/mounts#620
corporate-gadfly merged 1 commit into
OpenVoxProject:mainfrom
jenxie:fix-excessive-reads

Conversation

@jenxie

@jenxie jenxie commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Short description

Optimizes read_mounts in Puppet::Util::SELinux by caching the parsed mount data using File.mtime('/proc/mounts'). This avoids reading the file thousands of times during a single catalog application.

Also includes a unit test to validate the caching behavior.

Fixes #619

Used Gemini to help debug the initial Ruby class variable state and structure the RSpec memoization test. All changes were manually verified and tested locally.

Checklist

I have:

@jenxie

jenxie commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Created a couple of file resources with:

cat test_selinux.pp
Integer[1, 1000].each |$i| {
  file { "/tmp/test_file_${i}":
    ensure => present,
  }
}

On Rocky Linux 9.8 node with SELinux enabled temporarily applied the changes locally to /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/selinux.rb , ran it with strace -e trace=open,openat,read -f puppet apply test_selinux.pp 2>&1 | grep "/proc/mounts" | wc -l

Before it resulted in 4211 and afterwards it results in 1.

@bastelfreak bastelfreak added the bug Something isn't working label Aug 21, 2026
@jenxie
jenxie force-pushed the fix-excessive-reads branch from 770ed26 to e1cfb70 Compare August 23, 2026 18:24
@jenxie

jenxie commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Fix Windows tests, confirmed working in a Windows 2025 VM with Ruby 4.0.

Comment thread spec/unit/util/selinux_spec.rb Outdated
Comment thread lib/puppet/util/selinux.rb Outdated
@corporate-gadfly
corporate-gadfly dismissed their stale review August 23, 2026 19:26

looks like I missed a commit

@jenxie
jenxie force-pushed the fix-excessive-reads branch from 3dcb0d4 to f860efa Compare August 24, 2026 17:51
@corporate-gadfly

Copy link
Copy Markdown
Contributor

@jenxie All tests are passing. Could you squash the 3 commits into a single commit? I'll try to get some more feedback in the mean time.

Signed-off-by: jenxie <32846807+jenxie@users.noreply.github.com>
Co-authored-by: Gemini <noreply@google.com>
@jenxie
jenxie force-pushed the fix-excessive-reads branch from f860efa to c9c9de6 Compare August 24, 2026 19:44
@jenxie

jenxie commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@jenxie All tests are passing. Could you squash the 3 commits into a single commit? I'll try to get some more feedback in the mean time.

Done

@corporate-gadfly
corporate-gadfly merged commit b731108 into OpenVoxProject:main Aug 24, 2026
16 checks passed
@corporate-gadfly

Copy link
Copy Markdown
Contributor

@jenxie TY for your contribution.

@corporate-gadfly corporate-gadfly added the backport 8.x backports the merged PR to the 8.x branch label Aug 24, 2026
@OpenVoxProjectBot

Copy link
Copy Markdown
Contributor

Successfully created backport PR for 8.x:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 8.x backports the merged PR to the 8.x branch bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Excessive reads of /proc/mounts

5 participants