Skip to content

Commit 2b0f1d0

Browse files
author
yanshay
committed
improve to avoid unneeded read before write when writing 512 bytes to a block
1 parent 1b5c28f commit 2b0f1d0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/volume_mgr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -878,15 +878,15 @@ where
878878
Err(e) => return Err(e),
879879
};
880880
let to_copy = core::cmp::min(block_avail, bytes_to_write - written);
881-
let block = if block_offset != 0
882-
|| data.open_files[file_idx].current_offset < data.open_files[file_idx].entry.size
883-
{
881+
let block = if (block_offset == 0) && (to_copy == block_avail) {
882+
// we're replacing the whole Block, so the previous contents
883+
// are irrelevant
884+
data.block_cache.blank_mut(block_idx)
885+
} else {
884886
debug!("Reading for partial block write");
885887
data.block_cache
886888
.read_mut(block_idx)
887889
.map_err(Error::DeviceError)?
888-
} else {
889-
data.block_cache.blank_mut(block_idx)
890890
};
891891
block[block_offset..block_offset + to_copy]
892892
.copy_from_slice(&buffer[written..written + to_copy]);

0 commit comments

Comments
 (0)