You are not logged in.
Pages: 1
I was wondering if any kind of attention is needed in trimming the swap partition of my drive.
I am currently running fstrim.timer to execute trim commandweekly. On my main drive it gets executed on root and home partition but non on swap partition (this should be happening because fstrim gets executed on mounted partitions only).
I can see that swapon provides a discard option, and there is the possibility to set discard in /etc/fstab. On the other hand I read that using discard is not suggested in most cases.
Should I use discard on the swap partition, is there some other method to trim that, or what exactly is the best practice in this case?
Offline
Perhaps use a swap file instead and that will get trimmed with the root trim?
https://ugjka.net
"It is easier to fool people, than to convince them that they've been fooled" ~ Dr. Andrea Love
Offline
I guess that would solve the trim situation, but I wanted to avoid swap file.
I was just wondering what the best practice for a swap partition would be.
Thanks though!
Offline
swap files don't help here. they have to be allocated so they won't be discarded by fstrim either.
swap supports several discard modes (none, once, pages, both). you have to choose one of them. there is no other method other than obscure ones.
obscure way to discard swapfile: swapoff, delete file, fstrim, create new file, swapon.
obscure way to discard swap partition: swapoff, blkdiscard swap partition, mkswap, swapon.
that's if you absolutely had to do it manually (like fstrim) without using the builtin discard support. however it would be prone to errors so just go with the discard options.
if you intend to trim the swap partition out of privacy concerns, it would be better to use encryption instead.
Offline
On the other hand I read that using discard is not suggested in most cases.
Where did you read this? I have
LABEL=SWAP swap swap noauto,discard 0 0
in fstab and curious in what cases it may be harmful.
Offline
See the notes in
https://wiki.archlinux.org/title/Solid_state_drive#TRIM
https://wiki.archlinux.org/title/Solid_ … nuous_TRIM
Ftr
This may improve performance on some Solid State Devices, but often it does not. The option allows one to select between two available swap discard policies
Offline
jsaxx wrote:On the other hand I read that using discard is not suggested in most cases.
Where did you read this? I have
LABEL=SWAP swap swap noauto,discard 0 0
in fstab and curious in what cases it may be harmful.
The idea I have against discard is mostly taken from Arch wiki as mentioned by Seth: https://wiki.archlinux.org/title/Solid_state_drive#TRIM
Note: If you want to use TRIM, use either periodic TRIM or continuous TRIM. Continuous TRIM is not the most preferred way to issue TRIM commands among the Linux community. For example, Ubuntu enables periodic TRIM by default [2], Debian does not recommend using continuous TRIM and Red Hat recommends using periodic TRIM over using continuous TRIM if feasible [3].
***
See the notes in
https://wiki.archlinux.org/title/Solid_state_drive#TRIM
https://wiki.archlinux.org/title/Solid_ … nuous_TRIMFtr
https://man.archlinux.org/man/core/util-linux/swapon.8.en wrote:This may improve performance on some Solid State Devices, but often it does not. The option allows one to select between two available swap discard policies
I am concerned about trimming swap mostly because of disk performance and longevity. Should I be then using the discard option? Or is the benefit to performance and longevity negligible?
Offline
Make sure your SSD principally supports trimming, just try.
If you start to get random memory errors, try defining a (different) method.
If you still get random memory errors, disable trimming.
If the memory errors go away, you cannot use trimming (regardless of the pot. benefits)
Otherwise it's not likely to make your concerned issues worse. Whether it improves them depends on access patterns and the swap size and probably the model. You can (synthetically) test the performance immediately. Longevity benefits will require to use the disk for a long time w/ and w/o trimming and compare the sector wear stats of the periods.
Offline
Thanks seth. The SSD itself does support trimming, and is being trimmed on root and boot partitions weekly.
I will probably give a shot on creating swapon with discard and try out the different methods to see how it goes.
Last edited by jsaxx (2023-03-28 14:48:59)
Offline
Pages: 1