Skip to content
This repository was archived by the owner on Apr 3, 2018. It is now read-only.

pkg: oci: support OCI spec memory limit - #341

Merged
sboeuf merged 1 commit into
containers:masterfrom
wcwxyz:per-container-memory
Aug 16, 2017
Merged

sboeuf merged 1 commit into
containers:masterfrom
wcwxyz:per-container-memory

Conversation

@wcwxyz

@wcwxyz wcwxyz commented Aug 15, 2017 •

Copy link
Copy Markdown
Contributor

We should run VM(container) regarding OCI spec config.json memory limit.

Signed-off-by: WANG Chao chao.wang@ucloud.cn

--

This pull request resolves clearcontainers/runtime#381
The original patch is at clearcontainers/runtime#390

@coveralls

coveralls commented Aug 15, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 66.502% when pulling a2fa066 on wcwxyz:per-container-memory into 58ebe95 on containers:master.

@wcwxyz wcwxyz changed the title pkg: oci: support OCI spec memory limit [RFC] pkg: oci: support OCI spec memory limit Aug 15, 2017
Comment thread pkg/oci/utils.go Outdated
return "", fmt.Errorf("Could not find pod ID")
}

func ociResourceUpdateRuntimeConfig(ocispec CompatOCISpec, config *RuntimeConfig) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please create instead a function:

func vmConfig(ocispec CompatOCISpec, runtime RuntimeConfig) (Resources, error) {
    ...
}

In case there is no memory limit defined by the config.json file, we fallback to what is provided by RuntimeConfig. Otherwise, we take the value provided by the config.json.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Comment thread pkg/oci/utils.go Outdated
}

func ociResourceUpdateRuntimeConfig(ocispec CompatOCISpec, config *RuntimeConfig) error {
if ocispec.Linux == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make sure you gather all the statements together as they end up with the same result:

if ocispec.Linux == nil ||
   ocispec.Linux.Resources == nil ||
   ocispec.Linux.Resources.Memory == nil ||
   ocispec.Linux.Resources.Memory.Limit == nil {
	return nil
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Comment thread pkg/oci/utils.go Outdated
memBytes := *ocispec.Linux.Resources.Memory.Limit

// round up memory bytes to MB
mem := int(math.Ceil(float64(memBytes) / 1024 / 1024))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't need that much precision, I think this should be enough

mem := uint(memBytes / (1024 * 1024))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm ok with less precision, because this is trivial.

But @grahamwhaley suggested that we should round up at clearcontainers/runtime#390 (comment). I just quoted here:

maybe we should round this up. Docker allows fine granularity (down to bytes). I think it is probably better we allocate more than requested rather than too little

@grahamwhaley what do you think now?

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 still think rounding up is the technically right thing to do. I'd rather hand a container slightly more than requested, rather than artificially starve it. tbh though, the amount we are likely to drop as a % from not rounding up is tiny - given the smallest memory we can probably support might be 128m or so.
If we don't like the float math, we could do something integer like this to round up:

mem = (memBytes + ((1024*1024)-1))) / (1024*1024)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@grahamwhaley yes I like this one, you add 1MiB to make sure we round this up. My main concern was to avoid playing with float64 numbers whilst we don't really need that much precision.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @grahamwhaley @sboeuf . I'll update the patch.

@sboeuf

sboeuf commented Aug 16, 2017

Copy link
Copy Markdown
Collaborator

@wcwxyz Global question here, why do you use [RFC] prefix ? What does that mean ?

@wcwxyz

wcwxyz commented Aug 16, 2017

Copy link
Copy Markdown
Contributor Author

@sboeuf It's Request For Comment, meaning the idea or design needs to be discussed or commented.

@sboeuf

sboeuf commented Aug 16, 2017

Copy link
Copy Markdown
Collaborator

@wcwxyz oh okay, I didn't know. I think you can remove it since we consider every PR as something we want to review thoroughly :)

@wcwxyz

wcwxyz commented Aug 16, 2017

Copy link
Copy Markdown
Contributor Author

@sboeuf Sure. Thanks for heads-up.

@wcwxyz wcwxyz changed the title [RFC] pkg: oci: support OCI spec memory limit pkg: oci: support OCI spec memory limit Aug 16, 2017
@grahamwhaley

Copy link
Copy Markdown
Contributor

:-) RFC sort of comes from here: https://www.ietf.org/rfc.html, but funnily enough most of those RFCs pretty much become 'standards', but are still called RFCs :-)
Adding RFC here I think is fine, it is a common idiom - but, you should probably also add our 'do-not-merge' github label at the same time, to indicate this is something to discuss and work on and not to immediately merge, until agreement has been found.

@coveralls

coveralls commented Aug 16, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 66.527% when pulling 551b0ec on wcwxyz:per-container-memory into af35aeb on containers:master.

@sboeuf sboeuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two tiny comments here.
Also, could you please add some unit tests for vmConfig().

Comment thread pkg/oci/utils.go Outdated

// round up memory to 1MB
mem := uint((memBytes + (1024*1024 - 1)) / (1024 * 1024))
if mem <= 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should check memBytes instead of mem, that's the one which could be negative. You should make this check right after you retrieved memBytes value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. I missed this one while updating my code last time.

Comment thread pkg/oci/utils.go Outdated
cpu := config.VMConfig.VCPUs

return vc.Resources{
VCPUs: cpu,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Assign directly VCPUs to config.VMConfig.VCPUs here. If we need to use a temporary variable for later, let's do that in a follow up patch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will update.

We should run VM(container) regarding OCI spec config.json memory limit.

Signed-off-by: WANG Chao <chao.wang@ucloud.cn>
@coveralls

coveralls commented Aug 16, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 66.527% when pulling 1b02f69 on wcwxyz:per-container-memory into af35aeb on containers:master.

@sboeuf sboeuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changes :)
LGTM

@sboeuf
sboeuf merged commit 710c4bb into containers:master Aug 16, 2017
jodh-intel pushed a commit to jodh-intel/runtime that referenced this pull request Sep 8, 2017
"docker run -m" is now supported [1], so it no longer needs to be
specified in the limitations document.

Partially fixes clearcontainers#494.

[1] - See containers/virtcontainers#341 and
clearcontainers#381.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support docker run -m MEMORY memory resource constraint/definition

4 participants