Prime Stake Pool
WebsiteTwitterTelegram
  • Home
  • About Us
  • Server Setup Basics
    • How to setup your Cloud Server securely
      • Create new user
      • Use ssh key pair to access your server
        • Create .ssh folder
        • Create rsa key pair (public/private)
        • Copy rsa public key to remote server
      • Disable root login,password and change default port 22
      • Install fail2ban
      • Firewall rules
      • Enable 2FA
      • Setup video
    • Linux Swap Space
      • Add Swap Space
      • Kernel cache pressure and swappiness
      • Add swap video
  • Server Settings
    • Setting Up chrony
    • Static IP using Netplan
    • Time Synchronization
    • Important Settings
    • TMUX
  • Linux Commands
    • Basic Commands
    • Important Uses
  • Node Setup Guide
    • Cardano
      • How to minimize missed slot leader checks / missed blocks
        • Garbage collection
        • Run node in multicore mode
        • Turn off TraceMempool
    • Ethereum
  • Monitoring
    • Raspberry Pi ARM
    • Linux System x64
  • Maintenance
  • Logical Volume Management (LVM)
    • Basic concepts
    • LVM Resize
      • Decrease an LVM partition
      • Increase an LVM partition
    • Add a new PV to VG
    • LVM Commands
    • LVM on Pi
  • Disk Check
  • Backup Disk
Powered by GitBook
On this page
  1. Server Setup Basics
  2. Linux Swap Space

Kernel cache pressure and swappiness

Adjust your server’s cache pressure and tendency to swap (swappiness)

PreviousAdd Swap SpaceNextAdd swap video

Last updated 2 years ago

Now that you have swap enabled. Consider adjusting your server’s cache pressure and tendency to swap () by following the guide below.

vfs_cache_pressure – Controls the kernel’s tendency to reclaim the memory, which is used for caching of directory and inode objects. (default = 100, recommend value 50 to 200)

swappiness – This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase aggressiveness; lower values decrease the amount of swap. (default = 60, recommended values between 1 and 60) Remove your swap for 0 value, but usually not recommended in most cases.

To edit, you can add or replace these lines in /etc/sysctl.conf file. For example, if you have low memory until you upgrade, you can try something such as:

This will increase the cache pressure, which may seem somewhat counterproductive since caching is good for performance. However, too frequent swapping reduces your server’s overall performance significantly more. So not keeping as much cache in memory will help reduce swap activity. Also, with vm.swappiness set to 10 or as low as 1, it will reduce disk swapping.

On a healthy server with lots of available memory, use the following:

This will decrease the cache pressure. Since caching is good for performance, we want to keep cached data in memory longer. Since the cache will grow larger, we still want to reduce swapping to not cause increased swap I/O.

To check current values using these commands use:

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

To enable these settings temporarily without rebooting, use the following commands:

sudo sysctl -w vm.swappiness=10
sudo sysctl -w vm.vfs_cache_pressure=50

Swap space will give you some breathing room in cases that would otherwise lead to out-of-memory exceptions.

If you are running into OOM (out of memory) errors, or if you find that your system is unable to use the applications you need, the best solution is to optimize your application configurations or upgrade your server.

This article has a reference from Hayden James's Linux blog .

Why You Should Almost Always Add Swap Space
vm.swappiness