0# Change the swap Settings
In Ubuntu, swap partitions are often used instead of running out of physical memory. The size of swappiness is very important for how to use swap partitions. When swappiness=0, it means the maximum use of physical memory, followed by swap space. When swappiness= 100, it means the active use of swap partition, and the timely transfer of memory data to swap space. For Ubuntu’s default Settings, this value is equal to 60. It is recommended to change it to 10.
1# Check your system’s swappiness
cat /proc/sys/vm/swappiness
# If nothing goes wrong, you should see 60
Copy the code
2# Change the swappiness value to 10
sudo sysctl vm.swappiness=10
# But this is only a temporary change, it will restore the default 60 when you restart the system, so there is one more step to do:
sudo gedit /etc/sysctl.conf
Add the following line at the end of the document:
vm.swappiness=10
Copy the code
1# Release memory periodically
# vim /root/satools/freemem.sh
#! /bin/bash
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "= = = = = = = = = = = = = = = = = = = = = = = = = = =" >> /var/log/mem.log
date >> /var/log/mem.log
echo "The Memory usage | [Use:${used}MB] [Free:${free}MB]" >> /var/log/mem.log
if [ $free -le 100 ] ; then
sync && echo 1 > /proc/sys/vm/drop_caches
sync && echo 2 > /proc/sys/vm/drop_caches
sync && echo 3 > /proc/sys/vm/drop_caches
echo "OK" >> /var/log/mem.log
else
echo "Not required" >> /var/log/mem.log
fi
Copy the code
Add the script to the Crond task and execute it periodically.
# echo "*/1 * * * * root /root/satools/freemem.sh" >> /etc/crontab
# or
crontab -e
# add
*/1 * * * * root /root/satools/freemem.sh
Copy the code
2 # CPU Settings
Install CPU frequency management software
sudo apt-get install cpufrequtils
Check the current CPU status
cpufreq-info
# 3 set CPU policy (in this case, I set CPU policy to Performance)
sudo cpufreq-set -g performance
Set the CPU frequency under the current policy
sudo cpufreq-set -d1800 m - 2700 m/u/applicable mode: powersave | ondemand | conservative | performance sudo cpufreq - set-f{1800m-2700m} // Applicable mode: userspace-d Sets the minimum frequency
#-u Sets the maximum frequency
Copy the code
3# References
- Ubuntu frequently freezes fixed
- Fixed ubuntu always crashing
- How does Ubuntu adjust CPU policy