Skip to content

Fix excessive reads of /proc/mounts - #620

Open
jenxie wants to merge 1 commit into
OpenVoxProject:mainfrom
jenxie:fix-excessive-reads
Open

Fix excessive reads of /proc/mounts#620
jenxie wants to merge 1 commit into
OpenVoxProject:mainfrom
jenxie:fix-excessive-reads

Conversation

@jenxie

@jenxie jenxie commented Aug 21, 2026

Copy link
Copy Markdown

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:

Signed-off-by: jenxie <32846807+jenxie@users.noreply.github.com>
Co-authored-by: Gemini <noreply@google.com>
@jenxie

jenxie commented Aug 21, 2026

Copy link
Copy Markdown
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Excessive reads of /proc/mounts

2 participants