Linux Containers (LXC) are lightweight virtualization technologies that allow running multiple Linux systems simultaneously on a single host. Resource allocation in LXC, including RAM, is managed by control groups, or cgroups.
Cgroups is a Linux kernel feature that limits, accounts for, and isolates the usage of various system resources such as CPU, memory, disk I/O etc. for a process or group of processes.
In terms of memory, cgroups provide several methods to control how much memory a LXC container can use, including:
- Limit in Bytes: The maximum amount of memory a container can use.
- Soft Limit in Bytes: The memory limit that a container should stay under during normal activity.
- Memory and Swap Limit: The combined limit for memory and swap usage.
- OOM Control: Configuration for how the Out Of Memory manager responds when the container’s memory limit is exceeded.
To apply these settings, one typically modifies the respective cgroups files. You can also use “lxc-cgroup” command or specify these settings in the LXC configuration file (“/var/lib/lxc/mycontainer/config”).
Moreover, LXC uses the Linux Kernel’s own resource isolation capabilities, ensuring that containers are as isolated in respect to resources as they would be in other forms of virtualization, but much more efficient due to sharing the same kernel.
Keep in mind that the total amount of available memory cannot exceed the physical RAM of the host system, so memory resources must be allocated wisely amongst containers.