<p>In Kubernetes, <em>is it possible to enforce virtual memory (physical page swapping to disk) on a pod/container with memory requests and limits set?</em></p>
<p>For instance, as per the Kubernetes documentation, “if you set a memory limit of 4GiB for a container, the kubelet (and container runtime) enforce the limit. The runtime prevents the container from using more than the configured resource limit. For example: when a process in the container tries to consume more than the allowed amount of memory, the system kernel terminates the process that attempted the allocation, with an out of memory (OOM) error.”</p>
<p><em>Hence, is it possible to configure the pod (and hence linux kernel) to enforce virtual memory (that is paging and memory swapping ) on the specified physical  memory limits of the pod (4GiB) instead of OOM error?  am I missing something?</em></p>

Mazen Ezzeddine
<p>Reading the <a href="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory-interface-files" rel="nofollow noreferrer">kernel documentation</a> on this leads me to believe this is <strong>not</strong> possible. And I don't think this is a desirable behavior. Let's just think about the following scenario: You have a machine with 64GB of physical memory with 10GB of those used. Then you start a process with a &quot;physical&quot; memory limit of 500MB. If this memory limit is reached the kernel would start swapping and the process would stall even though there is enough memory available to service the memory requests of the process.</p>
<p>The memory limit you specify on the container is actually not a physical memory limit, but a virtual memory limit with overcommit allowed. This means your process can allocate as much memory as it wants (until you reach the overcommit limit), but it gets killed as soon as it tries to use too much memory.</p>
