Using SSDs as swap

Willem Jan Withagen wjw at digiware.nl
Sat Aug 8 18:51:44 UTC 2015


On 8-8-2015 20:32, Konstantin Belousov wrote:
> On Sat, Aug 08, 2015 at 12:26:38PM -0600, Warren Block wrote:
>> On Sat, 8 Aug 2015, Willem Jan Withagen wrote:
>>>
>>> So perhaps the nicest thing to do for the SSDs is TRIM swap at
>>> startup??? So the the SSD controller van do its garbage collection and
>>> then keep the remainder of the stuff as it is.
>>
>> This can be done now by using a swap file on a UFS partition with trim 
>> enabled.  The catch is that the swap file has to be deleted and 
>> recreated to trigger the trim.  The delete is quick, but the create 
>> depends on the size of the file and the speed of the hardware.  (And no, 
>> sparse files do not work as swap files.)
> This could work, in the sense that swap would indeed work as a swap,
> and not as a deadlock generator.  But it adds very significant (up to
> 100% in the CPU time, I think) overhead.
> 
> Note that you cannot swap to file directly, you must create md(4) over
> the file and swap to it.
> 
> But doing such layer over layer to get the TRIM is somewhat silly.

Right, added layering is not really something you'd be looking for here.
We talking about incidental swapping to SSD, so then the system is
already under pressure.

>> Maybe rotate swap files like log files, so they could be created when 
>> the system is idle.

'mmm, once swap is in use, I do not think you can unswap?
So even if the sytem is idle, was was not swapped back in because it is
needed stays out on swap.

Look at my curent swap on a ZFS file server, I added 2 SSDs partitions
about 1,2 ago. But even the old swap was not released....
{ swap on SSD's are on ad{2,3}p2 }

Device          1K-blocks     Used    Avail Capacity
/dev/ada2p2       8388608     122M     7.9G     1%
/dev/ada3p2       8388608     123M     7.9G     2%
/dev/gpt/swap0    8388608     4.6M     8.0G     0%
/dev/gpt/swap1    8388608     5.0M     8.0G     0%
Total            33554432     255M      32G     1%

(Yes, I realise that 32Gb swap for a 8Gb system is somewhat silly)

Different idea if we do not want to TRIM from the kernel when issueing
swapon:
Would it be possible to use camcontrol to issue a "trim" on a (GPT) swap
partition? Or does gpart anything that could be conceived as a TRIM.
Because then the initscript would first check for saved cores, and once
done that trim the swappartition with a commandline tool?

--WjW


More information about the freebsd-fs mailing list