Red Hat Training

A Red Hat training course is available for Red Hat Linux

7.5. Configuring System Memory Capacity

This section discusses memory-related kernel parameters that may be useful in improving memory utilization on your system. These parameters can be temporarily set for testing purposes by altering the value of the corresponding file in the /proc file system. Once you have determined the values that produce optimal performance for your use case, you can set them permanently by using the sysctl command.
Memory usage is typically configured by setting the value of one or more kernel parameters. These parameters can be set temporarily by altering the contents of files in the /proc file system, or they can be set persistently with the sysctl tool, which is provided by the procps-ng package.
For example, to set the overcommit_memory parameter to 1 temporarily, run the following command:
# echo 1 > /proc/sys/vm/overcommit_memory
To set this value persistently, add sysctl vm.overcommit_memory=1 in /etc/sysctl.conf then run the following command:
# sysctl -p
Setting a parameter temporarily is useful for determining the effect the parameter has on your system. You can then set the parameter persistently when you are sure that the parameter's value has the desired effect.

Note

To expand your expertise, you might also be interested in the Red Hat Enterprise Linux Performance Tuning (RH442) training course.

7.5.1. Virtual Memory Parameters

The parameters listed in this section are located in /proc/sys/vm unless otherwise indicated.
dirty_ratio
A percentage value. When this percentage of total system memory is modified, the system begins writing the modifications to disk with the pdflush operation. The default value is 20 percent.
dirty_background_ratio
A percentage value. When this percentage of total system memory is modified, the system begins writing the modifications to disk in the background. The default value is 10 percent.
overcommit_memory
Defines the conditions that determine whether a large memory request is accepted or denied.
The default value is 0. By default, the kernel performs heuristic memory overcommit handling by estimating the amount of memory available and failing requests that are too large. However, since memory is allocated using a heuristic rather than a precise algorithm, overloading memory is possible with this setting.
When this parameter is set to 1, the kernel performs no memory overcommit handling. This increases the possibility of memory overload, but improves performance for memory-intensive tasks.
When this parameter is set to 2, the kernel denies requests for memory equal to or larger than the sum of total available swap space and the percentage of physical RAM specified in overcommit_ratio. This reduces the risk of overcommitting memory, but is recommended only for systems with swap areas larger than their physical memory.
overcommit_ratio
Specifies the percentage of physical RAM considered when overcommit_memory is set to 2. The default value is 50.
max_map_count
Defines the maximum number of memory map areas that a process can use. The default value (65530) is appropriate for most cases. Increase this value if your application needs to map more than this number of files.
min_free_kbytes
Specifies the minimum number of kilobytes to keep free across the system. This is used to determine an appropriate value for each low memory zone, each of which is assigned a number of reserved free pages in proportion to their size.

Warning

Extreme values can damage your system. Setting min_free_kbytes to an extremely low value prevents the system from reclaiming memory, which can result in system hangs and OOM-killing processes. However, setting min_free_kbytes too high (for example, to 5–10% of total system memory) causes the system to enter an out-of-memory state immediately, resulting in the system spending too much time reclaiming memory.
oom_adj
In the event that the system runs out of memory and the panic_on_oom parameter is set to 0, the oom_killer function kills processes until the system can recover, starting from the process with the highest oom_score.
The oom_adj parameter helps determine the oom_score of a process. This parameter is set per process identifier. A value of -17 disables the oom_killer for that process. Other valid values are from -16 to 15.

Note

Processes spawned by an adjusted process inherit the oom_score of the process.
swappiness
The swappiness value, ranging from 0 to 100, controls the degree to which the system favors anonymous memory or the page cache. A high value improves file-system performance while aggressively swapping less active processes out of RAM. A low value avoids swapping processes out of memory, which usually decreases latency at the cost of I/O performance. The default value is 60.

Warning

Setting swappiness==0 will very aggressively avoids swapping out, which increase the risk of OOM killing under strong memory and I/O pressure.

7.5.2. File System Parameters

Parameters listed in this section are located in /proc/sys/fs unless otherwise indicated.
aio-max-nr
Defines the maximum allowed number of events in all active asynchronous input/output contexts. The default value is 65536. Modifying this value does not pre-allocate or resize any kernel data structures.
file-max
Determines the maximum number of file handles for the entire system. The default value on Red Hat Enterprise Linux 7 is the maximum of either 8192, or one tenth of the free memory pages available at the time the kernel starts.
Raising this value can resolve errors caused by a lack of available file handles.

7.5.3. Kernel Parameters

Default values for the following parameters, located in the /proc/sys/kernel/ directory, can be calculated by the kernel at boot time depending on available system resources.
msgmax
Defines the maximum allowable size in bytes of any single message in a message queue. This value must not exceed the size of the queue (msgmnb). To determine the current msgmax value on your system, use:
# sysctl kernel.msgmax
msgmnb
Defines the maximum size in bytes of a single message queue. To determine the current msgmnb value on your system, use:
# sysctl kernel.msgmnb
msgmni
Defines the maximum number of message queue identifiers, and therefore the maximum number of queues. To determine the current msgmni value on your system, use:
# sysctl kernel.msgmni
shmall
Defines the total amount of shared memory pages that can be used on the system at one time. A page is 4096 bytes on the AMD64 and Intel 64 architecture, for example.
To determine the current shmall value on your system, use:
# sysctl kernel.shmall
shmmax
Defines the maximum size (in bytes) of a single shared memory segment allowed by the kernel. To determine the current shmmax value on your system, use:
# sysctl kernel.shmmax
shmmni
Defines the system-wide maximum number of shared memory segments. The default value is 4096 on all systems.
threads-max
Defines the system-wide maximum number of threads available to the kernel at one time. To determine the current threads-max value on your system, use:
# sysctl kernel.threads-max
The default value is the result of:
mempages / (8 * THREAD_SIZE / PAGE SIZE )
The minimum value is 20.