Principal Technical Account Manager
São Paulo - Sep 2018
Technologies
How to Overcommit RAM
Clever Trick
Works in the guest RAM
Inflates and... Deflate :-P
Text
8 GB
8 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        3018        4320          30         644        4633
Swap:          3071           0        3071
[root@satserver-rf ~]# 8 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        3018        4320          30         644        4633
Swap:          3071           0        3071
[root@satserver-rf ~]# Some minutes later...
8 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        4492         794          45        2696        3100
Swap:          3071           0        3071
[root@satserver-rf ~]# 8 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        4492         794          45        2696        3100
Swap:          3071           0        3071
[root@satserver-rf ~]# Let's apply a Balloon!
6 GB
2 GB
6 GB
2 GB
6 GB
2 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           5935        2799         434          45        2701        2746
Swap:          3071           0        3071
[root@satserver-rf ~]# Now:
6 GB
2 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           5935        2799         434          45        2701        2746
Swap:          3071           0        3071
[root@satserver-rf ~]# [root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        4492         794          45        2696        3100
Swap:          3071           0        3071
[root@satserver-rf ~]#Now:
Was:
6 GB
2 GB
[root@satserver-rf ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           5935        2799         434          45        2701        2746
Swap:          3071           0        3071
[root@satserver-rf ~]# Â
Â
Â
Â
Â
Â
Â
Â
Â
:-)
\o/
:-D
:-D
:-D
:-D
:-D
:-D
Â
Works on top of frontswap - which uses Transcendent Memory as its back-end
Â
Stashes 'swapped' pages in compressed memory region
Â
Extremely optimistic - expect pages to be reclaimed while still on RAM
Useful if you have a external memory device as backing for Frontswap...
Useful if you have a external memory device as backing for Frontswap...
... which is not exactly
common.
May break bad when system is under memory pressure
Â
Breaks swappiness algorithm
Â
Consumes...
RAM.
May break bad when system is under memory pressure
Â
Breaks swappiness algorithm
Â
Consumes...
RAM.
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
¯\_(ツ)_/¯
Mix of solutions - KSM and...
Mix of solutions - KSM and...
Swap!
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Expected routine: A few sparse pgin/pgout ops
Be Conservative
Â
75% of your RAM overcommit
Â
Ex.: Host 1 TB RAM, overcommit 1.5:1
Â
vm.swappiness = 100
Â
Rationale: Preserve as much as possible cache memory and shed cold pages to Swap ASAP, avoiding a reclaiming trashing by kswapd when memory goes low
High throughput volume
Â
or
or
Easy implementation
Â
qemu-kvm is treated as a regular process, without specific tricks to make use of swap
Â
Robustness against memory consumption surges
Â
No need of external control
Â
Â
Â
Sometimes, even 1:1 (no overcommit) might not be attainable (no KSM, using Hugepages, heterogeneous workload), because... Above.
while true ; do
   echo -n 'KSM state: '
   cat /sys/kernel/mm/ksm/run
   echo -n 'Saved (deduped) memory (bytes) : '
   echo `cat /sys/kernel/mm/ksm/pages_sharing`*4096 | bc | numfmt --to=si
   echo -n 'Actual size in memory (bytes)  : '
   echo `cat /sys/kernel/mm/ksm/pages_shared`*4096 | bc | numfmt --to=si
   egrep '(Dirty|MemFree|^Cached)' /proc/meminfo
   sleep 1
   clear
donehttps://people.redhat.com/rfreire/kvm-overcommit/
rfreire@redhat.com