How to measure individual processes swapped out memory?

1 view
Skip to first unread message

Edward Sanford Sutton, III

unread,
Jul 27, 2026, 6:39:58 PM (13 days ago) Jul 27
to freebsd-...@freebsd.org
Is there any proper way to tell how much swap memory is used per
process? /usr/bin/top has the -w option and 'w' key when running that
shows "approximate swap usage for each process" but the approximations
are too far off to be anything useful for me. As an example, `top -n 400
-w -o swap` currently lists all processes as using 0 bytes of swap while
I have 37GB of swap currently used, most of which is consumed by Firefox
processes. Even when I have seen top report numbers in the swap column,
they never add up to anywhere near what is actually in swap.
I cannot just approximate things with SIZE - RES because SIZE seems
to be what a process has requested for address space and RES+SWAP only
list what is consumed by pages that actually received writes. With
processes like jellyfin and baloo requesting over 200GB right at the
start they add up to more that all my ram + swap in my system and make
that column useless. Similarly other processes are known to request
significantly more memory than they actually use including Firefox so it
too does not help when trying to analyze what they have actually used.
The only way I know of currently is to have enough free/freeable
memory that everything in 'Swap:Used' can fit back into RAM and then
note RES for each process before+after unmounting all swap to force it
back into RAM. I am hoping for a way to read the amount without having
to move it in/out.
I'm currently on 15.1-RELEASE but do not recall ever having seen top
help me over the years but maybe it used to track it right at some point.
Thank you for any feedback.

Wojciech Puchar

unread,
Jul 28, 2026, 1:19:10 PM (12 days ago) Jul 28
to Edward Sanford Sutton, III, freebsd-...@freebsd.org
> The only way I know of currently is to have enough free/freeable memory
> that everything in 'Swap:Used' can fit back into RAM and then note RES for
> each process before+after unmounting all swap to force it back into RAM. I am
> hoping for a way to read the amount without having to move it in/out.
> I'm currently on 15.1-RELEASE but do not recall ever having seen top help
> me over the years but maybe it used to track it right at some point.
> Thank you for any feedback.
>
>
if you run swapctl -d if it is not possible you will get message and swap
will not be unmounted.

Edward Sanford Sutton, III

unread,
Jul 29, 2026, 4:34:16 PM (11 days ago) Jul 29
to Wojciech Puchar, freebsd-...@freebsd.org
For a single swap partition it is shorter syntax to replace with
swapoff without a parameter which will also fail if memory is too short.
Attempting to unmount a swap partition with either command will check
for the combination of RAM+remaining swap to see if there will be space
and fail when not true. If the combined room will work then swapped
memory on that devices is pushed out to RAM and remaining swap and then
it unmounts. Seems swapctl accepts a list of mount points so syntax
quickly becomes shorter with it. Using a list, it iterates through one
partition at a time as separate unmount calls so if you have 2 equally
sized partitions and 40% swap used with RAM effectively full then you
will first get 1 partition to unmount and the other is 80% full and when
it reaches the second partition it will fail with an error. Re-mounting
the first swap will bring you back to 40% full but for performance
reasons you will find all read calls now are always using I/O of the
second partition for currently stored memory until it gets swapped
out+in again.
The only way I know of to improve layout without closing+reopening
programs requires you have another swap partition large enough to hold
all swapped contents but is normally unmounted and mount it, unmount all
normally used partitions, mount all normally used partitions, and then
unmount the single large partition. I'm not sure that it is any formal
rule that it will always split the allocation across remaining drives
rather than filling them sequentially but it seemed to give that result
when I previously messed with it. If you have 3+ partitions and
accidentally unmounted multiple but not all of them and don't have a
spare large partition for such a shuffle, you can probably get to the
next closest state by mounting all partitions and then sequentially
unmount+remount any partitions that contained data before the mount;
this will leave you with at least one partition unpopulated and the
others carrying its load until swapped data gets pushed to RAM and back
to swap. If you have an extra swap partition that is not normally used
then you can have it in this sequence as the last partition to be
unmounted which will help reach closer to even data distribution but
with more steps and still not likely as well balanced.
As an interesting sidenote, manpage says 'swapctl -d' can also take
-f to have it proceed to unmount the partition but may deadlock the
system. Wouldn't it be more appropriate to kill processes as RAM becomes
exhausted as should be done in a low memory situation?

Reply all
Reply to author
Forward
0 new messages