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

Fix warning when configuring /recompress. Actually write global recompression configuration #216

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 written to `.../recompress`.

* `writeback-device`=

Expand Down
49 changes: 24 additions & 25 deletions src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,25 @@ 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 {
(
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={} 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!(
"Warning: algorithm {:?} supplemental data {:?} not written: {}",
algo, data, err,
algo, add_data, err,
);
}
}
Expand All @@ -98,6 +79,24 @@ pub fn run_device_setup(device: Option<Device>, 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");
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down
5 changes: 1 addition & 4 deletions zram-generator.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down