diff --git a/man/zram-generator.conf.md b/man/zram-generator.conf.md
index c3fc7d4..135262c 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 written to `.../recompress`.
* `writeback-device`=
diff --git a/src/setup.rs b/src/setup.rs
index daad2a4..267d22c 100644
--- a/src/setup.rs
+++ b/src/setup.rs
@@ -35,43 +35,24 @@ 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!(
- "Warning: algorithm {algo:?} supplemental data {data:?} not written: {err}",
+ "Warning: algorithm {algo:?} supplemental data {add_data:?} not written: {err}",
);
}
}
@@ -97,6 +78,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");
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".