Skip to content

Instantly share code, notes, and snippets.

@vrkansagara
Forked from marianposaceanu/linux_performance.md
Last active March 7, 2018 16:03
Show Gist options
  • Save vrkansagara/5abfccdbf8d3cbd50d8b8bc207cffa3f to your computer and use it in GitHub Desktop.
Save vrkansagara/5abfccdbf8d3cbd50d8b8bc207cffa3f to your computer and use it in GitHub Desktop.
Linux simple performance tweaks

Linux simple performance tweaks

Change the I/O Scheduler

Open $ vim /etc/default/grub then add elevator=noop next to GRUB_CMDLINE_LINUX_DEFAULT. Run $ update-grub and $ cat /sys/block/sda/queue/scheduler to be sure that noop is being used:

$ vim /etc/default/grub
$ update-grub
$ cat /sys/block/sda/queue/scheduler
[noop] deadline cfq

noop : a trivial scheduler that just passes down the I/O that comes to it. Useful for checking whether complex I/O scheduling decisions of other schedulers are not causing I/O performance regressions.

In some cases it can be helpful for devices that do I/O scheduling themselves, as intelligent storage, or devices that do not depend on mechanical movement, like SSDs. Usually, the DEADLINE I/O scheduler is a better choice for these devices, but due to less overhead NOOP may produce better performance on certain workloads.

Enable KSM

Open $ vim /sys/kernel/mm/ksm/run and change 0 to 1

Kernel Samepage Merging (KSM) is a feature of the Linux kernel introduced in the 2.6.32 kernel. KSM allows for an application to register with the kernel to have its pages merged with other processes that also register to have their pages merged. For KVM, the KSM mechanism allows for guest virtual machines to share pages with each other. In an environment where many of the guest operating systems are similar, this can result in significant memory savings.

note : this might be useful when running multiple VMs on the same machine

Swappiness and cache pressure

Edit /etc/sysctl.conf and change the values for swappiness and vfs_cache_pressure.

vm.swappiness=10
vm.vfs_cache_pressure=50

You can check current values with:

sudo cat /proc/sys/vm/swappiness
sudo cat /proc/sys/vm/vfs_cache_pressure

swappiness this control is used to define how aggressively the kernel swaps out anonymous memory relative to pagecache and other caches. Increasing the value increases the amount of swapping. The default value is 60.

vfs_cache_pressure this variable controls the tendency of the kernel to reclaim the memory which is used for caching of VFS caches, versus pagecache and swap. Increasing this value increases the rate at which VFS caches are reclaimed.

Mentions

  • disable pagefile not recommanded : swapoff -a

credits

Filesystem caches are more important than other caches We've already established that the filesystem cache is important because, without it, file browsing goes extremely slowly as well. Now we'll learn how to tell Linux that we want it to prefer inode/dentry cache to other caches.

Try this:

sync echo 3 > /proc/sys/vm/drop_caches dd if=/dev/zero of=/tmp/testfile count=1 bs=900M

sysctl -w vm.vfs_cache_pressure=100 find / > /dev/null cp /tmp/testfile /tmp/testfile2 time find / > /dev/null

sysctl -w vm.vfs_cache_pressure=50 find / > /dev/null cp /tmp/testfile2 /tmp/testfile3 time find / > /dev/null

rm -f /tmp/testfile /tmp/testfile2 /tmp/testfile3

https://rudd-o.com/linux-and-free-software/tales-from-responsivenessland-why-linux-feels-slow-and-how-to-fix-that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment