Skip to content

Conversation

@kzys
Copy link
Member

@kzys kzys commented Sep 3, 2021

Most of bytes.Buffer in stargz-snapshotter is unbounded in terms of
size and sync.Pool's Get may choose to ignore the pool.

Resizing a buffer before returning to the pool may alleviate the
snapshotter's memory utilization issue.

golang/go#23199 has a long discussion about
the issue.

Signed-off-by: Kazuyoshi Kato [email protected]

Most of bytes.Buffer in stargz-snapshotter is unbounded in terms of
size and sync.Pool's Get may choose to ignore the pool.

Resizing a buffer before returning to the pool may alleviate the
snapshotter's memory utilization issue.

golang/go#23199 has a long discussion about
the issue.

Signed-off-by: Kazuyoshi Kato <[email protected]>
}

func (dc *directoryCache) putBuffer(b *bytes.Buffer) {
b.Reset()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Use temporally buffer for aligning this chunk
b := sf.gr.bufPool.Get().(*bytes.Buffer)
b.Reset()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remain Reset before use for safety?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but would it have real effects? Get() returns either a new Buffer, which is safe to use according to https://cs.opensource.google/go/go/+/refs/tags/go1.17:src/bytes/buffer.go;l=449

In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.

or a buffer which is put by putBuffer().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think you are right. Merging.

@ktock ktock merged commit 1d81483 into containerd:main Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants