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

Compact memory before requesting huge pages #82656

Merged
merged 1 commit into from
Oct 18, 2019

Conversation

odinuge
Copy link
Member

@odinuge odinuge commented Sep 12, 2019

What type of PR is this?
/kind flake

What this PR does / why we need it:
Compact memory to make bigger contiguous blocks of memory available
before allocating huge pages.

https://www.kernel.org/doc/Documentation/sysctl/vm.txt

Which issue(s) this PR fixes:

ref #81726

Special notes for your reviewer:

/sig node
/sig testing

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/flake Categorizes issue or PR as related to a flaky test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 12, 2019
@odinuge odinuge changed the title Drop kernel caches before requesting huge pages Drop kernel caches before requesting huge pages in tests Sep 12, 2019
@odinuge
Copy link
Member Author

odinuge commented Sep 12, 2019

/cc mattjmcnaughton
/cc oomichi

Copy link
Contributor

@mattjmcnaughton mattjmcnaughton left a comment

Choose a reason for hiding this comment

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

Thanks for this pr :)

Some high level requests from me around comments/documentation before I review :) want to be sure I know what I'm reviewing haha and I'm far from a huge pages expert :)

@@ -85,7 +85,14 @@ func makePodToVerifyHugePages(baseName string, hugePagesLimit resource.Quantity)

// configureHugePages attempts to allocate 10Mi of 2Mi hugepages for testing purposes
func configureHugePages() error {
err := exec.Command("/bin/sh", "-c", "echo 5 > /proc/sys/vm/nr_hugepages").Run()
// Drop all kernel caches to make sure we can get the requested amount of huge pages
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please expand on how dropping the kernel caches is necessary to ensure we get the requested amount of huge pages?

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing I forgot to say... thank you for linking the kernel docs! That is helpful :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Still curious about the answer to the specific q in my first comment when you get a chance :) Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi,

After some more research, it looks like running memory compaction is more reasonable.

This is the docs from kernel.org about /proc/sys/vm/compact_memory:

Available only when CONFIG_COMPACTION is set. When 1 is written to the file,
all zones are compacted such that free memory is available in contiguous
blocks where possible. This can be important for example in the allocation of
huge pages although processes will also directly compact memory as required.

I have updated the PR to use that instead. Thoughts?

// Drop all kernel caches to make sure we can get the requested amount of huge pages
// This will only affect kernel level cache hit, and nothing visible in userspace
// https://www.kernel.org/doc/Documentation/sysctl/vm.txt
err := exec.Command("/bin/sh", "-c", "echo 3 > /proc/sys/vm/drop_caches").Run()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the k8s tests running as root? I'm a little surprised that a test would have permissions to run this command (especially on the k8s CI)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi,
Yes, and they have to!

The same permissions apply to the pre allocation of huge pages (see 2-3 lines below) by writing to /proc/sys/vm/nr_hugepages 😄

@mattjmcnaughton
Copy link
Contributor

mattjmcnaughton commented Sep 17, 2019 via email

Compact memory to make bigger contiguous blocks of memory available
before allocating huge pages.

https://www.kernel.org/doc/Documentation/sysctl/vm.txt
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 17, 2019
@odinuge odinuge changed the title Drop kernel caches before requesting huge pages in tests Compact memory before requesting huge pages Sep 17, 2019
@oomichi
Copy link
Member

oomichi commented Sep 17, 2019

The change itself is good for me according to the Linux doc which is specified in this PR:

compact_memory

Available only when CONFIG_COMPACTION is set. When 1 is written to the file,
all zones are compacted such that free memory is available in contiguous
blocks where possible. This can be important for example in the allocation of
huge pages although processes will also directly compact memory as required.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 17, 2019
@odinuge
Copy link
Member Author

odinuge commented Sep 17, 2019

/assign @tallclair

Copy link
Contributor

@mattjmcnaughton mattjmcnaughton left a comment

Choose a reason for hiding this comment

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

/lgtm

I don't see any harm in trying this out. It's still not immediately clear if we are seeing actual errors because this doesn't exist, or its more of a preventative measure.

Also, confirming that CONFIG_COMPACTION is set re the documentation?

test/e2e_node/hugepages_test.go Show resolved Hide resolved
@odinuge
Copy link
Member Author

odinuge commented Sep 19, 2019

Thanks for the review @mattjmcnaughton!

I don't see any harm in trying this out. It's still not immediately clear if we are seeing actual errors because this doesn't exist, or its more of a preventative measure.

Tests like this will flake once in a while, but compacting memory before trying to allocate huge page memory should reduce the amount of flakes by a fair share. Since we only allocate 10MiB of 2MiB pages, it should more or less never flake.

Also, confirming that CONFIG_COMPACTION is set re the documentation?

It is quite difficult to check kernel config at runtime since it depends on what version it is running, and what distro it is. The file /proc/sys/vm/compact_memory will only be present if CONFIG_COMPACTION=y, and the code verifies that the file exists before trying to write to it. 😄

@odinuge
Copy link
Member Author

odinuge commented Sep 19, 2019

/cc @alejandrox1

@mattjmcnaughton
Copy link
Contributor

mattjmcnaughton commented Sep 20, 2019 via email

@alejandrox1
Copy link
Contributor

im a bit late to the party but thank you for working on this @odinuge !
/priority important-longterm
/milestone v1.17

/assign @Random-Liu @derekwaynecarr @ConnorDoyle
ptal

@k8s-ci-robot k8s-ci-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label Oct 1, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.17 milestone Oct 1, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Oct 1, 2019
@oomichi
Copy link
Member

oomichi commented Oct 18, 2019

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: odinuge, oomichi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 18, 2019
@k8s-ci-robot k8s-ci-robot merged commit edfffff into kubernetes:master Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/flake Categorizes issue or PR as related to a flaky test. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants