Skip to content
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

Makefile: build Cilium with madvdontneed=1 #14634

Merged
merged 1 commit into from
Feb 11, 2021
Merged

Conversation

aanm
Copy link
Member

@aanm aanm commented Jan 18, 2021

Setting this option makes Cilium to be compiled in a mode that will
allow it to reduce its process' RSS even if the system is not under
memory pressure.

By default, i.e. without 'madvdontneed' being set, Cilium will only
release its process' RSS when the system is under pressure. This
may be confusing for users since they will assume Cilium needs the
memory reported in RSS, which is not true.

Signed-off-by: André Martins andre@cilium.io

Make Go runtime to return unused memory to OS more often

Benchmark results:
100 node cluster with clusterloader2:
The red lines represent the beginning and end of the test

BASE VS NEW
diff

@aanm aanm added kind/performance There is a performance impact of this. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. needs-backport/1.8 labels Jan 18, 2021
@aanm aanm requested a review from a team as a code owner January 18, 2021 13:47
@aanm aanm requested a review from borkmann January 18, 2021 13:47
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.10.0 Jan 18, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.8.7 Jan 18, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.9.2 Jan 18, 2021
@aanm
Copy link
Member Author

aanm commented Jan 18, 2021

test-me-please

Copy link
Member

@borkmann borkmann left a comment

Choose a reason for hiding this comment

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

Do you have some before/after graphs for comparison?

@brb
Copy link
Member

brb commented Jan 18, 2021

I think the release note is misleading. The env setting doesn't make the mem management more efficient. Most likely in opposite, as the Go runtime will go to OS more often to beg for memory.

Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

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

Unfortunately I think this won't have any effect on the compiled binary as GODEBUG is checked at runtime: https://github.com/golang/go/blob/682a1d2176b02337460aeede0ff9e49429525195/src/runtime/runtime1.go#L367

I think we would need to set GODEBUG=madvdontneed=1 in the cilium-runtime image instead.

FWIW, Fortunately, Go 1.16 will switch back to madvdontneed=1 as the default, see https://tip.golang.org/doc/go1.16#runtime:

On Linux, the runtime now defaults to releasing memory to the operating system promptly (using MADV_DONTNEED), rather than lazily when the operating system is under memory pressure (using MADV_FREE). This means process-level memory statistics like RSS will more accurately reflect the amount of physical memory being used by Go processes. Systems that are currently using GODEBUG=madvdontneed=1 to improve memory monitoring behavior no longer need to set this environment variable.

@aanm aanm requested a review from a team as a code owner January 18, 2021 14:57
@aanm aanm requested a review from a team January 18, 2021 14:57
@aanm aanm requested a review from a team as a code owner January 18, 2021 14:57
@aanm aanm requested a review from rolinh January 18, 2021 14:57
@aanm
Copy link
Member Author

aanm commented Jan 18, 2021

test-me-please

@aanm
Copy link
Member Author

aanm commented Jan 18, 2021

test-me-please

@aanm
Copy link
Member Author

aanm commented Jan 19, 2021

retest-gke

@aanm aanm added the dont-merge/blocked Another PR must be merged before this one. label Jan 19, 2021
@aanm
Copy link
Member Author

aanm commented Jan 19, 2021

I'll try to run some tests before merging to have some idea.

@aanm aanm added this to Needs backport from master in 1.9.3 Jan 20, 2021
@aanm aanm removed this from Needs backport from master in 1.9.2 Jan 20, 2021
@aanm aanm requested a review from tklauser February 10, 2021 14:56
@aanm aanm removed the dont-merge/blocked Another PR must be merged before this one. label Feb 10, 2021
@aanm aanm marked this pull request as ready for review February 10, 2021 15:06
@aanm
Copy link
Member Author

aanm commented Feb 10, 2021

test-me-please

Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

I think this change makes sense.

While it is not clear to me whether the test numbers added by @aanm actually show the added CPU cost of MADV_FREE vs MADV_DONTNEED, I believe that this change is the right way to move forward since it's going to be adopted in 1.16 anyway, and it also solves the practical issue of better reporting of memory usage.

From the description of the change: https://go-review.googlesource.com/c/go/+/267100/, it also seems to me that the go scavenger can pace itself now to reduce the effect whatever added overhead.

I think we should go with the future default sooner rather than later, and if we came into issues we can always use madvdontneed=0.

Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

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

Could we prepend the notes to remove the ENV with a FIXME so that they are easy to find/grep?

@brb
Copy link
Member

brb commented Feb 11, 2021

@aanm you might want to still address this #14634 (comment).

Setting this option makes Cilium to run in a mode that will allow
it to reduce its process' RSS even if the system is not under
memory pressure.

By default, i.e. without 'madvdontneed' being set, Cilium will only
release its process' RSS when the system is under pressure. This
may be confusing for users since they will assume Cilium needs the
memory reported in RSS, which is not true.

Signed-off-by: André Martins <andre@cilium.io>
@aanm
Copy link
Member Author

aanm commented Feb 11, 2021

the CI was green, I just applied this suggestion #14634 (review) merging

@aanm aanm merged commit 83cb610 into cilium:master Feb 11, 2021
@aanm aanm deleted the pr/addmadvdontneed branch February 11, 2021 11:12
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.8 in 1.8.7 Feb 12, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.9 in 1.9.5 Feb 12, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.8 to Backport done to v1.8 in 1.8.7 Feb 15, 2021
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.9 to Backport done to v1.9 in 1.9.5 Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/performance There is a performance impact of this. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
No open projects
1.8.7
Backport done to v1.8
1.9.5
Backport done to v1.9
Development

Successfully merging this pull request may close these issues.

None yet

9 participants