Skip to content

Conversation

yeazelm
Copy link
Contributor

@yeazelm yeazelm commented Jul 15, 2025

Issue number:

Part of # bottlerocket-os/bottlerocket#4588

Description of changes:
The files that are linked at build time could be compressed which allows space savings on disk for a minor boot time increase. driverdog now can detect that the requested file may be compressed and have an o.gz extension. If so, then it will decompress before working with the file.

Testing done:
Built variants with and without compressed modules (see this commit for how they were compressed) and confirmed both work. For the compressed objects, the link-telsa-kernel-modules.service journal looks like this:

bash-5.1# journalctl -u link-tesla-kernel-modules.service
Jul 15 21:37:41 localhost systemd[1]: Starting Link Tesla kernel modules...
Jul 15 21:37:41 localhost driverdog[1221]: 21:37:41 [INFO] Decompressing to "/tmp/.tmpMgFCtX/nv-modeset-interface.o"
Jul 15 21:37:41 localhost driverdog[1221]: 21:37:41 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nv-modeset-interface.o.gz to /tmp/.tmpMgFCtX/nv-modeset-interface.o
Jul 15 21:37:41 localhost driverdog[1221]: 21:37:41 [INFO] Decompressing to "/tmp/.tmpMgFCtX/nv-modeset-kernel.o"
Jul 15 21:37:41 localhost driverdog[1221]: 21:37:41 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nv-modeset-kernel.o.gz to /tmp/.tmpMgFCtX/nv-modeset-kernel.o
Jul 15 21:37:42 localhost driverdog[1221]: 21:37:42 [INFO] Linked object 'nvidia-modeset.o'
Jul 15 21:37:42 localhost driverdog[1221]: 21:37:42 [INFO] Stripped object 'nvidia-modeset.o'
Jul 15 21:37:42 localhost driverdog[1221]: 21:37:42 [INFO] Decompressing to "/tmp/.tmpMgFCtX/nv-interface.o"
Jul 15 21:37:42 localhost driverdog[1221]: 21:37:42 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nv-interface.o.gz to /tmp/.tmpMgFCtX/nv-interface.o
Jul 15 21:37:42 localhost driverdog[1221]: 21:37:42 [INFO] Decompressing to "/tmp/.tmpMgFCtX/nv-kernel.o"
Jul 15 21:37:57 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:57 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nv-kernel.o.gz to /tmp/.tmpMgFCtX/nv-kernel.o
Jul 15 21:37:57 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:57 [INFO] Linked object 'nvidia.o'
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Stripped object 'nvidia.o'
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Found compressed file: "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-modeset.mod.o.gz"
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-modeset.mod.o.gz to /tmp/.tmpMgFCtX/nvidia-modeset.mod.o
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Linked nvidia-modeset.ko
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Found compressed file: "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-uvm.o.gz"
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-uvm.o.gz to /tmp/.tmpMgFCtX/nvidia-uvm.o
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Found compressed file: "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-uvm.mod.o.gz"
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-uvm.mod.o.gz to /tmp/.tmpMgFCtX/nvidia-uvm.mod.o
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Linked nvidia-uvm.ko
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Found compressed file: "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia.mod.o.gz"
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Decompressed /x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia.mod.o.gz to /tmp/.tmpMgFCtX/nvidia.mod.o
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal driverdog[1221]: 21:37:58 [INFO] Linked nvidia.ko
Jul 15 21:37:58 ip-192-168-12-156.us-west-2.compute.internal systemd[1]: Finished Link Tesla kernel modules.

For non-compressed, they look like this:

bash-5.1# journalctl -u link-tesla-kernel-modules.service
Jul 15 22:53:15 localhost systemd[1]: Starting Link Tesla kernel modules...
Jul 15 22:53:15 localhost driverdog[1137]: 22:53:15 [INFO] Linked object 'nvidia-modeset.o'
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Stripped object 'nvidia-modeset.o'
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Linked object 'nvidia.o'
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Stripped object 'nvidia.o'
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Copying "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-modeset.mod.o"
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Linked nvidia-modeset.ko
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Copying "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia.mod.o"
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Linked nvidia.ko
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Copying "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-uvm.o"
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Copying "/x86_64-bottlerocket-linux-gnu/sys-root/usr/share/nvidia/tesla/module-objects.d/nvidia-uvm.mod.o"
Jul 15 22:53:16 localhost driverdog[1137]: 22:53:16 [INFO] Linked nvidia-uvm.ko
Jul 15 22:53:16 localhost systemd[1]: Finished Link Tesla kernel modules.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

The files that are linked at build time could be compressed which allows
space savings on disk for a minor boot time increase. driverdog now can
detect that the requested file may be compressed and have a .gz
extension. If so, then it will decompress before working with the file.

Signed-off-by: Matthew Yeazel <yeazelm@amazon.com>
@yeazelm
Copy link
Contributor Author

yeazelm commented Aug 15, 2025

^pushed a new change using OptionalCompressionReader and io::copy

@@ -193,7 +193,7 @@ syn = { version = "2", default-features = false }
tar = { version = "0.4", default-features = false }
tempfile = "3"
test-case = "3"
tokio = { version = "~1.43", default-features = false } # LTS
tokio = { version = "~1.43", default-features = false } # LTS
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this change.

@@ -10,6 +10,7 @@ exclude = ["README.md"]

[dependencies]
argh.workspace = true
early-boot-config-provider.workspace = true
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd pictured a new crate that both of these could depend on.

Comment on lines +10 to +16
/// Creates a temporary directory with test files for compression tests
fn setup_test_files() -> TempDir {
let temp_dir = tempfile::tempdir().expect("Failed to create temp directory");

// Create a regular object file
let regular_file_path = temp_dir.path().join("module.o");
File::create(&regular_file_path).expect("Failed to create regular file");
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests seem to be just copies of the ones in main.rs - seems like we can get rid of this whole file.

Comment on lines +655 to +657
let compressed_file_path = temp_dir.path().join("compressed_module.o.gz");
File::create(&compressed_file_path).expect("Failed to create compressed file");
temp_dir
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't actually a compressed file, which feels like it could create a false sense of coverage.

Comment on lines +550 to +553
use std::{
path::PathBuf,
process::{Command, Output},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous code seemed fine, I'm not a huge fan of this nested style.

Comment on lines +278 to +287
match is_compressed(&from) {
Some(compressed_path) => {
info!("Found compressed file: {:?}", compressed_path);
copy_and_decompress(&compressed_path, &object_file_path)?;
}
None => {
info!("Copying {:?}", &from);
copy_and_decompress(&from, &object_file_path)?;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we don't really need the is_compressed check.

Either the package could just list the .o.gz file directly in the driverdog config, or the package could compress the .o file and include it without the gzip extension.

I.e. the change can just be:

- fs::copy(&from, &object_file_path)
+ copy_and_decompress(&from, &object_file_path)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants