summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandy.boot <bootandy@gmail.com>2022-08-25 08:56:30 +0100
committerandy.boot <bootandy@gmail.com>2022-08-31 21:14:56 +0100
commitc363e5ff8b7d141a7f93d059e1109f79778430eb (patch)
tree2e78423788bf163a7e675c84e6e6c695558d567a
parentc148cd904424910b4bd7a6df3a7b1792bf91ffd4 (diff)
Fix: Only create large stack size if enough memoryv0.8.3
Small boxes do not have enough memory to create a large stack Conversely we want a large stack size for large boxes with a very highly nested directory structure. Version: New version
-rw-r--r--Cargo.lock41
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs24
3 files changed, 61 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c4f62f4..3e7b6c9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -69,6 +69,12 @@ dependencies = [
]
[[package]]
+name = "cc"
+version = "1.0.73"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -119,6 +125,12 @@ dependencies = [
]
[[package]]
+name = "core-foundation-sys"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
+
+[[package]]
name = "crossbeam-channel"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -197,7 +209,7 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "du-dust"
-version = "0.8.2"
+version = "0.8.3"
dependencies = [
"ansi_term",
"assert_cmd",
@@ -210,6 +222,7 @@ dependencies = [
"regex",
"serde",
"stfu8",
+ "sysinfo",
"tempfile",
"terminal_size",
"thousands",
@@ -323,6 +336,15 @@ dependencies = [
]
[[package]]
+name = "ntapi"
+version = "0.3.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "num_cpus"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -519,6 +541,23 @@ dependencies = [
]
[[package]]
+name = "sysinfo"
+version = "0.15.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de94457a09609f33fec5e7fceaf907488967c6c7c75d64da6a7ce6ffdb8b5abd"
+dependencies = [
+ "cc",
+ "cfg-if",
+ "core-foundation-sys",
+ "doc-comment",
+ "libc",
+ "ntapi",
+ "once_cell",
+ "rayon",
+ "winapi",
+]
+
+[[package]]
name = "tempfile"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 078b07c..8ecd934 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "du-dust"
description = "A more intuitive version of du"
-version = "0.8.2"
+version = "0.8.3"
authors = ["bootandy <bootandy@gmail.com>", "nebkor <code@ardent.nebcorp.com>"]
edition = "2021"
readme = "README.md"
@@ -39,6 +39,7 @@ regex = "1"
config-file = "0.2"
serde = { version = "1.0", features = ["derive"] }
directories = "4"
+sysinfo = "0.15"
[target.'cfg(windows)'.dependencies]
winapi-util = "0.1"
diff --git a/src/main.rs b/src/main.rs
index f020f1c..942a414 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,6 +12,7 @@ mod utils;
use crate::cli::build_cli;
use std::collections::HashSet;
use std::process;
+use sysinfo::{System, SystemExt};
use self::display::draw_it;
use clap::Values;
@@ -19,6 +20,7 @@ use config::get_config;
use dir_walker::{walk_it, WalkData};
use filter::get_biggest;
use filter_type::get_all_file_types;
+use rayon::ThreadPoolBuildError;
use regex::Regex;
use std::cmp::max;
use std::path::PathBuf;
@@ -154,11 +156,7 @@ fn main() {
by_filecount,
ignore_hidden: config.get_ignore_hidden(&options),
};
- // Larger stack size to handle cases with lots of nested directories
- rayon::ThreadPoolBuilder::new()
- .stack_size(usize::pow(1024, 3))
- .build_global()
- .unwrap();
+ let _rayon = init_rayon();
let iso = config.get_iso(&options);
let (top_level_nodes, has_errors) = walk_it(simplified_dirs, walk_data);
@@ -191,3 +189,19 @@ fn main() {
)
}
}
+
+fn init_rayon() -> Result<(), ThreadPoolBuildError> {
+ let large_stack = usize::pow(1024, 3);
+ // Warning: Creating System is slow, takes ~ 100ms
+ let s = System::new();
+ let available = s.get_available_memory() * 1024;
+
+ if available > large_stack.try_into().unwrap() {
+ // Larger stack size to handle cases with lots of nested directories
+ rayon::ThreadPoolBuilder::new()
+ .stack_size(large_stack)
+ .build_global()
+ } else {
+ Ok(())
+ }
+}