4

To see some memory info I can watch it in top of through cat /proc/meminfo.
In /proc/meminfo I can see the swap usage of the whole system like this:

SwapCached:            4 kB
SwapTotal:      33460220 kB
SwapFree:       33460216 kB

But there can be I situation when almost all the swap is used (i.e. there is a too small piece of SwapFree). How can I figure out, which process(es) are eating this swap?

UPD: there is a too small piece of SwapFree basically means that there is some process(processes) which ate a lot of memory and didn't use it for a long time. I need to find such processes.

5
  • @Peregrino69 If something gets swapped it means that it eats a lot of memory and is not under use. I.e. these memory pages are rarely used
    – NK-cell
    Commented Sep 20, 2021 at 16:02
  • @Peregrino69 Nope. The question is what processes are eating swap. I need to find all the processes that ate memory a lot and didn't use it for long time, so they were swapped. If process is eating memory eagerly and uses it quite often - I'm not interested in that.
    – NK-cell
    Commented Sep 20, 2021 at 16:32
  • @Peregrino69 why not as answer?
    – NK-cell
    Commented Sep 20, 2021 at 17:36
  • @Peregrino69 press 'p' to add swap to display when I go to SWAP: ` SWAP = Swapped Size (KiB)` and press p nothing happens..
    – NK-cell
    Commented Sep 20, 2021 at 17:42
  • 1
    Now that works, at least to the point of displaying swap - can't vouch further as my swap utilization is zero. Thanks for kicking my butt :-) I'm dropping a comment on the thread I quoted. Commented Sep 20, 2021 at 17:58

3 Answers 3

9
  1. Run top
  2. Press f to select displayed fields
  3. Navigate down to SWAP using arrow keys
  4. Hit Space - SWAP will become preceded by asterisk *
  5. Press right arrow key - this will allow you to move SWAP to a convenient place in the listing, for example between %MEM and TIME+
  6. Press q to return to top view

Step 5 isn't necessary, just convenience - without it SWAP will be showing up as the last entry of the list, after COMMAND.

3
  • Thanks! But how can I see, which processes ate more swap? Should I sort?
    – NK-cell
    Commented Sep 21, 2021 at 10:24
  • "without it SWAP will be showing up as the last entry of the list, after COMMAND" - nope, it will not show after COMMAND column in my case.
    – NK-cell
    Commented Sep 21, 2021 at 10:25
  • The testing comes from my system (BunsenLabs / Debian 10) which runs a version of top, I can't be certain whether your system has the same version, so can't confirm whether step 5 is needed there. By default top in my system sorts on CPU utilization, so you need to use either option -o when launching it, or choose the column used for sorting with command s in the field view (f). Commented Sep 21, 2021 at 10:34
2

You can use smem command line tool.

smem manpages:

Memory can be reported by process, by user, by mapping,
or systemwide. Both text mode and graphical output are available.

smem memory reporting tool

2
  • I'm unfamiliar with this tool, but the webpage doesn't mention swap. Judging by the output it only shows RAM or combined RAM or swap, which isn't useful in this case. Commented Sep 20, 2021 at 17:55
  • Unfortunately this tool is not a regular utility in Linux. So it most likely that there is no such tool in random server/machine. It is not always possible to download anything from anywhere
    – NK-cell
    Commented Sep 21, 2021 at 10:27
1

A tool for monitoring memory and swap usage is smemstat, what can show top-like output with

smemstat -mT
( "Swap reports memory that is swapped out to disk." man smemstat )

in terminal, sorted for highest memory usage on top.

2
  • Thanks. Is there a way to sort processes by swap?
    – NK-cell
    Commented Oct 10, 2021 at 9:15
  • [1] smemstat -m | sort -n -k 2 or reverse smemstat -m | sort -nr -k 2 should sort for amount of swap used, [2] customizing a script superuser.com/a/355710/981508 for more diverse tasks
    – beyondtime
    Commented Oct 10, 2021 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .