Skip to content

cmd/containerd-shim: aggressive memory reclamation#2055

Merged
stevvooe merged 1 commit intocontainerd:masterfrom
stevvooe:aggressive-memory-shim
Jan 25, 2018
Merged

cmd/containerd-shim: aggressive memory reclamation#2055
stevvooe merged 1 commit intocontainerd:masterfrom
stevvooe:aggressive-memory-shim

Conversation

@stevvooe
Copy link
Copy Markdown
Member

@stevvooe stevvooe commented Jan 24, 2018

To avoid having the shim hold on to too much memory, we've made a few
adjustments to favor more aggressive reclamation of memory from the
operating system. Typically, this would be negligible, on the order of a
few megabytes, but this is impactful when running several containers.

The first fix is to lower the threshold used to determine when to run
the garbage collector. The second runs runtime/debug.FreeOSMemory at a
regular interval.

Under test, this result in a sustained memory usage of around 3.7 MB.

Fixes #2020

Signed-off-by: Stephen J Day [email protected]

To avoid having the shim hold on to too much memory, we've made a few
adjustments to favor more aggressive reclamation of memory from the
operating system. Typically, this would be negligible, on the order of a
few megabytes, but this is impactful when running several containers.

The first fix is to lower the threshold used to determine when to run
the garbage collector. The second runs `runtime/debug.FreeOSMemory` at a
regular interval.

Under test, this result in a sustained memory usage of around 3.7 MB.

Signed-off-by: Stephen J Day <[email protected]>
@stevvooe stevvooe added this to the 1.0.2 milestone Jan 24, 2018
}

func main() {
debug.SetGCPercent(10)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good, but could/should these be configurable to let folks tune?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can add a flag on the shim post merge, i'm cool with that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How does -Xio.containerd.ShimMemoryUsage=keepitlow sound?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd prefer a runtime flag instead of a build time one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mlaventure Sorry, this was a JVM joke.

We can add a flag in a follow up, but I don't think it is important to tune for this use case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah 😅, I don't Java ;-)

Copy link
Copy Markdown
Member

@mikebrow mikebrow Jan 25, 2018

Choose a reason for hiding this comment

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

Yes, not tuning for "just" this use case was the point of my let it be configurable comment :-)

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #2055 into master will decrease coverage by 4.92%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2055      +/-   ##
==========================================
- Coverage   50.35%   45.43%   -4.93%     
==========================================
  Files          84       96      +12     
  Lines        7393     9429    +2036     
==========================================
+ Hits         3723     4284     +561     
- Misses       2964     4435    +1471     
- Partials      706      710       +4
Flag Coverage Δ
#linux 50.35% <ø> (ø) ⬆️
#windows 40.31% <ø> (?)
Impacted Files Coverage Δ
fs/path.go 60.69% <0%> (-12.56%) ⬇️
oci/spec.go 40% <0%> (-10%) ⬇️
snapshots/naive/naive.go 43.89% <0%> (-10%) ⬇️
metadata/snapshot.go 45.95% <0%> (-8.96%) ⬇️
archive/compression/compression.go 43.93% <0%> (-8.9%) ⬇️
remotes/docker/fetcher.go 41.42% <0%> (-7.6%) ⬇️
content/local/writer.go 52.63% <0%> (-7.37%) ⬇️
fs/copy.go 34.83% <0%> (-7.2%) ⬇️
archive/tar.go 43.25% <0%> (-6.9%) ⬇️
metadata/containers.go 47.31% <0%> (-6.4%) ⬇️
... and 61 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d32d9e...0e8f084. Read the comment docs.

@crosbymichael
Copy link
Copy Markdown
Member

LGTM

Copy link
Copy Markdown
Contributor

@mlaventure mlaventure left a comment

Choose a reason for hiding this comment

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

LGTM

@stevvooe stevvooe merged commit 3fcc52b into containerd:master Jan 25, 2018
@stevvooe stevvooe deleted the aggressive-memory-shim branch January 25, 2018 00:07
crosbymichael referenced this pull request Jan 25, 2018
[release/1.0] cmd/containerd-shim: aggressive memory reclamation
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.

The containerd-shim consume 8M memory.

5 participants