Skip to content

Commit

Permalink
rafs: do not include chunk info array in the metadata blob
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jiangliu committed Mar 17, 2023
1 parent c9d9b43 commit aa13eb5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
49 changes: 27 additions & 22 deletions rafs/src/builder/core/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use storage::device::BlobFeatures;

use super::chunk_dict::DigestWithBlobIndex;
use super::node::Node;
use crate::builder::{Bootstrap, BootstrapContext, BuildContext, ConversionType, Tree};
use crate::builder::{Bootstrap, BootstrapContext, BuildContext, ConversionType, Feature, Tree};
use crate::metadata::chunk::ChunkWrapper;
use crate::metadata::inode::new_v6_inode;
use crate::metadata::layout::v6::{
Expand All @@ -41,7 +41,7 @@ impl Node {
f_bootstrap: &mut dyn RafsIoWrite,
orig_meta_addr: u64,
meta_addr: u64,
chunk_cache: &mut BTreeMap<DigestWithBlobIndex, Arc<ChunkWrapper>>,
chunk_cache: Option<&mut BTreeMap<DigestWithBlobIndex, Arc<ChunkWrapper>>>,
) -> Result<()> {
let xattr_inline_count = self.info.xattrs.count_v6();
ensure!(
Expand Down Expand Up @@ -69,7 +69,9 @@ impl Node {
if self.is_dir() {
self.v6_dump_dir(ctx, f_bootstrap, meta_addr, meta_offset, &mut inode)?;
} else if self.is_reg() {
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode)?;
if let Some(chunk_cache) = chunk_cache {
self.v6_dump_file(ctx, f_bootstrap, chunk_cache, &mut inode)?;
}
} else if self.is_symlink() {
self.v6_dump_symlink(ctx, f_bootstrap, &mut inode)?;
} else {
Expand Down Expand Up @@ -685,7 +687,11 @@ impl Bootstrap {
// Each layer uses the corresponding chunk in the blob of its own layer.
// If HashChunkDict is used here, it will cause duplication. The chunks are removed,
// resulting in incomplete chunk info.
let mut chunk_cache = BTreeMap::new();
let mut chunk_cache = if ctx.features.is_enabled(Feature::BlobToc) {
None
} else {
Some(BTreeMap::new())
};

// Dump bootstrap
timing_tracer!(
Expand All @@ -696,7 +702,7 @@ impl Bootstrap {
bootstrap_ctx.writer.as_mut(),
orig_meta_addr,
meta_addr,
&mut chunk_cache,
chunk_cache.as_mut(),
)
.context("failed to dump bootstrap")?;
}
Expand Down Expand Up @@ -725,24 +731,23 @@ impl Bootstrap {
}

// TODO: get rid of the chunk info array.
// Dump chunk info array.
let chunk_table_offset = bootstrap_ctx
.writer
.seek_to_end()
.context("failed to seek to bootstrap's end for chunk table")?;
let mut chunk_table_size: u64 = 0;
for (_, chunk) in chunk_cache.iter() {
let chunk_size = chunk
.store(bootstrap_ctx.writer.as_mut())
.context("failed to dump chunk table")?;
chunk_table_size += chunk_size as u64;
if let Some(chunk_cache) = chunk_cache.as_ref() {
// Dump chunk info array.
let chunk_table_offset = bootstrap_ctx
.writer
.seek_to_end()
.context("failed to seek to bootstrap's end for chunk table")?;
let mut chunk_table_size: u64 = 0;
for (_, chunk) in chunk_cache.iter() {
let chunk_size = chunk
.store(bootstrap_ctx.writer.as_mut())
.context("failed to dump chunk table")?;
chunk_table_size += chunk_size as u64;
}
ext_sb.set_chunk_table(chunk_table_offset, chunk_table_size);
debug!( "chunk_table offset {} size {}", chunk_table_offset, chunk_table_size );
Self::v6_align_to_4k(bootstrap_ctx)?;
}
ext_sb.set_chunk_table(chunk_table_offset, chunk_table_size);
debug!(
"chunk_table offset {} size {}",
chunk_table_offset, chunk_table_size
);
Self::v6_align_to_4k(bootstrap_ctx)?;

// Prepare device slots.
let mut pos = bootstrap_ctx
Expand Down
6 changes: 3 additions & 3 deletions src/bin/nydus-image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,9 +990,9 @@ impl Command {
};
let config =
Self::get_configuration(matches).context("failed to get configuration information")?;
config
.internal
.set_blob_accessible(matches.get_one::<String>("config").is_some());
let blob_accessible = matches.get_one::<String>("config").is_some()
|| matches.get_one::<String>("blob-dir").is_some();
config.internal.set_blob_accessible(blob_accessible);
let mut ctx = BuildContext {
prefetch: Self::get_prefetch(matches)?,
..Default::default()
Expand Down

0 comments on commit aa13eb5

Please sign in to comment.