Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration option for setting mem_limit in /sys/block/zramX/… #192

Merged
merged 6 commits into from
Feb 25, 2024

Conversation

Malgarion
Copy link
Contributor

…mem_limit, needed in cases when

zram device size is big with compression ratios that can't be fit in RAM yet zram device does not report as being full. Option is "zram-resident-limit = " and syntax is same as with setting 'zram-size ='. Tested on my system and works as expected, additional test may be needed.

…mem_limit, needed in cases when

zram device size is big with compression ratios that can't be fit in RAM yet zram device does not report as
being full. Option is "zram-resident-limit = " and syntax is same as with setting 'zram-size ='.
Tested on my system and works as expected, additional test may be needed.

Sets the maximum resident memory limit of the zram device as a function of *MemTotal*, available as the `ram` variable.

Arithmetic operators (^%/\*-+), e, π, SI suffixes, log(), int(), ceil(), floor(), round(), abs(), min(), max(), and trigonometric functions are supported.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Same format as zram-size.", merge with next para at the end


Arithmetic operators (^%/\*-+), e, π, SI suffixes, log(), int(), ceil(), floor(), round(), abs(), min(), max(), and trigonometric functions are supported.

Defaults to *0* meaning there is no limit, usefull to set when having zram device bigger than available RAM.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Defaults to 0 (no limit)."

src/config.rs Outdated
Comment on lines 130 to 147
self.mem_limit = (match self.zram_resident_limit.as_ref() {
Some(zs) => {
zs.1.from(&zs.2.ps)
.eval(&zs.2, &mut RamNs(memtotal_mb as f64))
.with_context(|| format!("{} zram-resident-limit", self.name))
.and_then(|f| {
if f >= 0. {
Ok(f)
} else {
Err(anyhow!("{}: zram-resident-limit={} < 0", self.name, f))
}
})?
}
None => 0.0,
} * 1024.
* 1024.) as u64;

Ok(())
Copy link
Collaborator

Choose a reason for hiding this comment

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

this clearly duplicates the else in set_disksize_if_enabled(); lift it out

Comment on lines +366 to +373
let mut sl = fasteval::Slab::new();
dev.zram_resident_limit = Some((
value.to_string(),
fasteval::Parser::new()
.parse_noclear(value, &mut sl.ps)
.with_context(|| format!("{} zram-resident-limit", dev.name))?,
sl,
));
Copy link
Collaborator

Choose a reason for hiding this comment

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

clear copy-paste of the "zram-size" branch

# zram-resident-limit=ram/8, then the resident space on RAM won't
# exceed 64MiB. Recomended value is ram / 2.
#
# The default is "0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

.

# The maximum size of resident memory of zram device, as function of
# MemTotal, both in MB. For example, if the machine has 1GiB, and
# zram-resident-limit=ram/8, then the resident space on RAM won't
# exceed 64MiB. Recomended value is ram / 2.
Copy link
Collaborator

Choose a reason for hiding this comment

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

cite? by whom?

Comment on lines 23 to 25
# MemTotal, both in MB. For example, if the machine has 1GiB, and
# zram-resident-limit=ram/8, then the resident space on RAM won't
# exceed 64MiB. Recomended value is ram / 2.
Copy link
Collaborator

Choose a reason for hiding this comment

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

math wrong I think?

@@ -19,6 +19,14 @@ host-memory-limit = 9048
# The default is "min(ram / 2, 4096)".
zram-size = min(ram / 10, 2048)

# The maximum size of resident memory of zram device, as function of
Copy link
Collaborator

Choose a reason for hiding this comment

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

"The maximum memory resident for this zram device, as a function of MemTotal, both in MB." Also format this like the sexion above :v

@Malgarion
Copy link
Contributor Author

Pushed new changes.

@nabijaczleweli nabijaczleweli merged commit 51372d7 into systemd:main Feb 25, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants