Repository navigation
pkg: oci: support OCI spec memory limit - #341
Conversation
| return "", fmt.Errorf("Could not find pod ID") | ||
| } | ||
|
|
||
| func ociResourceUpdateRuntimeConfig(ocispec CompatOCISpec, config *RuntimeConfig) error { |
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| func ociResourceUpdateRuntimeConfig(ocispec CompatOCISpec, config *RuntimeConfig) error { | ||
| if ocispec.Linux == nil { |
There was a problem hiding this comment.
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
}| 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.
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.
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.
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.
@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.
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 :-) |
sboeuf
left a comment
There was a problem hiding this comment.
Two tiny comments here.
Also, could you please add some unit tests for vmConfig().
|
|
||
| // round up memory to 1MB | ||
| mem := uint((memBytes + (1024*1024 - 1)) / (1024 * 1024)) | ||
| if mem <= 0 { |
There was a problem hiding this comment.
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.
You're right. I missed this one while updating my code last time.
| cpu := config.VMConfig.VCPUs | ||
|
|
||
| return vc.Resources{ | ||
| VCPUs: cpu, |
There was a problem hiding this comment.
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.
We should run VM(container) regarding OCI spec config.json memory limit. Signed-off-by: WANG Chao <chao.wang@ucloud.cn>
sboeuf
left a comment
There was a problem hiding this comment.
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 <james.o.hunt@intel.com>
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