首页主机资讯Ubuntu Swapper如何监控和调整

Ubuntu Swapper如何监控和调整

时间2025-10-31 17:26:03发布访客分类主机资讯浏览290
导读:Monitoring Ubuntu Swapper (Swap Usage To effectively manage the Swapper (swap space in Ubuntu, start by monitoring its...

Monitoring Ubuntu Swapper (Swap Usage)
To effectively manage the Swapper (swap space) in Ubuntu, start by monitoring its usage to understand system behavior:

  • Check Total and Used Swap: Use 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.
  • View Detailed Swap Entries: Run 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.
  • Advanced System Monitoring: For real-time insights into swap activity, use tools like 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.
  • Deep Dive with SystemTap: For detailed process-level monitoring, install SystemTap and run scripts (e.g., 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:

  • Tune Swappiness Parameter: The 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.
  • Resize Swap Space: If your system frequently runs low on swap, increase its size. For a swap file (recommended for simplicity):
    1. Create a file: sudo fallocate -l 4G /swapfile (adjust size as needed).
    2. Set permissions: sudo chmod 600 /swapfile (restrict access to root).
    3. Format as swap: sudo mkswap /swapfile.
    4. Enable it: sudo swapon /swapfile.
    5. Make permanent: Add /swapfile none swap sw 0 0 to /etc/fstab.
      To reduce swap size, disable it (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.
  • Adjust Swap Priority: For systems with multiple swap partitions/files, prioritize their usage with 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.
  • Remove Unnecessary Swap: Disable and delete unused swap files/partitions to free up disk space. Run 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.

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: Ubuntu Swapper如何监控和调整
本文地址: https://pptw.com/jishu/740113.html
Ubuntu Swapper能替代物理内存吗 Ubuntu Swapper对游戏性能有何帮助

游客 回复需填写必要信息