{"id":17777,"date":"2026-12-02T19:07:42","date_gmt":"2026-12-02T13:37:42","guid":{"rendered":"https:\/\/www.skynats.com\/blog\/?p=17777"},"modified":"2026-12-02T19:08:07","modified_gmt":"2026-12-02T13:38:07","slug":"diagnose-linux-swap-usage-with-smem","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/diagnose-linux-swap-usage-with-smem\/","title":{"rendered":"How to Diagnose Swap Usage on Linux with smem"},"content":{"rendered":"<p><b>Introduction<\/b><\/p>\n<p>Have you ever logged into a <a href=\"https:\/\/www.skynats.com\/linux-server-management\">Linux server<\/a>, noticed that swap memory is being used, and wondered why when the system still has plenty of free RAM?<\/p>\n<p>This is a common situation in <a href=\"https:\/\/www.skynats.com\/blog\/puppeteer-chrome-launch-failures-linux\/\">Linux server administration<\/a>. Linux uses swap space to manage memory efficiently. It can move less frequently accessed memory pages from RAM to swap, allowing available RAM to be used for other activities, including filesystem caching.<\/p>\n<p>However, consistently high swap usage can indicate memory pressure, inefficient application configuration, or a process consuming more memory than expected.<\/p>\n<p>The first step in troubleshooting Linux swap usage is identifying which processes are consuming swap memory<strong>.<\/strong> The <code>smem<\/code> command makes this easier by displaying memory consumption at the process level, including swap usage.<\/p>\n<p>In this guide, you will learn how to:<\/p>\n<ul>\n<li>\n<div>\n<div>\n<p>Check current Linux RAM and swap usage.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Install and use the <code>smem<\/code> command.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Identify processes consuming the most swap memory.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Understand USS, PSS, RSS, and swap metrics.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Compare smem with other Linux monitoring tools.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<li>\n<div>\n<div>\n<p>Troubleshoot and reduce unnecessary swap usage safely.<\/p>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<p>Whether you manage a VPS, dedicated server, cloud instance, or production Linux environment, these steps will help you investigate memory consumption more effectively.<\/p>\n<h2><strong>How to Check Swap Usage in Linux<\/strong><\/h2>\n<p>To identify which Linux processes are using the most swap memory, install <code>smem<\/code> and run:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>smem -rs swap -k<\/code><\/pre>\n<\/div>\n<\/div>\n<p>This command displays processes sorted by swap consumption, with the highest-consuming processes appearing first.<\/p>\n<p>Before that, check overall system memory using:<\/p>\n<div>\n<div>\n<pre dir=\"ltr\"><code>free -h<\/code><\/pre>\n<\/div>\n<\/div>\n<p>If you need to investigate high swap usage, compare the results with process memory consumption and system monitoring metrics before changing kernel settings.<\/p>\n<h2><strong>What Is Swap Memory in Linux?<\/strong><\/h2>\n<p>Swap memory is disk space that <span style=\"color: #999999;\"><a style=\"color: #999999;\" href=\"https:\/\/www.linux.org\/\" target=\"_blank\" rel=\"noopener\">Linux<\/a><\/span> uses as an extension of physical RAM. When the kernel needs to manage memory pressure, it can move certain inactive memory pages from RAM into swap space.<\/p>\n<h3><b>Step 1: Check the current swap usage<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Check how much swap is in use:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">free -h<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Look at the swap row. If the used column is high, continue with the next steps.<\/span><\/p>\n<h3><b>Step 2: Install smem<\/b><\/h3>\n<p><b><i>smem<\/i><\/b><span style=\"font-weight: 400;\"> is a memory reporting tool that shows memory usage per process, including swap. It is not installed by default, but it is available in most repositories.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">On RHEL, AlmaLinux, CentOS or Fedora (on RHEL-based systems you may need to enable the EPEL repository first):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">dnf install smem<\/span><\/p>\n<p><span style=\"font-weight: 400;\">On Debian or Ubuntu:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">apt install smem<\/span><\/p>\n<h2><b>Step 3: Find the processes using swap<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Run the following command to list processes sorted by swap usage, highest first:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">smem -rs swap<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you want the sizes in a readable format such as MB or GB, add the <\/span><span style=\"font-weight: 400;\">-k<\/span><span style=\"font-weight: 400;\"> option:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">smem -rs swap -k<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The output looks like this (shortened):<\/span><\/p>\n<p>PID User Command Swap USS PSS RSS<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n3878245 root \/usr\/bin\/python3 \/usr\/bin\/s 128.0M 10.2M 45.7M 85.6M<br \/>\n3878239 monit \/usr\/bin\/ping -q -c10 -i2 2 0 156.0K 200.0K 2.1M<br \/>\n3878238 monit sh -c \/usr\/bin\/ping -q -c10 4.0M 280.0K 443.0K 3.2M<br \/>\n3878237 monit \/omd\/sites\/monit\/bin\/n 32.0M 300.0K 8.1M 18.5M<br \/>\n3878235 monit \/usr\/bin\/ping -q -c10 -i2 2 0 156.0K 200.0K 2.1M<br \/>\n3878232 monit sh -c \/usr\/bin\/ping -q -c10 0 280.0K 439.0K 3.2M<br \/>\n3878231 monit \/omd\/sites\/monit\/bin\/n 16.0M 864.0K 6.1M 12.5M<br \/>\n3877754 root bash 0 4.8M 5.1M 8.2M<br \/>\n3877748 root sshd-session: root@pts\/0 0 748.0K 2.2M 7.6M<br \/>\n3877745 root sshd-session: root [priv] 8.0M 1.2M 2.9M 11.6M<br \/>\n3877731 root \/usr\/libexec\/nm-dispatcher 0 2.8M 4.2M 9.1M<\/p>\n<p><span style=\"font-weight: 400;\">Here is what the columns mean:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Swap<\/b><span style=\"font-weight: 400;\">: memory of that process currently sitting in swap<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>USS<\/b><span style=\"font-weight: 400;\">: memory that belongs only to that process<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>PSS<\/b><span style=\"font-weight: 400;\">: the process&#8217;s own memory plus its fair share of shared memory<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>RSS<\/b><span style=\"font-weight: 400;\">: all the RAM the process is using, including shared memory<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Bonus: <\/span><b>smem<\/b> <span style=\"font-weight: 400;\">can also draw a pie chart on a desktop with a graphical environment (pie chart requires matplotlib):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">smem &#8211;pie name -s rss<\/span><\/p>\n<h3><b>Step 4: Cross-check with other tools<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">No single tool is perfect for every situation. These alternatives are also useful for checking memory and swap per process.<\/span><\/p>\n<p><b>No installation needed:<\/b><span style=\"font-weight: 400;\"> every process exposes its swap usage in <\/span><span style=\"font-weight: 400;\">\/proc<\/span><span style=\"font-weight: 400;\">, so this one-liner works on almost any system:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">grep VmSwap \/proc\/[0-9]*\/status 2&gt;\/dev\/null | sort -k2 -nr | head<\/span><\/p>\n<p><b>htop:<\/b><span style=\"font-weight: 400;\"> an interactive version of <\/span><span style=\"font-weight: 400;\">top<\/span><span style=\"font-weight: 400;\">. It shows RES and VIRT by default. To see swap, press F2, go to Columns, and add the <\/span><span style=\"font-weight: 400;\">SWAP<\/span><span style=\"font-weight: 400;\"> column.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">dnf install htop\u00a0 \u00a0 # or apt install htop<\/span><\/p>\n<p><b>atop:<\/b><span style=\"font-weight: 400;\"> like <\/span><span style=\"font-weight: 400;\">top<\/span><span style=\"font-weight: 400;\">, but it also records system usage over time, which makes it great for finding out what happened in the past. Press <\/span><span style=\"font-weight: 400;\">m<\/span><span style=\"font-weight: 400;\"> inside atop to see memory details per process.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">dnf install atop\u00a0 \u00a0 # or apt install atop<\/span><\/p>\n<p><b>glances:<\/b><span style=\"font-weight: 400;\"> a real-time monitoring tool that shows per-process memory and swap on one screen. It can also run in server mode and be checked remotely.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">dnf install glances\u00a0 \u00a0 # or apt install glances<\/span><\/p>\n<p><b>btop and bottom (btm):<\/b><span style=\"font-weight: 400;\"> modern, colourful alternatives to <\/span><span style=\"font-weight: 400;\">top<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">htop<\/span><span style=\"font-weight: 400;\">. They give a clear visual view of CPU, memory, swap, disk and network. Both are available from their project pages and many package repositories.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">apt install btop<\/span><\/p>\n<h2><b>Step 5: Reduce swap usage<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Once you know which service is using swap, fix the cause first:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Tune memory-heavy services such as MySQL or rsyslog so they use less memory.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If a service really needs more memory, consider adding RAM.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">After that, you can lower the <\/span><span style=\"font-weight: 400;\">vm.swappiness<\/span><span style=\"font-weight: 400;\"> value so the kernel avoids swapping unless it really needs to:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">sysctl vm.swappiness=10<\/span><\/p>\n<p><span style=\"font-weight: 400;\">echo &#8216;vm.swappiness=10&#8217; &gt;&gt; \/etc\/sysctl.conf<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The first command applies the change immediately, and the second keeps it after a reboot. Note that swap which is already in use is not released automatically; it is moved back to RAM only when the process needs it again.<\/span><\/p>\n<h3><b>Conclusion<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Swap usage is not always a problem, but it is worth understanding when it grows. <\/span><b>smem<\/b><span style=\"font-weight: 400;\"> is a light and simple tool that shows exactly which processes are using swap, and its PSS values give an accurate view of real memory usage.\u00a0<\/span><\/p>\n<p><strong>Experiencing High Swap Usage on Your Linux Server?<\/strong><\/p>\n<p>Don&#8217;t let memory issues affect your server performance. Let Skynats help you identify resource bottlenecks, troubleshoot <a href=\"https:\/\/www.skynats.com\/linux-server-management\">Linux memory issues<\/a>, and keep your infrastructure running smoothly.<\/p>\n<p><a href=\"https:\/\/www.skynats.com\/linux-server-management\">Get Expert Linux Server Management Support<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Have you ever logged into a Linux server, noticed that swap memory is being used, and wondered why when the system still has plenty of free RAM? This is a common situation in Linux server administration. Linux uses swap space to manage memory efficiently. It can move less frequently accessed memory pages from RAM [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-17777","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/17777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=17777"}],"version-history":[{"count":4,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/17777\/revisions"}],"predecessor-version":[{"id":17782,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/17777\/revisions\/17782"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=17777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=17777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=17777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}