vm.overcommit_memory

vm.overcommit_memory

The vm.overcommit_memory is a kernel parameter in the Linux operating system that controls the memory overcommit behavior of the system's virtual memory manager.

Virtual memory is a memory management option that allows processes to use more memory than is physically available by utilizing disk space as a swap or paging area.

This parameter influences how the Linux kernel handles memory allocation requests when the system is running low on available physical memory with the help of this parameter in the Linux kernel allows sysadmins to make balance between memory utilization, system stability, and the risk of out-of-memory situations.


Understand the different modes and their implications:

It is crucial when configuring the memory management behavior of a Linux system to specific workloads.

When a process in Linux requests memory, the kernel typically reserves memory for the process. However, it doesn't necessarily allocate physical memory at that moment; instead, it might just promise that memory will be available when the process tries to access it. This concept of allocating more virtual memory than there is available physical memory is known as memory overcommitment.

The vm.overcommit_memory parameter defines 3 different modes of memory overcommit behavior:


1. Mode 0 (Default):

  This mode adheres to the traditional overcommit behavior. The kernel allows processes to allocate more memory than is physically available, assuming that most processes won't use all the memory they request. Actual memory allocation occurs on-demand, and if the system runs out of physical memory, it starts to kill processes to free up space.


2. Mode 1 (Conservative):

  In this mode, the kernel still allows overcommitment, but it also performs additional checks when memory allocation requests are made. These checks are intended to ensure that there's a reasonable expectation that the requested memory will eventually be used. If the requested memory is deemed unlikely to be used, the allocation request might be denied even if there is technically enough virtual memory available.


3. Mode 2 (Strict):

  This mode prevents overcommitment entirely. The kernel tries to ensure that the sum of the memory allocations requested by all processes does not exceed the available physical memory and swap space. When a process requests memory in excess of the available resources, the allocation request is denied, and the process is usually notified with an error.



Configuration:


The vm.overcommit_memory parameter is located in the /proc/sys/vm/ directory and can be configured using the sysctl command or by directly modifying the value in the /proc/sys/vm/overcommit_memory file.

To set the vm.overcommit_memory parameter using the sysctl command, you can use the following syntax:

# sysctl vm.overcommit_memory=<value>        

Replace <value> with one of the following values:

  • 0: Default behavior (Mode 0)
  • 1: Conservative mode (Mode 1)
  • 2: Strict mode (Mode 2)




Usage and Considerations:


The choice of vm.overcommit_memory value depends on the specific use case and requirements of the system. While the default mode (0) generally works well for most applications, there are cases where the conservative (1) or strict (2) mode might be more appropriate.


>> Mode (0):

  • Suitable for most general-purpose applications.
  • Allows memory overcommitment, which can lead to better memory utilization.
  • Risk of potential out-of-memory situations when multiple processes request significant memory simultaneously.


>> Mode (1):

  • Offers a compromise between the default and strict modes.
  • May prevent some overcommit situations, reducing the likelihood of unexpected process terminations.
  • Can be helpful for systems where predictability and stability are crucial.


>> Mode (2):

  • Prevents memory overcommitment entirely.
  • Ensures that processes are allocated only what is currently available in physical memory and swap space.
  • Suitable for environments at where avoiding out-of-memory conditions is a top priority, even if it means denying memory requests.


It's important to note that using strict mode (2) might lead to certain applications being unable to start due to memory allocation failures. System administrators and architects should carefully assess the memory requirements of their applications before choosing a specific vm.overcommit_memory mode.




Method to calculate manually using shell script . #!/bin/bash Hostnames=$(uname -n | cut -d. -f1) scriptdate=`date` MemTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}') SwapTotal=$(grep SwapTotal /proc/meminfo | awk '{print $2}') RAM_MB=$(echo "scale=0; $MemTotal/1024" | bc -l) SWAP_MB=$(echo "scale=0; $SwapTotal/1024" | bc -l) OVERCOMMIT_RATIO=$(cat /proc/sys/vm/overcommit_ratio) CommitLimit=$(echo "scale=0; $RAM_MB * $OVERCOMMIT_RATIO / 100 + $SWAP_MB" | bc) Committed_AS=$(grep Committed_AS /proc/meminfo | awk '{print $2}') Committed_AS_MB=$(echo "scale=0; $Committed_AS/1024" | bc -l) echo $Hostnames "$scriptdate" MAX_LIMIT="$CommitLimit"MB CURRENT_USED="$Committed_AS_MB"MB

Like
Reply

Identifying Virtual Memory MAX Limit: CommitLimit = (RAM size * (overcommit_ratio / 100)) + Swap Size # cat /proc/sys/vm/overcommit_ratio Alternative method: # cat /proc/meminfo | grep –iE 'CommitLimit' ---------------------------------------------------------- To Identifying Virtual Memory Current Usage: # cat /proc/meminfo | grep -iE 'Committed_AS'

Like
Reply

To view or add a comment, sign in

More articles by Sanju Debnath

  • File management in Linux CLi
  • Whitespace for alignment

    Whitespace in simply means the spaces, tabs, and newlines you use when writing commands or scripts even though it looks…

  • bash in-built eval command

    Normally, when you tell `bash` something, it reads your instruction one time and does exactly what it understands from…

  • Whitespaces difference in between sed and awk output.

    The difference between sed and awk in terms of whitespaces during output sed just remove the declared characters and…

  • Color your terminal

    Run following commands in Linux terminal to make your black & white screen colourful. To keep script at your machine…

  • crontab

    The crontab, a very useful and most important tool to use it for repetitive jobs. It has most customizable schedule…

  • Pluggable Authentication Modules (PAM)

    PAM is a system for authenticating users in Linux and other Unix-like operating systems. PAM allows for the flexible…

  • Strings command substitute

    I was looking for basic available tools an option to replace strings which is mostly not pre-installed or shipped with…

  • Bash scripting - while conditional loop

    while conditional loop - A loop; repeatedly executes a block of code as long as a condition is true, in other words it…

  • Script to rename predictable network devices into classic network devices

    In a curiosity to make a script to have classic network interface name created this script rpni.sh this script is not…

Others also viewed

Explore content categories