Skip to content

Commit

Permalink
log number of open files when panic
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Nov 23, 2022
1 parent 267bbca commit 00f8c29
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bucket_map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
54 changes: 47 additions & 7 deletions bucket_map/src/bucket_storage.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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,
Expand All @@ -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();

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}
}
22 changes: 22 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 00f8c29

Please sign in to comment.