8000 LCOW: adds memory limit for linux containers by bruegth · Pull Request #35955 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

LCOW: adds memory limit for linux containers #35955

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

Closed
wants to merge 2 commits into from
Closed

LCOW: adds memory limit for linux containers #35955

wants to merge 2 commits into from

Conversation

bruegth
Copy link
@bruegth bruegth commented Jan 8, 2018

- What I did
LCOW: adds memory limit to linux containers
Because if omitted a Hyper-V container is limited to 1GB and couldn't changed.

- How I did it
copy and paste from windows container creation

- How to verify it
run meminfo in linux container under windows

- Description for the changelog

LCOW: Adds memory limit for linux containers

- A picture of a cute animal (not mandatory but encouraged)

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "lcow-adds-memory-limit-to-linux-containers" git@github.com:bruegth/moby.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@GordonTheTurtle GordonTheTurtle added dco/no Automatically set by a bot when one of the commits lacks proper signature status/0-triage labels Jan 8, 2018
Signed-off-by: Thomas Brueggemann <thomas.brueggemann@wuh-group.com>
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Jan 8, 2018
@yongtang
Copy link
Member
yongtang commented Jan 9, 2018

/cc @jhowardmsft

@@ -418,6 +418,13 @@ func (c *client) createLinux(id string, spec *specs.Spec, runtimeOptions interfa
}
configuration.NetworkSharedContainerName = spec.Windows.Network.NetworkSharedContainerName
}

// Add memory limit (if omittet the memory will be limited to default (1GB) in Hyper-V isolation)
if spec.Windows.Resources.Memory != nil {
Copy link
Member

Choose a reason for hiding this comment

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

These don't need to be nested - the second if won't be evaluated if the first is false.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow. The first is required in case specs.Windows.Resources.Memory is nil, right?

@lowenna
Copy link
Member
lowenna commented Jan 9, 2018

@johnstep PTAL

@@ -418,6 +418,13 @@ func (c *client) createLinux(id string, spec *specs.Spec, runtimeOptions interfa
}
configuration.NetworkSharedContainerName = spec.Windows.Network.NetworkSharedContainerName
}

// Add memory limit (if omittet the memory will be limited to default (1GB) in Hyper-V isolation)
Copy link
Member

Choose a reason for hiding this comment

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

s/omittet/omitted/

@@ -418,6 +418,13 @@ func (c *client) createLinux(id string, spec *specs.Spec, runtimeOptions interfa
}
configuration.NetworkSharedContainerName = spec.Windows.Network.NetworkSharedContainerName
}

// Add memory limit (if omittet the memory will be limited to default (1GB) in Hyper-V isolation)
if spec.Windows.Resources.Memory != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow. The first is required in case specs.Windows.Resources.Memory is nil, right?


// Add memory limit (if omittet the memory will be limited to default (1GB) in Hyper-V isolation)
if spec.Windows.Resources.Memory != nil {
if spec.Windows.Resources.Memory.Limit != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I'm super confused; spec.Windows.Resources controls resources for Linux containers? I'm worried that we'll now be duplicating all functionality that's already covered by standard Linux containers;

// Linux is platform-specific configuration for Linux based containers.
Linux *Linux `json:"linux,omitempty" platform:"linux"`
// Solaris is platform-specific configuration for Solaris based containers.
Solaris *Solaris `json:"solaris,omitempty" platform:"solaris"`
// Windows is platform-specific configuration for Windows based containers.
Windows *Windows `json:"windows,omitempty" platform:"windows"`

Copy link
Author

Choose a reason for hiding this comment

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

I think the distinction Windows / Linux is not so well chosen, possibly HCS / Docker (+plattform specific subset) would be better.
Conversely, the HCS is also a subset of the docker config.

https://github.com/Microsoft/hcsshim/blob/master/interface.go#L67
https://docs.docker.com/engine/api/v1.35/#operation/ContainerCreate

Copy link
Member

Choose a reason for hiding this comment

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

Point is that Linux containers take a whole different set of options for Memory constraints;

// LinuxMemory for Linux cgroup 'memory' resource management
type LinuxMemory struct {
// Memory limit (in bytes).
Limit *int64 `json:"limit,omitempty"`
// Memory reservation or soft_limit (in bytes).
Reservation *int64 `json:"reservation,omitempty"`
// Total memory limit (memory + swap).
Swap *int64 `json:"swap,omitempty"`
// Kernel memory limit (in bytes).
Kernel *int64 `json:"kernel,omitempty"`
// Kernel memory limit for tcp (in bytes)
KernelTCP *int64 `json:"kernelTCP,omitempty"`
// How aggressive the kernel will swap memory pages.
Swappiness *uint64 `json:"swappiness,omitempty"`
// DisableOOMKiller disables the OOM killer for out of memory conditions
DisableOOMKiller *bool `json:"disableOOMKiller,omitempty"`
}

IIUC, this will now map the Memory-constraints for the container to the Hyper-V VM for the container (not the container itself)

Copy link
Author

Choose a reason for hiding this comment

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

Yes that is correct.
HyperV Isolation mode reserves the memory for the container and the container itself has a limit by container config.
So in HyperV Isolation the container count is limit by physical memory.

Signed-off-by: Thomas Brueggemann <thomas.brueggemann@wuh-group.com>
@tiborvass
Copy link
Contributor

I think @thaJeztah's concerns about LCOW vs Windows are valid: isn't the whole point of LCOW to abstract the Linux API implementation and let userspace programs behave the same as on Linux? In which case why don't we reuse the Linux configs?

Those questions have to be answered, but let's unblock this PR.

LGTM

@lowenna
Copy link
Member
lowenna commented Jan 19, 2018

@tiborvass I had an offline conversation with @johnstep, but there's a good reason here. The short answer is that on Windows, there really are two sets of "resources" to run an LCOW

Some are required to configure the utility VM itself, such as layer paths, defined in OCI under type Windows struct..., the same as for WCOW. In addition, this struct defines resources of the utility VM which is the WindowsResources element of the Windows struct.

Beyond that is configuration of the container inside the utility VM. That's where the Linux side of the OCI spec comes in (the LinuxResources OCI struct), and are applied inside the utility VM, as opposed to being properties of the utility VM itself. This category has not yet been implemented - in effect, the container inside the utility VM runs 'unbounded' currently. Obviously as we move forward and in RS4/5 can run multiple containers inside a UVM, then these resources are critical.

Does that help clear up your question?

@tiborvass
Copy link
Contributor

@jhowardmsft almost! How do the windows resources get set, and shouldn't the linux resources be set instead? IOW, docker run --memory 2gb can only set one of the two. My understanding is that the windows resource is more useful to be set because if it's not set, HCS will set it to the default 1Gb which is annoying, and it makes no sense to set 2GB limit for the linux container, when the VM is set to 1Gb.

So is the solution to only set the windows ressources for the ones that VMs also have, and set the linux ressources only for the very cgroupy things?

@johnstep
Copy link
Member

Please note that, while the code changes look fine, this should not be merged until the discussion above is completed, and there are still outstanding questions. Thanks.

@razzeee
Copy link
razzeee commented Feb 7, 2018

Would it be possible to get the discussion going again, as it seems to have have stopped for some reason :/

@fizxmike
Copy link
fizxmike commented Apr 25, 2018
67E6

Yes... please continue the conversation. I need this feature, and I'm sure others do too. (Unless someone here knows a different workaround for "... HCS [setting] the default 1Gb which is annoying"?)

@richardgavel
Copy link

Can we resolve this PR? Only being able to create a Linux container that support a hard coded ~1 GB of memory doesn't help much. I am trying to create a Linux Saltstack master + Windows minion combination and LCOW makes that combination of platform types much easier. However, Salt needs more than the default allocated memory.

@lowenna
Copy link
Member
lowenna commented Jul 18, 2018

I think in the HCS v1 schema, this is pretty much the best we can do. In the v2 schema, it's far more flexible with clients in control of both the utility VM side and the container side.

@notanaverageman
Copy link
Contributor

This PR would end in nil errors with only these changes. I had opened another pull request for both CPU and Memory limits on LCOW. #37296
I have been using it without a problem for more than a month.

@thaJeztah thaJeztah added the area/lcow Issues and PR's related to the experimental LCOW feature label Oct 30, 2018
@derek derek bot added the rebuild/* label Dec 21, 2018
@derek derek bot added the status/failing-ci Indicates that the PR in its current state fails the test suite label Dec 22, 2018
@olljanat
Copy link
Contributor

@bruegth CI fails to error:

18:23:50 libcontainerd/client_local_windows.go:1::warning: file is not gofmted with -s (gofmt)
18:23:50 libcontainerd/client_local_windows.go:1::warning: file is not goimported (goimports)
18:23:51 Build step 'Execute shell' marked build as failure

And there is reviews above which needs to be addressed.

@bruegth
Copy link
Author
bruegth commented Jan 7, 2019

@johnstep and @thaJeztah I suggest to close this PR and go further with #37296

@olljanat
Copy link
Contributor
olljanat commented Jan 10, 2019

@johnstep and @thaJeztah I suggest to close this PR and go further with #37296

Closing...

@derek derek bot closed this Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lcow Issues and PR's related to the experimental LCOW feature status/failing-ci Indicates that the PR in its current state fails the test suite status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0