Skip to content

Commit

Permalink
Fix how we configure compression parameters
Browse files Browse the repository at this point in the history
Closes: systemd#215
  • Loading branch information
nabijaczleweli committed Dec 13, 2024
1 parent 0007613 commit 400ef70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
4 changes: 2 additions & 2 deletions man/zram-generator.conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Devices with the final size of *0* will be discarded.
If unset, none will be configured and the kernel's default will be used.<br />
If more than one is given, and recompression is enabled in the kernel, subsequent ones will be set as the recompression algorithms, with decreasing priority.

If a compression algorithm is suffixed with a parenthesised comma-separated list of parameters, those are given to `.../algorithm_params` (and `.../recompress`).
A parenthesised parameter list *without* a compression algorithm is set as the global recompression parameters.
If a compression algorithm is suffixed with a parenthesised comma-separated list of parameters, those are given to `.../algorithm_params`.
A parenthesised parameter list *without* a compression algorithm is set as the global recompression parameters (`.../recompress`).

* `writeback-device`=

Expand Down
24 changes: 4 additions & 20 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,23 @@ pub fn run_device_setup(device: Option<Device>, device_name: &str) -> Result<()>
.iter()
.enumerate()
{
let params = if params.is_empty() {
None
} else {
Some(params)
};
let (path, data, add_pathdata) = if prio == 0 {
let (path, data) = if prio == 0 {
(
device_sysfs_path.join("comp_algorithm"),
algo,
params.as_ref().map(|p| {
(
device_sysfs_path.join("algorithm_params"),
format!("algo={} {}", algo, p),
)
}),
)
} else {
(
device_sysfs_path.join("recomp_algorithm"),
&format!("algo={} priority={}", algo, prio),
params.as_ref().map(|p| {
(
device_sysfs_path.join("recompress"),
format!("{} priority={}", p, prio),
)
}),
)
};

match fs::write(&path, data) {
Ok(_) => {
if let Some((add_path, add_data)) = add_pathdata {
match fs::write(add_path, &add_data) {
if !params.is_empty() {
let add_data = format!("priority={} {}", prio, params);
match fs::write(device_sysfs_path.join("algorithm_params"), &add_data) {
Ok(_) => {}
Err(err) => {
warn!(
Expand Down

0 comments on commit 400ef70

Please sign in to comment.