From e1aca7dab0e42edce1b36e83f6da675d76b07732 Mon Sep 17 00:00:00 2001 From: Wenhao Ren Date: Tue, 19 Dec 2023 09:58:42 +0800 Subject: [PATCH] storage: fix the tiny prefetch request for batch chunks By passing the chunk continuous check, and correctly sort batch chunks, the prefetch request will not be interrupted by batch chunks anymore. Signed-off-by: Wenhao Ren --- storage/src/cache/cachedfile.rs | 2 +- storage/src/device.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/storage/src/cache/cachedfile.rs b/storage/src/cache/cachedfile.rs index 49e7a8e3f2d..4122384a250 100644 --- a/storage/src/cache/cachedfile.rs +++ b/storage/src/cache/cachedfile.rs @@ -639,7 +639,7 @@ impl BlobCache for FileCacheEntry { // Then handle fs prefetch let max_comp_size = self.prefetch_batch_size(); let mut bios = bios.to_vec(); - bios.sort_unstable_by_key(|entry| entry.chunkinfo.compressed_offset()); + bios.sort_by_key(|entry| entry.chunkinfo.compressed_offset()); self.metrics.prefetch_unmerged_chunks.add(bios.len() as u64); BlobIoMergeState::merge_and_issue( &bios, diff --git a/storage/src/device.rs b/storage/src/device.rs index a816ae8e34b..51f58e400cf 100644 --- a/storage/src/device.rs +++ b/storage/src/device.rs @@ -750,6 +750,12 @@ impl BlobIoDesc { let prev_end = self.chunkinfo.compressed_offset() + self.chunkinfo.compressed_size() as u64; let next_offset = next.chunkinfo.compressed_offset(); + if self.chunkinfo.is_batch() || next.chunkinfo.is_batch() { + // Batch chunk can only be compared by uncompressed info. + return next.chunkinfo.uncompressed_offset() - self.chunkinfo.uncompressed_end() + <= max_gap; + } + if self.chunkinfo.blob_index() == next.chunkinfo.blob_index() && next_offset >= prev_end { if next.blob.is_legacy_stargz() { next_offset - prev_end <= max_gap * 8 @@ -999,7 +1005,7 @@ impl BlobIoRange { } /// Merge an `BlobIoDesc` into the `BlobIoRange` object. - pub fn merge(&mut self, bio: &BlobIoDesc, max_gap: u64) { + pub fn merge(&mut self, bio: &BlobIoDesc, _max_gap: u64) { let end = self.blob_offset + self.blob_size; let offset = bio.chunkinfo.compressed_offset(); let size = bio.chunkinfo.compressed_size() as u64; @@ -1007,7 +1013,7 @@ impl BlobIoRange { assert!(offset.checked_add(size).is_some()); size } else { - assert!((offset > end && offset - end <= max_gap)); + assert!(offset > end); size + (offset - end) }; assert!(end.checked_add(size).is_some());