In general folks disable swap of memory bound processes for linux instances (ymmv).
How to detect swapfile is present
1. grep -i –color swap /proc/meminfo
2. swapon -s
3. free -m
You will get confirmation no swap is setup. If you check for swappiness via cat /proc/sys/vm/swappiness though you will see swapping of default 60 :). Question on your mind will be where it is doing the swapping.
What should you do ? In general no swapping is good thing, so setting that swappiness to 0 is good thing with default installation. In case you require swapfile(which you will – if you care about latest kernel changes), Add a swap file based off local disk(sdb1 on the /mnt mostly or ssd ) on the guest (do not add azure storage) for the instance.
How to modify swappiness (for a web or file server) – echo 5 | sudo tee /proc/sys/vm/swappiness or – sudo sysctl vm.swappiness= 5 – To persist this setting through reboots it is better to edit the /etc/sysctl.conf and ensure add the swapfile to fstab. No swapping is good for lucene workloads(solr/elasticsearch), databases (cassandra/mongo/mysql/postgres etc) but for stability reasons at high constantly peaked machines- it is good to have local disk/ssd as help
How to allocate swapfile usually you will do it on local disk – use df -ah to get mount name) —- Allocate swapfile
– sudo fallocate -l 4G /mnt/swapfile (ensure size is double the memory size)
— Ensure root has access
– sudo chmod 600 /mnt/swapfile
– sudo mkswap /mnt/swapfile
– verify free -m
– add to fstab
– sudo nano /etc/fstab **** add line *** /mnt/swapfile none swap sw 0 0
To switch off swapping completely On Linux systems, you can disable swap temporarily by running:sudo swapoff -a.
To disable it permanently, you will need to edit the /etc/fstab file and comment out any lines that contain the word swap.
To ensure swapiness is switched after reboot
# Set the value in /etc/sysctl.conf
sudo echo ” >> /etc/sysctl.conf
sudo echo ‘#Set swappiness to 0 to avoid swapping’ >> /etc/sysctl.conf
sudo echo ‘vm.swappiness = 0’ >> /etc/sysctl.conf
Why to swap if nobody likes swapping and it is not 90s – For safety. From kernel version 3.5-rc1 and above, a swappiness of 0 will cause the OOM killer to kill the process instead of allowing swapping. (ref – http://java.dzone.com/articles/OOM-relation-to-swappiness ) While you are at all of this do notice – df /dev/shm and see what you can do about it. Do you want to use it?
Ref –
- ElasticSearch – from strong bootstrap.mlockall – with suggestion swappiness to zero to switch it off and also instruct oom not to kill it, http://www.elastic.co/guide/en/elasticsearch/reference/1.4/setup-configuration.html
- When Otis says something – I just follow it. http://elasticsearch-users.115913.n3.nabble.com/mlockall-vs-vm-swappiness-td4028126.html
- Solr – (http://www.cloudera.com/content/cloudera/en/documentation/cloudera-search/v1-latest/Cloudera-Search-User-Guide/csug_tuning_solr.html )
- Cassandra http://docs.datastax.com/en/cassandra/2.1/cassandra/install/installRecommendSettings.html
- MySql – https://mariadb.com/kb/en/mariadb/configuring-swappiness/
- MongoDB – http://docs.mongodb.org/manual/faq/diagnostics/
- Postgres – it is the same suggestion.
- Oracle – http://docs.oracle.com/cd/E24290_01/coh.371/e22838/tune_perftune.htm#COHAG223