Skip to content

Commit

Permalink
diskio: Add buffer_used() to Executor and verify it in the test
Browse files Browse the repository at this point in the history
In rust-lang#2774 we have seen hangs during installation for some low tier
platforms for whom the 32M default if sysinfo doesn't work causes
problems.  This change *exposes* that problem in a failing test.

Signed-off-by: Daniel Silverstone <[email protected]>
  • Loading branch information
kinnison committed May 28, 2021
1 parent 494b307 commit 60d206d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/diskio/immediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ impl Executor for ImmediateUnpacker {
fn buffer_available(&self, _len: usize) -> bool {
true
}

#[cfg(test)]
fn buffer_used(&self) -> usize {
0
}
}

/// The non-shared state for writing a file incrementally
Expand Down
4 changes: 4 additions & 0 deletions src/diskio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ pub(crate) trait Executor {

/// Query the memory budget to see if a particular size buffer is available
fn buffer_available(&self, len: usize) -> bool;

#[cfg(test)]
/// Query the memory budget to see how much of the buffer pool is in use
fn buffer_used(&self) -> usize;
}

/// Trivial single threaded IO to be used from executors.
Expand Down
6 changes: 4 additions & 2 deletions src/diskio/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
}
}
// sending a zero length chunk closes the file
let mut chunk = io_executor.get_buffer(0);
let mut chunk = io_executor.get_buffer(super::IO_CHUNK_SIZE);
chunk = chunk.finished();
sender(chunk);
loop {
for work in io_executor.completed().collect::<Vec<_>>() {
match work {
super::CompletedIo::Chunk(_) => unreachable!(),
super::CompletedIo::Chunk(_) => {}
super::CompletedIo::Item(_) => {
file_finished = true;
}
Expand All @@ -69,6 +69,8 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
// no more work should be outstanding
unreachable!();
}

assert_eq!(io_executor.buffer_used(), 0);
Ok(())
})?;
// We should be able to read back the file
Expand Down
5 changes: 5 additions & 0 deletions src/diskio/threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ impl<'a> Executor for Threaded<'a> {
let total_used = Threaded::ram_highwater(&self.vec_pools);
total_used + size < self.ram_budget
}

#[cfg(test)]
fn buffer_used(&self) -> usize {
self.vec_pools.iter().map(|(_, p)| *p.in_use.borrow()).sum()
}
}

impl<'a> Drop for Threaded<'a> {
Expand Down

0 comments on commit 60d206d

Please sign in to comment.