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

feature: add kernel-memory support in cli and ctrd #2717

Merged
merged 1 commit into from
Apr 2, 2019

Conversation

allencloud
Copy link
Collaborator

Signed-off-by: Allen Sun allensun.shl@alibaba-inc.com

Ⅰ. Describe what this PR did

This feature add kernel-memory support in cli part and containerd part.

Actually we have add KernelMemory in swagger.yml in https://github.com/alibaba/pouch/blob/master/apis/swagger.yml#L2676. Then in the API side, this field has been supported in the struct definition of Resource.

However in the daemon side, we have not set it in the LinuxResource of runc. Then there is no way to set kernel memory for PouchContainer.

This PR tries to fix that, and this pr did:

  • add kernel-memory flag in cli side;
  • deal kernel-memory in daemon side to insert it for containerd;
  • add kernel-memory checking in test case and refactor memory test case to add memory checking.

Ⅱ. Does this pull request fix one issue?

fix #2716

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

added

Ⅳ. Describe how to verify it

none

Ⅴ. Special notes for reviews

none

@codecov
Copy link

codecov bot commented Feb 19, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@572c732). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2717   +/-   ##
=========================================
  Coverage          ?   69.29%           
=========================================
  Files             ?      277           
  Lines             ?    17433           
  Branches          ?        0           
=========================================
  Hits              ?    12081           
  Misses            ?     4018           
  Partials          ?     1334
Flag Coverage Δ
#criv1alpha2_test 39.23% <40%> (?)
#integration_test_0 36.64% <40%> (?)
#integration_test_1 35.39% <0%> (?)
#integration_test_2 36.51% <60%> (?)
#integration_test_3 35.43% <0%> (?)
#node_e2e_test 35.14% <0%> (?)
#unittest 28.51% <0%> (?)
Impacted Files Coverage Δ
ctrd/utils.go 83.33% <100%> (ø)
daemon/mgr/spec_linux.go 79% <100%> (ø)

@@ -35,73 +35,88 @@ func (suite *PouchRunMemorySuite) TearDownTest(c *check.C) {

// TestRunWithMemoryswap is to verify the valid running container
// with --memory-swap
func (suite *PouchRunMemorySuite) TestRunWithMemoryswap(c *check.C) {
func (suite *PouchRunMemorySuite) TestRunWithMemoryswapAndKernelMemory(c *check.C) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we add the case for default value of kernel memory?

path = fmt.Sprintf("/sys/fs/cgroup/memory/default/%s/memory.memsw.limit_in_bytes", containerID)
checkFileContains(c, path, expectedMemSwap)
path = fmt.Sprintf("/sys/fs/cgroup/memory/default/%s/memory.kmem.usage_in_bytes", containerID)
checkFileContains(c, path, expectedKernelMem)
Copy link
Contributor

Choose a reason for hiding this comment

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

something wrong here

FAIL: cli_run_memory_test.go:38: PouchRunMemorySuite.TestRunWithMemoryswapAndKernelMemory


cli_run_memory_test.go:79:

    checkFileContains(c, path, expectedKernelMem)

cli_run_test.go:248:
    c.Assert(strings.Contains(string(cmdResult.Stdout()), expt),
        check.Equals, true)
... obtained bool = false
... expected bool = true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I should use memory.kmem.limit_in_bytes rather than memory.kmem.usage_in_bytes. Updated.

import units "github.com/docker/go-units"

// ParseKernelMemory parses the kernel memory param of container.
func ParseKernelMemory(kmem string) (int64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get all memory-related functions into one file, xxx/memory.go, there are too many file now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea. Could we do that in a separate PR?

sleep := "10000"
kernelMemory := "100m"
expectedMem := strconv.Itoa(100 * 1024 * 1024) // 100 MB
expectedKernelMem := strconv.Itoa(1024 * 1024 * 100) // 100 MB
Copy link
Contributor

Choose a reason for hiding this comment

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

I think kernel memory test should be single test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually both are OK. My concern is that if we combine the test case, we can reduce the CI time. It is a tradeoff.

@fuweid
Copy link
Contributor

fuweid commented Feb 25, 2019

@allencloud any update here?

@allencloud
Copy link
Collaborator Author

Could we kick the ball and make this move on? I think it will influence the @ireneYang 's scenario.
@fuweid

Signed-off-by: Allen Sun <allensun.shl@alibaba-inc.com>
Copy link
Contributor

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

@fuweid fuweid merged commit 856fc68 into AliyunContainerService:master Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] add support to config limit size of kmem
4 participants