Re: How to measure individual processes swapped out memory?

"Edward Sanford Sutton, III" <[email protected]> Wed, 29 Jul 2026 13:32:54 -0700
Newsgroups gmane.os.freebsd.questions
Message-ID <SA1PR11MB8811CC4E7830DF704DC9B990E6CA2@SA1PR11MB8811.namprd11.prod.outlook.com>
On 7/28/26 10:17, Wojciech Puchar wrote:
>>  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.

   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?