Skip to content

Bug 2091167 - SizeLimit plugin parses all of /proc/self/smaps in pure Perl after every request (~3 ms per request) - #2822

Merged
dklawren merged 6 commits into
mozilla:masterfrom
dklawren:2091167
Nov 12, 2026
Merged

dklawren merged 6 commits into
mozilla:masterfrom
dklawren:2091167

Conversation

@dklawren

@dklawren dklawren commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

… Perl after every request (~3 ms per request)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the SizeLimit memory-check optimization.

No open issues 🎉

What changed in this PR

This PR reduces per-request memory-check overhead in the SizeLimit plugin by reading VmSize from /proc/self/status instead of parsing /proc/self/smaps.

Changes:

  • Replaces smaps parsing with a lightweight virtual-memory-size reader while preserving the worker shutdown threshold.
  • Removes the Linux::Smaps::Tiny dependency.
  • Adds tests for memory-size reading, threshold behavior, and unavailable measurements.
File Description
t/​app-size-limit.t Tests memory readings and worker shutdown behavior.
Makefile.PL Removes Linux::Smaps::Tiny from optional prerequisites, retaining BSD::Resource.
cpanfile Removes the Linux::Smaps::Tiny dependency.
Bugzilla/​App/​Plugin/​SizeLimit.pm Reads VmSize from proc status for per-request memory checks.

Review effort: Balanced

@dklawren
dklawren requested review from Xzzz and cgsheeh November 10, 2026 00:05
Comment thread Makefile.PL Outdated
@@ -284,11 +284,8 @@ my %optional_features = (
prereqs => {runtime => {requires => {'Linux::Pid' => 0},},},
},
linux_smaps => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this feature only pulls in BSD::Resource, should we rename linux_smaps to something like rlimit? Or is the name referenced by --with-feature somewhere outside this repo, so it's safer to keep it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to rlimit in 7ccc262. Nothing in this repo referenced linux_smaps; checksetup.pl passes features through --with-feature, so the new name is picked up automatically.

Comment thread Bugzilla/App/Plugin/SizeLimit.pm Outdated
# reads a few dozen lines instead of parsing all of /proc/self/smaps (tens of
# thousands of lines in a BMO worker) after every request. Linux::Smaps::Tiny
# 0.10 also silently fell back to its pure-Perl parser: its XS loader runs in a
# BEGIN block before $VERSION is set, so the version check always failed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Linux::Smaps::Tiny is removed entirely in this patch, could the history about its XS loader bug live in the commit message/bug instead? Something like "Virtual memory size in kB from VmSize, or undef if unavailable" seems like enough here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to the one-line comment in 7ccc262. The Linux::Smaps::Tiny XS-loader history stays in the bug and the original commit message.

dklawren and others added 2 commits November 12, 2026 10:23
Addresses review feedback: the feature now only pulls in BSD::Resource, and the
Linux::Smaps::Tiny history belongs in the bug rather than the code.
}
}

# Virtual memory size in kB from VmSize, or undef if unavailable (non-Linux).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BMO_size_limit in README.md and localconfig_size_limit in template/en/default/setup/strings.txt.pl still mention the limit as "unshared memory", while it is compared to VmSize (much larger).
Since this PR makes it explicit, maybe could they say "virtual memory size (VmSize, in kB)" instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both BMO_size_limit in README.md and localconfig_size_limit in strings.txt.pl to say "virtual memory size (VmSize, in kB)" in a80ae4b14.

@Xzzz Xzzz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks! One optional doc comment, as you want ;)

dklawren and others added 2 commits November 12, 2026 11:23
Addresses review feedback: the limit is compared to VmSize, not unshared memory.
@dklawren
dklawren merged commit 28a8b3a into mozilla:master Nov 12, 2026
7 checks passed
@dklawren
dklawren deleted the 2091167 branch November 12, 2026 16:58
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.

4 participants