Skip to content

Commit 927f27f

Browse files
jiangliuadamqqqplay
authored andcommitted
rafs: do not include chunk info array in the metadata blob
Now we can reconstruct chunk info from RAFS v6 data blob with embedded chunk digest, so no need to embed the chunk info array in the metadata blob anymore, which helps to dramatically reduce size of metadata blob for big images. Signed-off-by: Jiang Liu <[email protected]>
1 parent b937989 commit 927f27f

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

rafs/src/builder/core/v6.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use storage::device::BlobFeatures;
1616

1717
use super::chunk_dict::DigestWithBlobIndex;
1818
use super::node::Node;
19-
use crate::builder::{Bootstrap, BootstrapContext, BuildContext, ConversionType, Tree};
19+
use crate::builder::{Bootstrap, BootstrapContext, BuildContext, ConversionType, Feature, Tree};
2020
use crate::metadata::chunk::ChunkWrapper;
2121
use crate::metadata::layout::v6::{
2222
align_offset, calculate_nid, new_v6_inode, RafsV6BlobTable, RafsV6Device, RafsV6Dirent,
@@ -40,7 +40,7 @@ impl Node {
4040
f_bootstrap: &mut dyn RafsIoWrite,
4141
orig_meta_addr: u64,
4242
meta_addr: u64,
43-
chunk_cache: &mut BTreeMap<DigestWithBlobIndex, Arc<ChunkWrapper>>,
43+
chunk_cache: Option<&mut BTreeMap<DigestWithBlobIndex, Arc<ChunkWrapper>>>,
4444
) -> Result<()> {
4545
let xattr_inline_count = self.info.xattrs.count_v6();
4646
ensure!(
@@ -68,7 +68,9 @@ impl Node {
6868
if self.is_dir() {
6969
self.v6_dump_dir(ctx, f_bootstrap, meta_addr, meta_offset, &mut inode)?;
7070
} else if self.is_reg() {
71-
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode)?;
71+
if let Some(chunk_cache) = chunk_cache {
72+
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode)?;
73+
}
7274
} else if self.is_symlink() {
7375
self.v6_dump_symlink(ctx, f_bootstrap, &mut inode)?;
7476
} else {
@@ -709,7 +711,11 @@ impl Bootstrap {
709711
// Each layer uses the corresponding chunk in the blob of its own layer.
710712
// If HashChunkDict is used here, it will cause duplication. The chunks are removed,
711713
// resulting in incomplete chunk info.
712-
let mut chunk_cache = BTreeMap::new();
714+
let mut chunk_cache = if ctx.features.is_enabled(Feature::BlobToc) {
715+
None
716+
} else {
717+
Some(BTreeMap::new())
718+
};
713719

714720
// Dump bootstrap
715721
timing_tracer!(
@@ -720,7 +726,7 @@ impl Bootstrap {
720726
bootstrap_ctx.writer.as_mut(),
721727
orig_meta_addr,
722728
meta_addr,
723-
&mut chunk_cache,
729+
chunk_cache.as_mut(),
724730
)
725731
.context("failed to dump bootstrap")?;
726732
}
@@ -751,24 +757,26 @@ impl Bootstrap {
751757
}
752758

753759
// TODO: get rid of the chunk info array.
754-
// Dump chunk info array.
755-
let chunk_table_offset = bootstrap_ctx
756-
.writer
757-
.seek_to_end()
758-
.context("failed to seek to bootstrap's end for chunk table")?;
759-
let mut chunk_table_size: u64 = 0;
760-
for (_, chunk) in chunk_cache.iter() {
761-
let chunk_size = chunk
762-
.store(bootstrap_ctx.writer.as_mut())
763-
.context("failed to dump chunk table")?;
764-
chunk_table_size += chunk_size as u64;
760+
if let Some(chunk_cache) = chunk_cache.as_ref() {
761+
// Dump chunk info array.
762+
let chunk_table_offset = bootstrap_ctx
763+
.writer
764+
.seek_to_end()
765+
.context("failed to seek to bootstrap's end for chunk table")?;
766+
let mut chunk_table_size: u64 = 0;
767+
for (_, chunk) in chunk_cache.iter() {
768+
let chunk_size = chunk
769+
.store(bootstrap_ctx.writer.as_mut())
770+
.context("failed to dump chunk table")?;
771+
chunk_table_size += chunk_size as u64;
772+
}
773+
ext_sb.set_chunk_table(chunk_table_offset, chunk_table_size);
774+
debug!(
775+
"chunk_table offset {} size {}",
776+
chunk_table_offset, chunk_table_size
777+
);
778+
Self::v6_align_to_4k(bootstrap_ctx)?;
765779
}
766-
ext_sb.set_chunk_table(chunk_table_offset, chunk_table_size);
767-
debug!(
768-
"chunk_table offset {} size {}",
769-
chunk_table_offset, chunk_table_size
770-
);
771-
Self::v6_align_to_4k(bootstrap_ctx)?;
772780

773781
// Prepare device slots.
774782
let mut pos = bootstrap_ctx

src/bin/nydus-image/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,9 @@ impl Command {
10771077
};
10781078
let config =
10791079
Self::get_configuration(matches).context("failed to get configuration information")?;
1080-
config
1081-
.internal
1082-
.set_blob_accessible(matches.get_one::<String>("config").is_some());
1080+
let blob_accessible = matches.get_one::<String>("config").is_some()
1081+
|| matches.get_one::<String>("blob-dir").is_some();
1082+
config.internal.set_blob_accessible(blob_accessible);
10831083
let mut ctx = BuildContext {
10841084
prefetch: Self::get_prefetch(matches)?,
10851085
..Default::default()

0 commit comments

Comments
 (0)