-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for calculating virtual image size as well. #1918
Conversation
057538e
to
eb885bb
Compare
This shouldn't be same? |
pkg/cmd/image/list.go
Outdated
// https://github.com/moby/moby/blob/65c371ed6e48d0014a4826a6933f9231f688327a/daemon/containerd/image_list.go#L184-L194 | ||
// What is VirtualSize: https://github.com/docker/docs/issues/1520#issuecomment-305179362 | ||
func computeVirtualSize(ctx context.Context, s snapshots.Snapshotter, img containerd.Image) (int64, error) { | ||
chainIDs, err := img.RootFS(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diffIDs, not chainID
https://github.com/opencontainers/image-spec/blob/v1.1.0-rc2/config.md#layer-chainid
pkg/cmd/image/list.go
Outdated
} | ||
var virtualSize int64 | ||
for _, chainID := range chainIDs { | ||
usage, err := s.Usage(ctx, chainID.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we cache this to avoid calculating the usage twice
See: docker/docs#16315 Also this: moby/moby#43862 :/ |
28c774c
to
2464f7f
Compare
@AkihiroSuda I made the change equivalent to moby's containerd implementation. Should we keep blob size now or remove it? |
@fahedouch Can you please have a look? Let me know what do you think? |
pkg/cmd/image/list.go
Outdated
//add ChainID's parent usage to the total usage | ||
if err := snapshotKey(info.Parent).add(ctx, s, &usage); err != nil { | ||
return 0, err | ||
virtualSize += usage.Size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the container writable layer
counted here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For images; it is zero; so it really does not matter.
For containers; the writable layer size will be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that VirtualSize
= blob size
+ writable layer size
but here you are not counting the writable layer size (before your modification it was counted by adding the parent of most top DiffId
size to the total size)
What I did in the past is
- calculate the
chainID
of the readonly layer - add
chainID
size to the total size - calculate the
chainID
parent size ( writable layer) - add the
chainID
parent size to the total size
info, err := s.Stat(ctx, chainID)
if err != nil {
return 0, err
}
//add ChainID's parent usage to the total usage
if err := snapshotKey(info.Parent).add(ctx, s, &usage); err != nil {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fahedouch Sorry for the late response. I have updated this PR; the previous behavior was correct and when I read through the moby issue; this is the behavior that we want.
However, now containerd provides withSnapshotUsage so we can re-use it. I have refactored the code and also added the field for VirtualSize.
Please let me know if this sounds good to you. I can write tests if this sounds good to you.
pkg/cmd/image/list.go
Outdated
@@ -304,7 +303,8 @@ func (x *imagePrinter) printImageSinglePlatform(ctx context.Context, img images. | |||
Tag: tag, | |||
Name: img.Name, | |||
Size: progress.Bytes(size).String(), | |||
BlobSize: progress.Bytes(blobSize).String(), | |||
VirtualSize: progress.Bytes(virtualSize).String(), | |||
BlobSize: progress.Bytes(size).String(), // Was introduced since docker had a different behavior earlier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need BlobSize
here ? I think we should keep either size
or BlobSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep Size (needed your opinion on it).
This will make tests docker incompatible until docker moves to containerd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
@@ -177,7 +175,8 @@ type imagePrintable struct { | |||
Name string // image name | |||
Size string // the size of the unpacked snapshots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since your modification // the size of the unpacked snapshots.
=> wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please check my comment above.
6866ce5
to
07a9347
Compare
Signed-off-by: Manu Gupta <manugupt1@gmail.com>
@@ -245,6 +246,7 @@ func (x *imagePrinter) printImageSinglePlatform(ctx context.Context, img images. | |||
Tag: tag, | |||
Name: img.Name, | |||
Size: progress.Bytes(size).String(), | |||
VirtualSize: progress.Bytes(size).String(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs comment lines to explain why these are same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs integration tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! Wanted to get an initial look. Will add by the end of this week.
Thanks!
@@ -119,6 +119,7 @@ type imagePrintable struct { | |||
Name string // image name | |||
Size string // the size of the unpacked snapshots. | |||
BlobSize string // the size of the blobs in the content store (nerdctl extension) | |||
VirtualSize string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment line
} | ||
return usage.Size, nil | ||
func UnpackedImageSize(ctx context.Context, img containerd.Image) (int64, error) { | ||
return img.Usage(ctx, containerd.WithSnapshotUsage()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just a refactoring, or does this change the computed size?
Could you consider making this a separate commit/PR ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not change the computed size at all. I verified locally.
@fahedouch Ping |
Even the sizes are inconistent now with docker and nerdctl. |
@manugupt1 why closing this ? |
I mostly closed this because of moby/moby#45180 |
Testing details