Monitoring Ubuntu Swapper (Swap Usage)
To effectively manage the Swapper (swap space) in Ubuntu, start by monitoring its usage to understand system behavior:
free -h to view a human-readable summary of physical memory (RAM) and swap space usage. This command shows total swap size, used swap, and free swap alongside RAM metrics.sudo swapon --show to list all active swap partitions/files, including their sizes and priorities. This helps identify which swap devices are currently in use.vmstat (e.g., vmstat 1 5 to display swap in/out every second for 5 iterations) or sar (e.g., sar -W 1 to monitor page swap activity). These commands help correlate swap usage with overall system performance.sudo stap -e 'probe scheduler.cpu_off { printf("%20s (%5d) -> %20s (%5d), idle:%d\n", task_execname(task_prev), task_pid(task_prev), task_execname(task_next), task_pid(task_next), idle); }') to track when the CPU switches to idle states, indicating potential swapper activity.Adjusting Ubuntu Swapper Settings
Once you’ve monitored swap usage, optimize its configuration to balance performance and resource usage:
vm.swappiness kernel parameter controls how aggressively the system uses swap (range: 0–100). A lower value (e.g., 10) reduces swap reliance, preferring RAM; a higher value (e.g., 60, the Ubuntu default) increases swap usage. To temporarily change it, run sudo sysctl vm.swappiness=10. For permanent changes, add vm.swappiness=10 to /etc/sysctl.conf and apply with sudo sysctl -p.sudo fallocate -l 4G /swapfile (adjust size as needed).sudo chmod 600 /swapfile (restrict access to root).sudo mkswap /swapfile.sudo swapon /swapfile./swapfile none swap sw 0 0 to /etc/fstab.sudo swapoff /swapfile), delete the file (sudo rm /swapfile), and remove its /etc/fstab entry. For partition resizing, use tools like gparted to modify partition sizes, then reformat and enable the new swap partition.sudo swapon -p <priority> /dev/swap_partition (higher numbers = higher priority). Lower-priority swaps are used only when higher-priority ones are full. List priorities with sudo swapon --show.sudo swapon -s to list active swaps, then sudo swapoff -v /swapfile (replace with your swap path) to disable it. Remove the file (sudo rm /swapfile) and delete its /etc/fstab entry.