Skip to content

Commit aa13eb5

Browse files
committed
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 c9d9b43 commit aa13eb5

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

rafs/src/builder/core/v6.rs

Lines changed: 27 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::inode::new_v6_inode;
2222
use crate::metadata::layout::v6::{
@@ -41,7 +41,7 @@ impl Node {
4141
f_bootstrap: &mut dyn RafsIoWrite,
4242
orig_meta_addr: u64,
4343
meta_addr: u64,
44-
chunk_cache: &mut BTreeMap<DigestWithBlobIndex, Arc<ChunkWrapper>>,
44+
chunk_cache: Option<&mut BTreeMap<DigestWithBlobIndex, Arc<ChunkWrapper>>>,
4545
) -> Result<()> {
4646
let xattr_inline_count = self.info.xattrs.count_v6();
4747
ensure!(
@@ -69,7 +69,9 @@ impl Node {
6969
if self.is_dir() {
7070
self.v6_dump_dir(ctx, f_bootstrap, meta_addr, meta_offset, &mut inode)?;
7171
} else if self.is_reg() {
72-
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode)?;
72+
if let Some(chunk_cache) = chunk_cache {
73+
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode)?;
74+
}
7375
} else if self.is_symlink() {
7476
self.v6_dump_symlink(ctx, f_bootstrap, &mut inode)?;
7577
} else {
@@ -685,7 +687,11 @@ impl Bootstrap {
685687
// Each layer uses the corresponding chunk in the blob of its own layer.
686688
// If HashChunkDict is used here, it will cause duplication. The chunks are removed,
687689
// resulting in incomplete chunk info.
688-
let mut chunk_cache = BTreeMap::new();
690+
let mut chunk_cache = if ctx.features.is_enabled(Feature::BlobToc) {
691+
None
692+
} else {
693+
Some(BTreeMap::new())
694+
};
689695

690696
// Dump bootstrap
691697
timing_tracer!(
@@ -696,7 +702,7 @@ impl Bootstrap {
696702
bootstrap_ctx.writer.as_mut(),
697703
orig_meta_addr,
698704
meta_addr,
699-
&mut chunk_cache,
705+
chunk_cache.as_mut(),
700706
)
701707
.context("failed to dump bootstrap")?;
702708
}
@@ -725,24 +731,23 @@ impl Bootstrap {
725731
}
726732

727733
// TODO: get rid of the chunk info array.
728-
// Dump chunk info array.
729-
let chunk_table_offset = bootstrap_ctx
730-
.writer
731-
.seek_to_end()
732-
.context("failed to seek to bootstrap's end for chunk table")?;
733-
let mut chunk_table_size: u64 = 0;
734-
for (_, chunk) in chunk_cache.iter() {
735-
let chunk_size = chunk
736-
.store(bootstrap_ctx.writer.as_mut())
737-
.context("failed to dump chunk table")?;
738-
chunk_table_size += chunk_size as u64;
734+
if let Some(chunk_cache) = chunk_cache.as_ref() {
735+
// Dump chunk info array.
736+
let chunk_table_offset = bootstrap_ctx
737+
.writer
738+
.seek_to_end()
739+
.context("failed to seek to bootstrap's end for chunk table")?;
740+
let mut chunk_table_size: u64 = 0;
741+
for (_, chunk) in chunk_cache.iter() {
742+
let chunk_size = chunk
743+
.store(bootstrap_ctx.writer.as_mut())
744+
.context("failed to dump chunk table")?;
745+
chunk_table_size += chunk_size as u64;
746+
}
747+
ext_sb.set_chunk_table(chunk_table_offset, chunk_table_size);
748+
debug!( "chunk_table offset {} size {}", chunk_table_offset, chunk_table_size );
749+
Self::v6_align_to_4k(bootstrap_ctx)?;
739750
}
740-
ext_sb.set_chunk_table(chunk_table_offset, chunk_table_size);
741-
debug!(
742-
"chunk_table offset {} size {}",
743-
chunk_table_offset, chunk_table_size
744-
);
745-
Self::v6_align_to_4k(bootstrap_ctx)?;
746751

747752
// Prepare device slots.
748753
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
@@ -990,9 +990,9 @@ impl Command {
990990
};
991991
let config =
992992
Self::get_configuration(matches).context("failed to get configuration information")?;
993-
config
994-
.internal
995-
.set_blob_accessible(matches.get_one::<String>("config").is_some());
993+
let blob_accessible = matches.get_one::<String>("config").is_some()
994+
|| matches.get_one::<String>("blob-dir").is_some();
995+
config.internal.set_blob_accessible(blob_accessible);
996996
let mut ctx = BuildContext {
997997
prefetch: Self::get_prefetch(matches)?,
998998
..Default::default()

0 commit comments

Comments
 (0)