5.5. Tuning Virtual Memory
Virtual memory is typically consumed by processes, file system caches, and the kernel. Virtual memory utilization depends on a number of factors, which can be affected by the following parameters.
swappiness
- A value from 0 to 100 which 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 physical memory. 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
Since RHEL 6.4, settingswappiness=0
more aggressively avoids swapping out, which increases the risk of OOM killing under strong memory and I/O pressure.A lowswappiness
value is recommended for database workloads. For example, for Oracle databases, Red Hat recommends aswappiness
value of10
.vm.swappiness=10
min_free_kbytes
- The minimum number of kilobytes to keep free across the system. This value is used to compute a watermark value for each low memory zone, which are then assigned a number of reserved free pages proportional to their size.
Warning
Be cautious when setting this parameter, as both too-low and too-high values can be damaging and break your system.Settingmin_free_kbytes
too low prevents the system from reclaiming memory. This can result in system hangs and OOM-killing multiple processes.However, setting this parameter to a value that is too high (5-10% of total system memory) will cause your system to become out-of-memory immediately. Linux is designed to use all available RAM to cache file system data. Setting a highmin_free_kbytes
value results in the system spending too much time reclaiming memory. dirty_ratio
- Defines a percentage value. Writeout of dirty data begins (via pdflush) when dirty data comprises this percentage of total system memory. The default value is
20
.Red Hat recommends a slightly lower value of15
for database workloads. dirty_background_ratio
- Defines a percentage value. Writeout of dirty data begins in the background (via pdflush) when dirty data comprises this percentage of total memory. The default value is
10
. For database workloads, Red Hat recommends a lower value of3
. dirty_expire_centisecs
- Specifies the number of centiseconds (hundredths of a second) dirty data remains in the page cache before it is eligible to be written back to disk. Red Hat does not recommend tuning this parameter.
dirty_writeback_centisecs
- Specifies the length of the interval between kernel flusher threads waking and writing eligible data to disk, in centiseconds (hundredths of a second). Setting this to
0
disables periodic write behavior. Red Hat does not recommend tuning this parameter. drop_caches
- Setting this value to
1
,2
, or3
causes the kernel to drop various combinations of page cache and slab cache.- 1
- The system invalidates and frees all page cache memory.
- 2
- The system frees all unused slab cache memory.
- 3
- The system frees all page cache and slab cache memory.
This is a non-destructive operation. Since dirty objects cannot be freed, runningsync
before setting this parameter's value is recommended.Important
Using thedrop_caches
to free memory is not recommended in a production environment.
To set these values temporarily during tuning, echo the desired value to the appropriate file in the proc file system. For example, to set
swappiness
temporarily to 50
, run:
# echo 50 > /proc/sys/vm/swappiness
To set this value persistently, you will need to use the
sysctl
command. For further information, refer to the Deployment Guide, available from http://access.redhat.com/site/documentation/Red_Hat_Enterprise_Linux/.