-
Notifications
You must be signed in to change notification settings - Fork 43
pkg: oci: support OCI spec memory limit #341
Conversation
pkg/oci/utils.go
Outdated
@@ -286,6 +287,35 @@ func (spec *CompatOCISpec) PodID() (string, error) { | |||
return "", fmt.Errorf("Could not find pod ID") | |||
} | |||
|
|||
func ociResourceUpdateRuntimeConfig(ocispec CompatOCISpec, config *RuntimeConfig) error { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
pkg/oci/utils.go
Outdated
@@ -286,6 +287,35 @@ func (spec *CompatOCISpec) PodID() (string, error) { | |||
return "", fmt.Errorf("Could not find pod ID") | |||
} | |||
|
|||
func ociResourceUpdateRuntimeConfig(ocispec CompatOCISpec, config *RuntimeConfig) error { | |||
if ocispec.Linux == nil { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
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)) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@wcwxyz Global question here, why do you use [RFC] prefix ? What does that mean ? |
@sboeuf It's Request For Comment, meaning the idea or design needs to be discussed or commented. |
@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 :) |
@sboeuf Sure. Thanks for heads-up. |
:-) 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 :-) |
There was a problem hiding this comment.
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()
.
pkg/oci/utils.go
Outdated
|
||
// round up memory to 1MB | ||
mem := uint((memBytes + (1024*1024 - 1)) / (1024 * 1024)) | ||
if mem <= 0 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/oci/utils.go
Outdated
cpu := config.VMConfig.VCPUs | ||
|
||
return vc.Resources{ | ||
VCPUs: cpu, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 <[email protected]>
There was a problem hiding this comment.
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
"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 <[email protected]>
We should run VM(container) regarding OCI spec config.json memory limit.
Signed-off-by: WANG Chao [email protected]
--
This pull request resolves clearcontainers/runtime#381
The original patch is at clearcontainers/runtime#390