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
Kubelet needs to allow configuration of container memory-swap #7294
Comments
/cc @thockin this aligns with our IRC discussion. |
/cc @danmcp per our chat as well. |
Hi all,
We're also customizing k8s to support memory swap in our project, so it can leverage docker memory swap. I'd like to contribute code using this issue, is my understanding above correct? |
I'd rather not put factors into a ResourceList, as is implied in item 2 of previous comment. All the items in resources.limits should be additive. If you want to allow users to specify this from the API, then they can just specify an absolute amount of swap, or if they leave it empty, then some admission controller could default it, and they could set it to an explicit value of 0 or maybe 1 if they don't want any swap. |
Hi erictune,
How about kubelet level support, do we still need it? |
The default value should be to not use swap at all. I think docker chose their format to be just like the cgroups interface. But, I don't think we need to copy that pattern. I'd rather that the resources list does not double-count resources or mix resources. It should be easy to add up resource lists like you add up vectors, to get aggregate amounts of resources. So, I think swap should just be the amount of swap, not swap + memory. And it should be called "swap" not "memoryswap", to reflect that. One case to think about: Swapfiles can be on rotating disk or on SSD. This gives very different performance characteristics. Also, the scheduler needs to subtract any swap space from the storage space of the node when a pod is bound to it. It needs to know whether to subtract that from rotating disk or SSD. Should, should we have separate "diskswap" and "ssdswap" resources? |
Hi erictune, |
I was thinking of the case where swap files are added dynamically by However, if nodes are statically provisioned with swap, and they exclude On Sun, Jun 28, 2015 at 11:20 PM, WangLei notifications@github.com wrote:
|
Hi erictune, |
I don't think we should allow pods to add swap to the system. I'd rather On Mon, Jun 29, 2015 at 8:32 AM, WangLei notifications@github.com wrote:
|
Hi thockin, |
I don't want to support memory-swap by default, at least for a near future
On another side, I understand some users might want to use swap no matter what; or some application is running on a dedicate node without any sharing, which still require swap space. @brendandburns proposed a way to simply pass-through such request to docker engine for certain container / pod with privileges. cc/ @bgrant0607 |
What is the use case for swap? If swap is enabled for any containers on a host, then no latency guarantees can be provided for other containers. |
Unassign myself since we don't want to add swap support for now unless someone provides me a real appealing use cases. |
what's the proper way to handle this then? disable swap on the host? |
Disabling swap is a good approach. When you have multiple containers and multiple machines they could be scheduled on, it is better to kill one container, than to have all the containers on a machine operate at an unpredictable, probably slow, rate. |
cc @vishh |
Based on the existing comments, this PR can be closed since there is no intention to support swap in the kubelet in the near future. @derekwaynecarr Feel free to re-open if you'd like to continue discussing support for swap. |
Yeah. This can be closed. I actually don't want to support swap right now On Thursday, May 19, 2016, Vish Kannan notifications@github.com wrote:
|
To contribute a use case for future reference: Swap space for running When Hope this is somewhat helpful. Thanks! See Also |
I would rather support swap as a cheap means of supporting overcommit, but On Monday, August 15, 2016, Yoshua Wuyts notifications@github.com wrote:
|
And to be clear this original issue was because Kubelet passed the wrong On Wednesday, August 17, 2016, Derek Carr decarr@redhat.com wrote:
|
@derekwaynecarr @vishh sorry to comment on a closed issue, but this has some context here: Kubelet seems to set MemorySwap (libcontainer config) to -1 by default here: which means /sys/fs/cgroup/memory.memsw.limit_in_bytes is set to unlimited (mem + swap) for the container. Isn't the Memory+swap should also be set to container.Resources.Limits.Memory().Value() above. Or am i missing something. |
Our approach has been that of asking users to not enable swap, but we never On Fri, Oct 7, 2016 at 3:18 PM, ravilr notifications@github.com wrote:
|
@derekwaynecarr @vishh setting memsw.limit to unlimited by default, doesn't seem right. Can we fix that. Not every environment has swap disabled, by default. |
Dear all, there is a new use case where we really need either: It's about Windows Docker compatibility, it was all good when using Windows docker version 1.12.2-cs2-ws-beta, but after upgraded to 1.14.0-dev, Windows Docker doesn't start any containers with below error output: https://github.com/docker/docker/blob/master/daemon/daemon_windows.go#L175 Disabling MemorySwap for every container is an alternative, but that would almost kill me in a long term point of view. |
I'd recommend disabling swap for all containers since kubelet cannot manage
swap space.
…On Mon, Dec 19, 2016 at 8:18 AM, Hongxi Ma ***@***.***> wrote:
Dear all, there is a new use case where we really need either:
a) Disable swap by default (set MemorySwap=0) or
b) Provide an option to do so for kubelet
It's about Windows Docker compatibility, it was all good when using
Windows docker version 1.12.2-cs2-ws-beta, but after upgraded to
1.14.0-dev, Windows Docker doesn't start any containers with below error
output:
"invalid option: Windows does not support MemorySwap"
The meantime MemorySwap was set to "-1" for "unlimited", but the code
expects it to be zero:
https://github.com/docker/docker/blob/master/daemon/daemon_windows.go#L175
Disabling MemorySwap for every container is an alternative, but that would
almost kill me in a long term point of view.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGvIKNMJtAeu6jZt4UABA5DOTjeqsgnXks5rJfCbgaJpZM4EH_zA>
.
|
Is this statement for Linux as well? Do you have any document for swap management in Kubernetes? Or any road map that it may support in the future? |
We do not intend to support swap in the near future. My statement is true
for Linux. Is swap behavior in Windows very different from Linux?
Turning on swap requires storage isolation and swap typically leads to
unpredictable performance which is not good in a clustered environment.
…On Tue, Dec 20, 2016 at 1:58 AM, Bill Wang ***@***.***> wrote:
@vishh <https://github.com/vishh>
Is this statement for Linux as well?
Do you have any document for swap management with Kubernetes? Or any road
map that it may support in the future?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGvIKP_hLQGxZx0I9OZAGzuv3nlhzS9uks5rJujfgaJpZM4EH_zA>
.
|
I have some users that continue to enable swap as a conscious choice. In
their environments, usage of swap was more important than QoS and eviction.
I don't think we can mandate disabling swap and still preserve backwards
compatibility unless it was gated by a flag of some kind whose default was
current behavior.
That said, I think we should warn via log if we detect swap is enabled if
we don't already (can't recall).
On Mon, Dec 19, 2016 at 10:52 PM Vish Kannan <notifications@github.com>
wrote:
… We do not intend to support swap in the near future. My statement is true
for Linux. Is swap behavior in Windows very different from Linux?
Turning on swap requires storage isolation and swap typically leads to
unpredictable performance which is not good in a clustered environment.
On Tue, Dec 20, 2016 at 1:58 AM, Bill Wang ***@***.***>
wrote:
> @vishh <https://github.com/vishh>
>
> Is this statement for Linux as well?
>
> Do you have any document for swap management with Kubernetes? Or any road
> map that it may support in the future?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#7294 (comment)
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AGvIKP_hLQGxZx0I9OZAGzuv3nlhzS9uks5rJujfgaJpZM4EH_zA
>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7294 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF8dbFaPZlJucp2Ept6QGoGo-i8V_e_Iks5rJ1D5gaJpZM4EH_zA>
.
|
I've created a separated issue #39003 specifically pointing to the showstopper for Windows case. @brendanburns provided a PR #39005 to disable MemorySwap only when it's Windows OS. Which keeps the current behavior for Linux (as of "unlimited memory swap") and also make Windows Docker working, it seems to be a proper solution at least for my case. |
FWIW, the default behavior is to disable swap since 1.6.0 |
Sorry to comment on an old dead thread, but I was looking at the commit that disabled swap, and comparing that to the docker docs on swap. In particular, the Docker docs say:
So the way I'm reading the docs, if kubelet sets memory swap to 0, then that will allow the container to have 2x its memory limit in swap. To disable swap, Am I missing something here? Or is this a bug? |
FYI, I'm running a 1.6.11 Kubernetes cluster, and confirmed that the pods running in that cluster are being allocated swap, at 2x the amount of memory that their limit is set to. (The below is a container running kube-state-metrics.)
|
@jonmoter Recent kubelet versions have a flag to work around this effect, by checking whether swap is turned on.
The kubelet won't start in this case. In your version, this setting was not implemented imho. |
@jonmoter Even you're right Kubernetes sets |
@Dominik-K, the container will be OOMkilled when Memory + Swap is exhausted. So if I have a container where I set the memory limit to 100MB, it will be killed when it exceeds ~300MB of total memory consumption. I can see this happening in the containers running in my system. And in the stackexchange answer you link in your image, it specifically says (emphasis mine):
My point in bringing all this up was that @munkyboy claimed above that swap was disabled by default in 1.6.0. That's not true. Starting in 1.6, swap is set to be And yes, in recent versions, there's the |
Automatic merge from submit-queue (batch tested with PRs 50724, 59025, 59710, 59404, 59958). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. dockertools: disable MemorySwap on Linux In this commit, set `MemorySwap` the same with `Memory` to prevent using swap on Linux. **What this PR does / why we need it**: In #39731, @pires tried to disable swap on Linux by setting `MemorySwap` to 0. However, according to [Docker's docs](https://docs.docker.com/config/containers/resource_constraints/#--memory-swap-details), setting `MemorySwap` to 0 is treated as unset, and its [default behavior](https://github.com/moby/moby/blob/v17.05.0-ce/daemon/daemon_unix.go#L266-L269) is to set to twice the size of `Memory`, which can still cause the container to use the swap. **Which issue(s) this PR fixes** : This issue was mentioned in this comment: #7294 (comment) **Special notes for your reviewer**: 1. For the case on Windows, we can still use the 0 because [Windows does not support `MemorySwap`](https://github.com/moby/moby/blob/v17.05.0-ce/daemon/daemon_windows.go#L185-L187). 2. There is another place using the `DefaultMemorySwap()` is for [sandbox](https://github.com/kubernetes/kubernetes/blob/v1.9.2/pkg/kubelet/dockershim/docker_sandbox.go#L505). Maybe setting the sandbox's `MemorySwap` to 0 is fine. I didn't change that. **Release note**: ```release-note dockertools: disable memory swap on Linux. ```
@jonmoter @Dominik-K This exact thing happened to us when we noticed that one of our java services was running super slow, and we debugged it to container.resources.limits.memory = 1Gi and the jvm Xms = 3Gi Xmx = 3Gi. So it wasn't getting OOM Killed but 2Gi of address space were swapped. |
@huggsboson what version of k8s were you using? Is kubelet flag |
We're still back on 1.6. We plan on disabling swap going forward. Just wanted to document some the bizarre and hard to debug behavior you can see with older versions of kube with swap enabled. |
I would like the Kubelet to support a flag like the following:
To control the default amount of MemorySwap that is given to a container as a percentage of their requested memory limit.
See https://docs.docker.com/reference/run/#runtime-constraints-on-cpu-and-memory for the third-row which is the behavior we show today when the user sets a memory-limit, but the kubelet does not specify memory-swap
We think using memory-swap at all is a big step to take, and if the administrator wanted to allow for memory swap, it should not default to 2L where (L is the memory specified).
For affected area of Kubelet, see:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/pkg/kubelet/dockertools/manager.go#L442
For value we should explicitly set, see:
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/Godeps/_workspace/src/github.com/fsouza/go-dockerclient/container.go#L177
The text was updated successfully, but these errors were encountered: