From 00f8c293311d6f2810eb960a3845894df6edd95d Mon Sep 17 00:00:00 2001 From: Haoran Yi Date: Wed, 23 Nov 2022 09:46:24 -0600 Subject: [PATCH] log number of open files when panic --- Cargo.lock | 16 ++++++++++ bucket_map/Cargo.toml | 2 ++ bucket_map/src/bucket_storage.rs | 54 +++++++++++++++++++++++++++----- programs/sbf/Cargo.lock | 22 +++++++++++++ 4 files changed, 87 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd55b720c65e2b..fae978572c12b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3541,6 +3541,21 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "procfs" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818" +dependencies = [ + "bitflags", + "byteorder", + "chrono", + "flate2", + "hex", + "lazy_static", + "rustix", +] + [[package]] name = "proptest" version = "1.0.0" @@ -4901,6 +4916,7 @@ dependencies = [ "log", "memmap2", "modular-bitfield", + "procfs", "rand 0.7.3", "rayon", "solana-logger 1.15.0", diff --git a/bucket_map/Cargo.toml b/bucket_map/Cargo.toml index 40f91d60b8fcf0..db8798d6ab739d 100644 --- a/bucket_map/Cargo.toml +++ b/bucket_map/Cargo.toml @@ -14,11 +14,13 @@ edition = "2021" log = { version = "0.4.17" } memmap2 = "0.5.3" modular-bitfield = "0.11.2" +procfs = "0.14.1" rand = "0.7.0" solana-measure = { path = "../measure", version = "=1.15.0" } solana-sdk = { path = "../sdk", version = "=1.15.0" } tempfile = "3.3.0" + [dev-dependencies] fs_extra = "1.2.0" rayon = "1.5.3" diff --git a/bucket_map/src/bucket_storage.rs b/bucket_map/src/bucket_storage.rs index dac4e9b11caf03..f7471459922540 100644 --- a/bucket_map/src/bucket_storage.rs +++ b/bucket_map/src/bucket_storage.rs @@ -1,6 +1,7 @@ use { crate::{bucket_stats::BucketStats, MaxSearch}, memmap2::MmapMut, + procfs::process::{Limit, Process}, rand::{thread_rng, Rng}, solana_measure::measure::Measure, std::{ @@ -262,6 +263,14 @@ impl BucketStorage { } } + fn get_number_of_open_files_and_limit() -> Option<(usize, Limit)> { + let proc = Process::myself().ok()?; + let max_open_files_limit = proc.limits().unwrap().max_open_files; + let num_open_files = proc.fd_count().unwrap(); + + Some((num_open_files, max_open_files_limit)) + } + fn new_map( drives: &[PathBuf], cell_size: usize, @@ -280,12 +289,24 @@ impl BucketStorage { .create(true) .open(file.clone()) .map_err(|e| { - panic!( - "Unable to create data file {} in current dir({:?}): {:?}", - file.display(), - std::env::current_dir(), - e - ); + if let Some((num_open_files, max_open_files_limit)) = Self::get_number_of_open_files_and_limit() { + panic!( + "Unable to create data file {} in current dir({:?}): {:?}, current number of open files: {}, max limit of open files: {:?}", + file.display(), + std::env::current_dir(), + e, + num_open_files, + max_open_files_limit, + ); + } + else { + panic!( + "Unable to create data file {} in current dir({:?}): {:?}", + file.display(), + std::env::current_dir(), + e, + ); + } }) .unwrap(); @@ -381,7 +402,7 @@ impl BucketStorage { #[cfg(test)] mod test { - use {super::*, tempfile::tempdir}; + use {super::*, procfs::process::LimitValue, tempfile::tempdir}; #[test] fn test_bucket_storage() { @@ -412,5 +433,24 @@ mod test { storage.free(ix, uid); assert!(storage.is_free(ix)); assert_eq!(storage.uid(ix), None); + + // test get_number_of_open_files_and_limit + if let Some((num_open_files, max_open_files_limit)) = + BucketStorage::get_number_of_open_files_and_limit() + { + assert!(num_open_files > 0); + match max_open_files_limit.soft_limit { + LimitValue::Unlimited => {} + LimitValue::Value(x) => assert!(x > 0), + } + + match max_open_files_limit.hard_limit { + LimitValue::Unlimited => {} + LimitValue::Value(x) => assert!(x > 0), + } + + println!("{:?}", num_open_files); + println!("{:?}", max_open_files_limit); + } } } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 03446bfa495cf0..5c301e09b0bc33 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -1801,6 +1801,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "histogram" version = "0.6.9" @@ -3259,6 +3265,21 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "procfs" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfb6451c91904606a1abe93e83a8ec851f45827fa84273f256ade45dc095818" +dependencies = [ + "bitflags", + "byteorder 1.4.3", + "chrono", + "flate2", + "hex", + "lazy_static", + "rustix", +] + [[package]] name = "prost" version = "0.9.0" @@ -4336,6 +4357,7 @@ dependencies = [ "log", "memmap2", "modular-bitfield", + "procfs", "rand 0.7.3", "solana-measure", "solana-sdk 1.15.0",