From d79f32b15dc4c493d13a1da8ecb3459c933616f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Fri, 13 Dec 2024 15:13:53 +0100 Subject: [PATCH 1/4] Fix warning when configuring /recompress Ref: #215 --- src/setup.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setup.rs b/src/setup.rs index daad2a4..e31cc0e 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -67,11 +67,11 @@ pub fn run_device_setup(device: Option, device_name: &str) -> Result<()> match fs::write(&path, data) { Ok(_) => { if let Some((add_path, add_data)) = add_pathdata { - match fs::write(add_path, add_data) { + match fs::write(add_path, &add_data) { Ok(_) => {} Err(err) => { warn!( - "Warning: algorithm {algo:?} supplemental data {data:?} not written: {err}", + "Warning: algorithm {algo:?} supplemental data {add_data:?} not written: {err}", ); } } From 7f56b6fa72137eb545b4a75e34f3bcd924f36fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Fri, 13 Dec 2024 15:16:55 +0100 Subject: [PATCH 2/4] Actually write global recompression configuration Ref: #215 --- src/setup.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/setup.rs b/src/setup.rs index e31cc0e..b383293 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -97,6 +97,24 @@ pub fn run_device_setup(device: Option, device_name: &str) -> Result<()> })?, } } + if !device + .compression_algorithms + .recompression_global + .is_empty() + { + match fs::write( + device_sysfs_path.join("recompress"), + &device.compression_algorithms.recompression_global, + ) { + Ok(_) => {} + Err(err) => { + warn!( + "Warning: configuring global recompression with {:?} failed: {}", + device.compression_algorithms.recompression_global, err, + ); + } + } + } if let Some(ref wb_dev) = device.writeback_dev { let writeback_path = device_sysfs_path.join("backing_dev"); From 44017fccf8b17ee2d5ebf7c6d027676a829e9962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Fri, 13 Dec 2024 22:46:57 +0100 Subject: [PATCH 3/4] Fix how we configure compression parameters Closes: #215 --- man/zram-generator.conf.md | 4 ++-- src/setup.rs | 29 +++++------------------------ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/man/zram-generator.conf.md b/man/zram-generator.conf.md index c3fc7d4..42e2166 100644 --- a/man/zram-generator.conf.md +++ b/man/zram-generator.conf.md @@ -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.
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`= diff --git a/src/setup.rs b/src/setup.rs index b383293..267d22c 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -35,39 +35,20 @@ pub fn run_device_setup(device: Option, device_name: &str) -> Result<()> .iter() .enumerate() { - let params = if params.is_empty() { - None - } else { - Some(params) - }; - let (path, data, add_pathdata) = 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}"), - ) - }), - ) + let (path, data) = if prio == 0 { + (device_sysfs_path.join("comp_algorithm"), algo) } else { ( device_sysfs_path.join("recomp_algorithm"), &format!("algo={algo} priority={prio}"), - params.as_ref().map(|p| { - ( - device_sysfs_path.join("recompress"), - format!("{p} priority={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!( From 7cc5b4aafb2c98bdac5cad7e794d1e15dec14267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Mon, 16 Dec 2024 16:17:06 +0100 Subject: [PATCH 4/4] Soft-hide global /recompress parameters Ref: #215 --- man/zram-generator.conf.md | 2 +- tests/test_cases.rs | 2 +- zram-generator.conf.example | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/man/zram-generator.conf.md b/man/zram-generator.conf.md index 42e2166..135262c 100644 --- a/man/zram-generator.conf.md +++ b/man/zram-generator.conf.md @@ -80,7 +80,7 @@ Devices with the final size of *0* will be discarded. 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`. - A parenthesised parameter list *without* a compression algorithm is set as the global recompression parameters (`.../recompress`). + A parenthesised parameter list *without* a compression algorithm is written to `.../recompress`. * `writeback-device`= diff --git a/tests/test_cases.rs b/tests/test_cases.rs index a09740b..7733ae4 100644 --- a/tests/test_cases.rs +++ b/tests/test_cases.rs @@ -326,7 +326,7 @@ fn test_10_example() { ("lzo-rle".into(), "".into()), ("zstd".into(), "level=3".into()) ], - recompression_global: "type=idle".into(), + ..Default::default() } ); assert_eq!(d.options, ""); diff --git a/zram-generator.conf.example b/zram-generator.conf.example index ca02620..f15be09 100644 --- a/zram-generator.conf.example +++ b/zram-generator.conf.example @@ -38,10 +38,7 @@ zram-resident-limit = maxhotplug * 3/4 # # Subsequent algorithms are used for recompression. # Comma-separated parameters may be specified in parentheses. -# -# Parameters without a compression algorithm are set as -# global recompression parameters. -compression-algorithm = lzo-rle zstd(level=3) (type=idle) +compression-algorithm = lzo-rle zstd(level=3) # By default, file systems and swap areas are trimmed on-the-go # by setting "discard".