This repository was archived by the owner on Apr 27, 2026. It is now read-only.
Subtract ZFS ARC size from RAM usage#1096
Merged
Merged
Conversation
Jas-SinghFSU
reviewed
Sep 2, 2025
|
|
||
| // Get ZFS ARC size, if nonzero | ||
| let arcSize = 0; | ||
| const [arcSuccess, arcstatsBytes] = GLib.file_get_contents('/proc/spl/kstat/zfs/arcstats'); |
Owner
There was a problem hiding this comment.
This will throw an exception if you don't have zfs as it won't be able to find that file - which will cause the ram calculation to fail in all cases unless zfs exists.
Most of this logic is sound, we can either:
- Wrap this in a try catch with an empty catch (a bit smelly)
- Move it out into a function and do a preliminary check to see if the path exists
I think approach 2 is cleaner so here we just do
const arcSize = this._getZfsArcSize();Then make a method down below
private _getZfsArcSize(): number {
const arcstatsPath = '/proc/spl/kstat/zfs/arcstats';
if (!GLib.file_test(arcstatsPath, GLib.FileTest.EXISTS)) {
return 0;
}
const [arcSuccess, arcstatsBytes] = GLib.file_get_contents(arcstatsPath);
if (!arcSuccess || arcstatsBytes === undefined) {
return 0;
}
const arcstats = new TextDecoder('utf-8').decode(arcstatsBytes);
const arcSizeMatch = arcstats.match(/size\s+\d\s+(\d+)/);
return arcSizeMatch ? parseInt(arcSizeMatch[1], 10) : 0;
}And we can reduce some nesting by using the early return pattern.
Also this is a bit wasteful since we're checking if the file exists on every ram calculation (every polling interval). Instead we can move hold a state int he constructor so we do that discovery on startup:
constructor() {
this._hasZfs = GLib.file_test('/proc/spl/kstat/zfs/arcstats', GLib.FileTest.EXISTS);
}Then we can just
if (!this._hasZfs) return 0;
Owner
|
Awesome, looks good with the exception of 1 linter error. |
Contributor
Author
|
Great, I fixed the linter error. Thanks a lot for your review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.