Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/orchestrator/pkg/sandbox/block/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (c *Cache) Dedup(
if err != nil {
return nil, nil, err
}
recordDedupAttrs(ctx, plan, compareDur, time.Since(writeStart))
recordDedupAttrs(ctx, plan, int64(plan.pageEmpty.GetCardinality()), compareDur, time.Since(writeStart))

return cache, &header.DiffMetadata{
Dirty: plan.pageDirty,
Expand Down
6 changes: 4 additions & 2 deletions packages/orchestrator/pkg/sandbox/block/dedup.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,12 @@ func parentKeyGroups(pages []dedupPageInfo) [][]int {
return groups
}

func recordDedupAttrs(ctx context.Context, plan *dedupPlan, compareDur, writeDur time.Duration) {
// recordDedupAttrs takes emptyPages explicitly because the memfd path merges
// the whole-VM inputEmpty bitmap into plan.pageEmpty in place before this
// runs; the caller captures the scan-only count first.
func recordDedupAttrs(ctx context.Context, plan *dedupPlan, emptyPages int64, compareDur, writeDur time.Duration) {
totalPages := plan.exportedSize / header.PageSize
uniquePages := int64(plan.pageDirty.GetCardinality())
emptyPages := int64(plan.pageEmpty.GetCardinality())
dedupedPages := totalPages - uniquePages - emptyPages
ratio := 0.0
if totalPages > 0 {
Expand Down
14 changes: 11 additions & 3 deletions packages/orchestrator/pkg/sandbox/block/memfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/e2b-dev/infra/packages/shared/pkg/logger"
"github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
"github.com/e2b-dev/infra/packages/shared/pkg/utils"
)

Expand Down Expand Up @@ -290,13 +291,20 @@ func (d *DedupedMemfdCache) runDedup(
return
}

meta := &header.DiffMetadata{Dirty: plan.pageDirty, Empty: plan.pageEmpty, BlockSize: header.PageSize}
// Capture the scan-only zero count before inputEmpty is merged in place:
// dedup.empty_pages must report content-detected zeros, not whole-VM
// empties (cloning the bitmap to preserve it would be too expensive).
scanEmptyPages := int64(plan.pageEmpty.GetCardinality())
if inputEmpty != nil {
ratio := uint64(blockSize / header.PageSize)
for start, end := range inputEmpty.Ranges() {
meta.Empty.AddRange(uint64(start)*ratio, end*ratio)
plan.pageEmpty.AddRange(uint64(start)*ratio, end*ratio)
}
}
meta := &header.DiffMetadata{Dirty: plan.pageDirty, Empty: plan.pageEmpty, BlockSize: header.PageSize}
// Whole-VM empty set recorded in the header (scan zeros + inputEmpty).
telemetry.SetAttributes(ctx,
attribute.Int64("dedup.header_empty_pages", int64(plan.pageEmpty.GetCardinality())))
logSetOnceErr(ctx, "dedup metaOut", metaOut.SetValue(meta))

writeStart := time.Now()
Expand All @@ -306,7 +314,7 @@ func (d *DedupedMemfdCache) runDedup(
logger.L().Warn(ctx, "close memfd after dedup drain", zap.Error(closeErr))
}

recordDedupAttrs(ctx, plan, compareDur, writeDur)
recordDedupAttrs(ctx, plan, scanEmptyPages, compareDur, writeDur)
logSetOnceErr(ctx, "dedup done", d.done.SetResult(cache, err))
}

Expand Down
Loading