summary refs log tree commit diff
path: root/disk
diff options
context:
space:
mode:
authorA. Cody Schuffelen <schuffelen@google.com>2020-03-19 16:43:00 -0700
committerCommit Bot <commit-bot@chromium.org>2020-04-07 23:03:40 +0000
commitf3081b120e0934539f6f3f2c60c9ff26c801c0ea (patch)
treeaa9d51315057d1ccf70ced7c84c1f820d3d9aaa1 /disk
parent0bf8a5590f3556d8ec05c182cb612f254fd416e5 (diff)
downloadcrosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.tar
crosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.tar.gz
crosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.tar.bz2
crosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.tar.lz
crosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.tar.xz
crosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.tar.zst
crosvm-f3081b120e0934539f6f3f2c60c9ff26c801c0ea.zip
Fix performance problem on Android Sparse images
This was adding ~11 minutes to the boot time with sparse images.

BUG=b:151981838
TEST=launch cuttlefish with sparse images.

Change-Id: I707258566aee338f742a3a5fe94d0bad8302c447
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2111117
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Diffstat (limited to 'disk')
-rw-r--r--disk/src/android_sparse.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/disk/src/android_sparse.rs b/disk/src/android_sparse.rs
index 07e5714..0772bfc 100644
--- a/disk/src/android_sparse.rs
+++ b/disk/src/android_sparse.rs
@@ -307,11 +307,12 @@ impl FileReadWriteAtVolatile for AndroidSparse {
                 .file
                 .read_at_volatile(subslice, *file_offset + chunk_offset),
             Chunk::Fill(fill_bytes) => {
+                let chunk_offset_mod = chunk_offset % fill_bytes.len() as u64;
                 let filled_memory: Vec<u8> = fill_bytes
                     .iter()
                     .cloned()
                     .cycle()
-                    .skip(chunk_offset as usize)
+                    .skip(chunk_offset_mod as usize)
                     .take(subslice.size() as usize)
                     .collect();
                 subslice.copy_from(&filled_memory);
@@ -475,6 +476,28 @@ mod tests {
     }
 
     #[test]
+    fn read_fill_offset_edges() {
+        let chunks = vec![
+            ChunkWithSize {
+                chunk: Chunk::DontCare,
+                expanded_size: 20,
+            },
+            ChunkWithSize {
+                chunk: Chunk::Fill(vec![10, 20, 30]),
+                expanded_size: 100,
+            },
+        ];
+        let mut image = test_image(chunks);
+        let mut input_memory = [55u8; 7];
+        let input_volatile_memory = &mut input_memory[..];
+        image
+            .read_exact_at_volatile(input_volatile_memory.get_slice(0, 7).unwrap(), 39)
+            .expect("Could not read");
+        let input_vec: Vec<u8> = input_memory.into_iter().cloned().collect();
+        assert_eq!(input_vec, vec![20, 30, 10, 20, 30, 10, 20]);
+    }
+
+    #[test]
     fn read_raw() {
         let chunks = vec![ChunkWithSize {
             chunk: Chunk::Raw(0),