Skip to content

Commit

Permalink
Add cache management options for DwarFS
Browse files Browse the repository at this point in the history
Add cache management options for DwarFS (to reduce RAM usage)
Add DWARFS_CACHESIZE env var for set DwarFS cachesize
Fix squashfuse speed degradation
  • Loading branch information
VHSgunzo committed Dec 23, 2024
1 parent 603cfab commit e1b2ad1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uruntime"
version = "0.0.9"
version = "0.1.1"
readme = "README.md"
license = "MIT"
repository = "https://github.com/VHSgunzo/uruntime"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ See [Build step in ci.yml](https://github.com/VHSgunzo/uruntime/blob/main/.githu
using extract and run option for reuse extracted data
TMPDIR=/path Specifies a custom path for mounting or extracting the image
FUSERMOUNT_PROG=/path Specifies a custom path for fusermount
DWARFS_CACHESIZE=128M Size of the block cache, in bytes for DwarFS (suffixes K, M, G)
```

* **AppImage runtime usage**
Expand Down Expand Up @@ -156,4 +157,5 @@ See [Build step in ci.yml](https://github.com/VHSgunzo/uruntime/blob/main/.githu
TMPDIR=/path Specifies a custom path for mounting or extracting the image
FUSERMOUNT_PROG=/path Specifies a custom path for fusermount
TARGET_APPIMAGE=/path Operate on a target AppImage rather than this file itself
DWARFS_CACHESIZE=128M Size of the block cache, in bytes for DwarFS (suffixes K, M, G)
```
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {

let assets = IndexMap::from([
#[cfg(feature = "squashfs")]
("squashfuse-upx", format!("https://github.com/VHSgunzo/squashfuse-static/releases/download/v0.5.2.r6.g4289904/squashfuse-{arch}-upx")),
("squashfuse-upx", format!("https://github.com/VHSgunzo/squashfuse-static/releases/download/v0.5.2.r6.g4289904/squashfuse-glibc-{arch}-upx")),
#[cfg(feature = "squashfs")]
("unsquashfs-upx", format!("https://github.com/VHSgunzo/squashfs-tools-static/releases/download/v4.6.1/unsquashfs-{arch}-upx")),
#[cfg(feature = "mksquashfs")]
Expand Down
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use signal_hook::{consts::{SIGINT, SIGTERM, SIGQUIT, SIGHUP}, iterator::Signals}


const URUNTIME_VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(feature = "dwarfs")]
const DWARFS_CACHESIZE: &str = "128M";


#[derive(Debug)]
Expand Down Expand Up @@ -327,6 +329,17 @@ fn create_tmp_dirs(dirs: Vec<&PathBuf>) -> Result<()> {
Err(Error::last_os_error())
}

#[cfg(feature = "dwarfs")]
fn get_dwfs_cachesize() -> String {
let cachesize_env = get_env_var("DWARFS_CACHESIZE");
if cachesize_env.is_empty() {
DWARFS_CACHESIZE.into()
} else {
let opts: Vec<&str> = cachesize_env.split(',').collect();
opts.first().unwrap_or(&DWARFS_CACHESIZE).to_string()
}
}

fn mount_image(embed: &Embed, image: &Image, mount_dir: PathBuf) {
check_fuse();

Expand All @@ -340,6 +353,8 @@ fn mount_image(embed: &Embed, image: &Image, mount_dir: PathBuf) {
let num_threads = num_cpus::get();
embed.dwarfs(vec!["-f".into(),
"-o".into(), "ro,nodev,noatime,clone_fd".into(),
"-o".into(), "cache_files,no_cache_image".into(),
"-o".into(), format!("cachesize={}", get_dwfs_cachesize()),
"-o".into(), format!("uid={uid},gid={gid}"),
"-o".into(), format!("offset={}", image.offset),
"-o".into(), format!("workers={num_threads}"),
Expand Down Expand Up @@ -404,6 +419,7 @@ fn extract_image(embed: &Embed, image: &Image, mut extract_dir: PathBuf, is_extr
let mut exec_args = vec![
"--input".into(), image_path,
"--log-level=error".into(),
format!("--cache-size={}", get_dwfs_cachesize()),
format!("--image-offset={}", image.offset),
format!("--num-workers={}", num_cpus::get()),
"--output".into(), extract_dir,
Expand Down Expand Up @@ -559,6 +575,8 @@ fn print_usage(portable_home: &PathBuf, portable_config: &PathBuf) {
FUSERMOUNT_PROG=/path Specifies a custom path for fusermount", arg_pfx.to_uppercase());
#[cfg(feature = "appimage")]
println!(" TARGET_APPIMAGE=/path Operate on a target {self_name} rather than this file itself");
#[cfg(feature = "dwarfs")]
println!(" DWARFS_CACHESIZE=128M Size of the block cache, in bytes for DwarFS (suffixes K, M, G)");
}

fn main() {
Expand Down

0 comments on commit e1b2ad1

Please sign in to comment.