LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 05-28-2013, 02:08 PM   #1
flokofcgulls
Member
 
Registered: Apr 2013
Posts: 79

Rep: Reputation: Disabled
Running fstrim manually on a swap partition - can it be done?


Hey folks, back with another question! I recently saw a thread here where someone was asking about SSD's, which brought my attention to some important issues with SSD systems, such as TRIM commands, alignment, etc.

After doing some research, it seems the best way is just to run fstrim manually from time to time, which I don't mind.

My / and swap partitions are inside an LVM, which is in turn inside of a LUKS container. I can boot from the Slackware disc, manually decrypt the container using the --allow-discards option, activate the LVM, and mount the / partition to run fstrim, no problems and looks like it works ok.

However, I can't seem to figure out how to do this for swap. I did a little more research, and it appears that it is not possible to manually mount swap, but fstrim will only work on a mounted filesystem.

So my question is...is this even possible? Can swap be mounted in some clever way to allow fstrim to work? Do I have to just accept that fstrim cannot be used on a swap partition, and that the area of the SSD containing swap may wear out first? Is it even an issue that I need to be concerned with?
 
Old 05-28-2013, 06:35 PM   #2
chemfire
Member
 
Registered: Sep 2012
Posts: 81

Rep: Reputation: Disabled
You probably don't need to run fstrim at all. You should have discard as a mount option for your swap space. Check your fstab, if its not present just put a comma after defaults on the line and then the word discard ie: defaults,discard. That should take care of things as additional swap space gets allocated than freed. Your SSD ware-levels over the entire disk as the controller is not aware of the partition tables; and presents a map of blocks to the operation system that in most cases only it knows how map onto the physical memory cells. So you don't need to worry about part of the disk getting worn out first.

With recent(recent being 3.2.x or newer)kernels if you are using ext4 you can mount it with the discard option as well and you really should never need to run fstrim at all. The exception being when you have been using the filesystem without the discard mount option. Some corners of the web claim discard is a performance hit; it may be a small one but unless your work load is really unusual you won't notice.
 
Old 05-28-2013, 07:15 PM   #3
flokofcgulls
Member
 
Registered: Apr 2013
Posts: 79

Original Poster
Rep: Reputation: Disabled
Yes, I've seen numerous places that talked about using the discard option in fstab, and I even experimented with it for a bit. But, I've also seen several places that said doing it that way wasn't considered a best practice, and that it was better to run it manually. Essentially what I took away from my research was that there's still a lot of debate about what is the best way to administer a system running on an SSD, and there is no clear "correct way" as of yet.

So, what do you do when you have lots of contradicting information? I generally take the more cautious approach, which in this case would be to just run it by hand occasionally...I was thinking maybe once a month would probably be reasonable.

Quote:
Your SSD ware-levels over the entire disk as the controller is not aware of the partition tables; and presents a map of blocks to the operation system that in most cases only it knows how map onto the physical memory cells. So you don't need to worry about part of the disk getting worn out first.
In regards to this statement, if I'm understanding you correctly, is that the disk controller automatically reads/writes to cells across the entire disk, regardless of where the partition tables are? I was under the impression that an SSD was similar to a traditional drive in that read/writes can be spread out within a partition, but not across the entire drive?

Quote:
With recent(recent being 3.2.x or newer)kernels if you are using ext4 you can mount it with the discard option as well and you really should never need to run fstrim at all. The exception being when you have been using the filesystem without the discard mount option.
Well, I do run ext4 within my root partition, but swap has it's own "swap" filesystem. I suppose I could try just using the discard option for swap in fstab, but I'll have to figure out how to test it (hadn't quite gotten that far yet.)

Quote:
Some corners of the web claim discard is a performance hit; it may be a small one but unless your work load is really unusual you won't notice.
Indeed, I have read this on numerous sites; I figured it probably wouldn't be noticeable, but I thought I'd go ahead and take the time to figure it out just so I would understand the whole thing better. Especially since there seem to be a lot of differing opinions, which makes it harder to get a solid answer.

I'll try simply mounting swap with the discard option in fstab, and see if I can confirm whether or not it works, and report back with my findings.
 
Old 05-31-2013, 12:58 PM   #4
flokofcgulls
Member
 
Registered: Apr 2013
Posts: 79

Original Poster
Rep: Reputation: Disabled
Well I have an update on this one.

I discovered that in order to test whether or not TRIM was working correctly requires writing a file to a specific section of the disk, and then checking that section to see if the blocks are zeroed out. Since swap cannot be handled like a regular file system, this makes testing/confirmation impossible.

However, I did discover mention of a kernel feature on three different sites, one on Wikipedia:

Quote:
On Linux, swap partitions automatically exploit TRIM operations when the underlying drive supports TRIM (no configuration is needed).
Which was referenced from a page on the Fedora project:

Quote:
The Linux swap code will issue TRIM commands to TRIM-enabled devices, and there is no option to control this behaviour.
I also saw mention of this one again under the Ubuntu FAQ:

Quote:
Since kernel 2.6.29 the swap system has automatically supported TRIM capable devices like SSDs.
I'm not 100% sure if this holds true when LVM/LUKS is involved, but assuming that TRIM has been enabled at those levels as well, I would guess that it does.

Based on this information, I'm going to assume that the kernel automatically handles TRIM commands on the swap partition without any manual configuration or optimization.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to create swap partition manually kiran.ursal Linux - General 7 10-02-2012 11:53 AM
[SOLVED] scripts is not running thriugh cron ...manually running fine ghoshdastidar1980 Linux - Newbie 3 09-27-2012 03:42 AM
how to mount swap partition running livecd? linus72 Linux - Newbie 1 04-12-2009 09:14 PM
Hard Drive Partition Management - Mandriva Double Partition with Swap File partition moshebagelfresser Linux - Hardware 2 05-23-2008 11:46 AM
Add swap partiiton manually? fireball003 Slackware 7 04-09-2007 06:04 PM


All times are GMT -5. The time now is 10:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration