Skip to content
Andrei Montchik edited this page Jul 7, 2024 · 9 revisions

Configure Swap

  • Review: sudo swapon --show
  • Resize:
    1. disable: sudo swapoff /swap.img
    2. resize: sudo fallocate -l 32G /swap.img
    3. mark the file as swap: sudo mkswap /swap.img
    4. enable swap file: sudo swapon /swap.img
  • Deprioritize:
    1. Check the current swappiness: cat /proc/sys/vm/swappiness
    2. Temporarily lower the swap priority: sudo sysctl vm.swappiness=10
    3. Permanently lower the swap priority:
      1. Add vm.swappiness = 10 to /etc/sysctl.conf
      2. Reload the configuration: sudo sysctl -p
      3. Confirm that the swap is active: swapon --show
  • Disable:
    1. Identify the swap file sudo swapon --show.
    2. Disable swapping until the next reboot: sudo swapoff <SWAP_FILE>.
    3. Comment out the swap configuration line in /etc/fstab to permanently disable swapping.
  • Clear swap manually:
    1. sudo swapoff -a
    2. sudo swapon -a
    3. Check the swap status, it should on bu empty. In case if it is off, re-enable: sudo swapon /swap.img

Memory mapped files limit

  • Check the current limit: sysctl vm.max_map_count
  • Increase:
  1. Search for the vm.max_map_count parameter the sysctl configuration files:
    • sudo grep max_map_count /etc/sysctl.conf
    • sudo grep max_map_count /etc/sysctl.d/*
  2. Update the existing or insert the new map count parameter to /etc/sysctl.conf: vm.max_map_count = 1000000
  3. Reload the sysctl service: sudo sysctl -p
  4. Confirm that the files limit was updated: sysctl vm.max_map_count

Stress Testing

CLI

  • Free memory: free -th or cat /proc/meminfo | grep MemFree
    • refresh every second: free -th -s 1
  • Top 10 processes that use most memory: ps aux --sort=-%mem | head -10

Clone this wiki locally