Question: How to view the system-wide swap usage on a CentOS/RHEL server via the top command to identify the highest consumers.
Below are the steps for CentOS/RHEL 5 and 6 which are the same, followed by CentOS/RHEL 7 as they differ on this release:
For CentOS/RHEL 5 and 6
1. Run the TOP command:
# top
2. On your keyboard press the “f” key followed by “p” to add the Swap column, Hit enter.
3. Next, upper case “O” and finally “p” sort by swap, Hit enter.
4. Perform your review as needed and press “q” to exit top command.
For CentOS/RHEL 7
1. Run the TOP command:
# top
2. On your keyboard press the “f” key and scroll down using the [down] arrow key until you have selected “SWAP” then press [Space] to select it. This should add a “*” symbol in front of it.
3. While still selecting “SWAP” press the [right] arrow key, which highlights the entire SWAP line, and using the [top] arrow key move it up to one of the first options (anywhere above “COMMAND”).
4. While still having “SWAP” selected, type the “s” key which will configure top to SORT by the currently selected option, in this case, SWAP. You will not see any changes on the screen when you press “s”, but the setting is saved in the backend.
5. Finally “q” to save the configuration changes and view the results.
6. Perform your review as needed and press “q” again to exit top command.
For more information on top options and fields review the man page. Below are a few lines from the top man page that provide some information on the memory fields and what they represent.
# man top MEM -- Memory Usage (RES) A task's currently used share of available physical memory. RES -- Resident Memory Size (KiB) The non-swapped physical memory a task is using. SHR -- Shared Memory Size (KiB) The amount of shared memory available to a task, not all of which is typically resident. It simply reflects memory that could be potentially shared with other processes. SWAP -- Swapped Size (KiB) The non-resident portion of a task's address space. VIRT -- Virtual Memory Size (KiB) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.