How to Sort by Memory Usage in htop?
The htop command-line utility is an interactive system
monitor for Linux that allows users to track system resources in real
time. While it defaults to sorting tasks by CPU usage, you can quickly
reconfigure it to sort processes by memory consumption instead. This
article provides a straightforward, step-by-step guide on how to change
the sort order using keyboard shortcuts or the interactive menu, helping
you identify memory-hogging applications instantly.
Sorting Memory with Keyboard Shortcuts
The fastest way to sort your processes by memory usage in
htop is by using built-in keyboard shortcuts. Once you have
opened the tool by typing htop in your terminal, use one of
the following methods:
- The M Key Shortcut: Press
Shift + M(capital M) on your keyboard. This instantly resorts the process list by the MEM% column in descending order. - The Interactive Column Menu: Press
F6(orShift + 6on some terminals). A menu will appear on the left side of the screen labeled Sort by. Use your arrow keys to scroll down and select PERCENT_MEM or RES (Resident Memory), then pressEnter.
Sorting Memory Using the Mouse
If your terminal emulator supports mouse interactions,
htop allows you to navigate the interface with direct
clicks:
- Locate the column headers at the top of the process list (e.g., PID, USER, CPU%, MEM%).
- Click directly on the MEM% header to sort processes by their percentage of RAM utilization.
- Click the header a second time if you need to toggle between ascending and descending order.
Alternative Column Metrics for Memory
When analyzing memory in htop, you might want to sort by
different types of memory allocations depending on your troubleshooting
needs. You can use the F6 menu to sort by these specific
columns:
- VIRT (Virtual Image): The total amount of memory the process has access to, including swapped memory and memory allocated but not yet used.
- RES (Resident Set Size): The actual physical RAM that the process is actively using. This is usually the most accurate metric for finding memory leaks.
- SHR (Shared Memory): The amount of memory that could be potentially shared with other processes.