Trick to resolve High memory issue on Linux or Unix Server.
Today we will see a trick to resolve high memory issues on a linux or unix server.
We will set few kernel parameters to optimize the memory usage on server.
It will help our OS to free some of the memory whenever it consumes more than a set limit.
1. We will set few kernel parameters in sysctl config file.
[root@ngelinux001 ~]# cat /etc/sysctl.conf # System default settings live in /usr/lib/sysctl.d/00-system.conf. # To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 vm.max_map_count=262144 net.ipv4.ip_forward=1 vm.swappiness=15 vm.pagecache="40" vm.min_free_kbytes="10240000" [root@ngelinux001 ~]#
2. Implement the changes on system.
[root@ngelinux001 ~]# sysctl -p >> /dev/null sysctl: cannot stat /proc/sys/vm/pagecache: No such file or directory sysctl: setting key "vm.min_free_kbytes": Invalid argument
3. Check out the impact
[root@ngelinux001 ~]# free -g total used free shared buff/cache available Mem: 377 5 15 38 357 333 Swap: 127 0 127 [root@ngelinux001 ~]# free -g total used free shared buff/cache available Mem: 377 5 181 38 190 135 Swap: 127 0 127
4. Clear the cache once.
[root@ngelinux001 ~]# echo 3 > /proc/sys/vm/drop_caches
5. Understanding the parameters.
vm.swappiness=15
vm.pagecache=”40″
vm.min_free_kbytes=”10240000″
a. vm.swappiness:- Change the swappiness from 60 to 15 to make most of the use of RAM. It will swap in and out less pages to virtual memory.
b. vm.pagecache:- Change the value of page cache from 100(disabled) to 40. It will clear up the old unused page cache buffers and free up some memory.
c. vm.min_free_kbytes=”10240000″ :- To keep minimum 10GB free out of total memory to avoid OOM situation on server.