@@ -28,6 +28,8 @@ const MAX_EXTRACT_SELF_SIZE: u64 = 350 * 1024 * 1024; // 350 MB
28
28
const DWARFS_CACHESIZE : & str = "512M" ;
29
29
#[ cfg( feature = "dwarfs" ) ]
30
30
const DWARFS_BLOCKSIZE : & str = "512K" ;
31
+ #[ cfg( feature = "dwarfs" ) ]
32
+ const DWARFS_READAHEAD : & str = "16M" ;
31
33
32
34
cfg_if ! {
33
35
if #[ cfg( feature = "appimage" ) ] {
@@ -389,36 +391,13 @@ fn create_tmp_dirs(dirs: Vec<&PathBuf>) -> Result<()> {
389
391
}
390
392
391
393
#[ cfg( feature = "dwarfs" ) ]
392
- fn get_dwfs_cachesize ( ) -> String {
393
- let cachesize_env = get_env_var ( "DWARFS_CACHESIZE" ) ;
394
- if cachesize_env. is_empty ( ) {
395
- DWARFS_CACHESIZE . into ( )
396
- } else {
397
- let opts: Vec < & str > = cachesize_env. split ( ',' ) . collect ( ) ;
398
- opts. first ( ) . unwrap_or ( & DWARFS_CACHESIZE ) . to_string ( )
399
- }
400
- }
401
-
402
- #[ cfg( feature = "dwarfs" ) ]
403
- fn get_dwfs_blocksize ( ) -> String {
404
- let blocksize_env = get_env_var ( "DWARFS_BLOCKSIZE" ) ;
405
- if blocksize_env. is_empty ( ) {
406
- DWARFS_BLOCKSIZE . into ( )
407
- } else {
408
- let opts: Vec < & str > = blocksize_env. split ( ',' ) . collect ( ) ;
409
- opts. first ( ) . unwrap_or ( & DWARFS_BLOCKSIZE ) . to_string ( )
410
- }
411
- }
412
-
413
- #[ cfg( feature = "dwarfs" ) ]
414
- fn get_dwfs_workers ( ) -> String {
415
- let num_threads = num_cpus:: get ( ) . to_string ( ) ;
416
- let workers_env = get_env_var ( "DWARFS_WORKERS" ) ;
417
- if workers_env. is_empty ( ) {
418
- num_threads
394
+ fn get_dwfs_option ( option : & str , default : & str ) -> String {
395
+ let option_env = get_env_var ( option) ;
396
+ if option_env. is_empty ( ) {
397
+ default. into ( )
419
398
} else {
420
- let opts: Vec < & str > = workers_env . split ( ',' ) . collect ( ) ;
421
- opts. first ( ) . unwrap_or ( & num_threads . as_str ( ) ) . to_string ( )
399
+ let opts: Vec < & str > = option_env . split ( ',' ) . collect ( ) ;
400
+ opts. first ( ) . unwrap_or ( & default ) . to_string ( )
422
401
}
423
402
}
424
403
@@ -436,10 +415,11 @@ fn mount_image(embed: &Embed, image: &Image, mount_dir: PathBuf) {
436
415
embed. dwarfs ( vec ! [ "-f" . into( ) ,
437
416
"-o" . into( ) , "ro,nodev,noatime,clone_fd" . into( ) ,
438
417
"-o" . into( ) , "cache_files,no_cache_image" . into( ) ,
439
- "-o" . into( ) , format!( "cachesize={}" , get_dwfs_cachesize( ) ) ,
440
- "-o" . into( ) , format!( "blocksize={}" , get_dwfs_blocksize( ) ) ,
418
+ "-o" . into( ) , format!( "cachesize={}" , get_dwfs_option( "DWARFS_CACHESIZE" , DWARFS_CACHESIZE ) ) ,
419
+ "-o" . into( ) , format!( "blocksize={}" , get_dwfs_option( "DWARFS_BLOCKSIZE" , DWARFS_BLOCKSIZE ) ) ,
420
+ "-o" . into( ) , format!( "readahead={}" , get_dwfs_option( "DWARFS_READAHEAD" , DWARFS_READAHEAD ) ) ,
441
421
"-o" . into( ) , "tidy_strategy=time,tidy_interval=500ms,tidy_max_age=1s" . into( ) ,
442
- "-o" . into( ) , format!( "workers={}" , get_dwfs_workers ( ) ) ,
422
+ "-o" . into( ) , format!( "workers={}" , get_dwfs_option ( "DWARFS_WORKERS" , & num_cpus :: get ( ) . to_string ( ) ) ) ,
443
423
"-o" . into( ) , format!( "uid={uid},gid={gid}" ) ,
444
424
"-o" . into( ) , format!( "offset={}" , image. offset) ,
445
425
"-o" . into( ) , "debuglevel=error" . into( ) ,
@@ -502,9 +482,9 @@ fn extract_image(embed: &Embed, image: &Image, mut extract_dir: PathBuf, is_extr
502
482
let mut exec_args = vec ! [
503
483
"--input" . into( ) , image_path,
504
484
"--log-level=error" . into( ) ,
505
- format!( "--cache-size={}" , get_dwfs_cachesize ( ) ) ,
485
+ format!( "--cache-size={}" , get_dwfs_option ( "DWARFS_CACHESIZE" , DWARFS_CACHESIZE ) ) ,
506
486
format!( "--image-offset={}" , image. offset) ,
507
- format!( "--num-workers={}" , get_dwfs_workers ( ) ) ,
487
+ format!( "--num-workers={}" , get_dwfs_option ( "DWARFS_WORKERS" , & num_cpus :: get ( ) . to_string ( ) ) ) ,
508
488
"--output" . into( ) , extract_dir,
509
489
"--stdout-progress" . into( )
510
490
] ;
@@ -707,12 +687,13 @@ fn print_usage(portable_home: &PathBuf, portable_config: &PathBuf) {
707
687
FUSERMOUNT_PROG=/path Specifies a custom path for fusermount
708
688
TARGET_{}=/path Operate on a target {SELF_NAME} rather than this file itself" ,
709
689
ARG_PFX . to_uppercase( ) , SELF_NAME . to_uppercase( ) ) ;
710
- #[ cfg( feature = "dwarfs" ) ]
711
- println ! ( " DWARFS_WORKERS=2 Number of worker threads for DwarFS (default: equal CPU threads)" ) ;
712
- #[ cfg( feature = "dwarfs" ) ]
713
- println ! ( " DWARFS_CACHESIZE=512M Size of the block cache, in bytes for DwarFS (suffixes K, M, G)" ) ;
714
- #[ cfg( feature = "dwarfs" ) ]
715
- println ! ( " DWARFS_BLOCKSIZE=512K Size of the block file I/O, in bytes for DwarFS (suffixes K, M, G)" ) ;
690
+ #[ cfg( feature = "dwarfs" ) ]
691
+ {
692
+ println ! ( " DWARFS_WORKERS=2 Number of worker threads for DwarFS (default: equal CPU threads)
693
+ DWARFS_CACHESIZE=512M Size of the block cache, in bytes for DwarFS (suffixes K, M, G)
694
+ DWARFS_BLOCKSIZE=512K Size of the block file I/O, in bytes for DwarFS (suffixes K, M, G)
695
+ DWARFS_READAHEAD=16M Set readahead size, in bytes for DwarFS (suffixes K, M, G)" ) ;
696
+ }
716
697
}
717
698
718
699
fn main ( ) {
0 commit comments