LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 03-01-2012, 05:18 AM   #1
pittsley
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Rep: Reputation: Disabled
Does the kernel send the TRIM command when formatting a partition ?


Hello,

I've read that for the kernel to send the TRIM command when you delete a file on an SSD you have to add the 'discard' option in /etc/fstab.

When you format a partition you delete all the files at the OS level since you create a new file system. However when you do so with a linux utility such as GParted the partition is unmounted therefore I suppose that all the options including 'discard' in /etc/fstab don't apply.

So I would like to know : does the kernel (which supports TRIM since version 2.6.33) send the TRIM command to the SSD controller when you format a partition with GParted ?

Thank you in advance for your help.
 
Old 03-01-2012, 08:34 AM   #2
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 11,204
Blog Entries: 3

Rep: Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433
Member response

Hi,

Welcome to LQ!

It seems you do not understand the 'TRIM' function as pertaining to 'SSD';
Quote:
excerpt from 'TRIM' wiki;
In computing, a TRIM command allows an operating system to inform a solid-state drive (SSD) which blocks of data are no longer considered in use and can be wiped internally. While TRIM is frequently spelled in capital letters, it is a command name, not an acronym.[1]
TRIM was introduced soon after SSDs started to become an affordable alternative to traditional hard disks. Because low-level operation of SSDs differs significantly from mechanical hard disks, the typical way in which operating systems handle operations like deletes and formats (not explicitly communicating the involved sectors/pages to the underlying storage medium) resulted in unanticipated progressive performance degradation of write operations on SSDs.[2] TRIM enables the SSD to handle garbage collection overhead, that would otherwise significantly slow down future write operations to the involved blocks, in advance.[3]
Although tools to "reset" some drives to a fresh state were already available before the introduction of TRIM, they also delete all data on the drive, which makes them impractical to use for ongoing optimization.[4] More recent SSDs will often contain internal idle/background garbage collection mechanisms that work independently of TRIM; although this successfully maintains their performance even under operating systems that do not (yet) support TRIM, it has the associated drawbacks of increased write amplification and wear of the flash cells.[5]
 
Old 03-01-2012, 09:11 AM   #3
pittsley
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by onebuck View Post
Hi,

Welcome to LQ!

It seems you do not understand the 'TRIM' function as pertaining to 'SSD';
Hello and thank you very much for your answer !

I'm not sure to understand what you mean.

I've been reading documentation about SSDs and how they work for the last 2 months during my free time. I read the page you quoted and much more (garbage collection, write amplification, write combining, over-provisioning, wear leveling etc.). I read the whole trilogy of articles about SSDs written by Anand. I've written for myself an .odt file of 25 pages so far to remember and organize all the information that I could find on SSDs.

For TRIM to function you must have a chain of 4 different elements that support it : the OS, the file system, the sata controller driver and the firmware of the ssd.

I already asked the same question on GParted forums and I've been told that it's not sent by the application but probably by the OS, which is what Wikipedia says. In the link you quoted it is said that it's a command sent by the OS not by the SSD.

Here it is said that the 'ATA Trim' command was added into the kernel in version 2.6.33 :
Quote:
For instance, the Linux kernel is now capable of "ATA Trim", which improves the performance and lifespan of SSDs.
So it's definitely something that the kernel does.
Yes it's not enough. The SSD, the SATA driver, and the file system must also support it. But ultimately it's the OS that sends this command.

Please if I'm wrong in my understanding of things could you clarify the functioning of TRIM for me ? Not what it does, I know TRIM is sent to remove LBA addresses of deleted files (at the file system level) in the allocation table of the SSD controller, but what sends TRIM ? If it's not the kernel then what ? It can't be the SSD, if the controller could know all by himself which data were still valid on the NAND and which data were invalid then there would be no need for TRIM in the first place.

Any help and advice would be greatly appreciated.

Last edited by pittsley; 03-01-2012 at 10:20 AM.
 
Old 03-01-2012, 10:46 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 11,204
Blog Entries: 3

Rep: Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433
Member response

Hi,

You are mixing things!

'Gparted' would handle the operations via the system controller to the 'SSD' controller which is maintained operation from the kernel thus no need for the 'TRIM' until requested to remove/replace blocks/data. 'TRIM' is a function(of the SSD controller) that allows the discard of no longer used blocks or data. Your 'SSD' controller must support 'TRIM' not just the kernel PATA/SATA. This interoperability is useful when writing/removing data on 'SSD' to free the unwanted area to be used by other operation(s) for a filesystem.

Look at it in this way: When you use 'Gparted' on a partition to resize or move data it is done incrementally(simplistic view) to allow the data to be presented to the 'SSD'. Same as a 'mke2fs' done incrementally to the 'SSD' to create the filesystem. Now once the creation of the filesystem then 'TRIM' when supported will allow control of adding/removing unwanted blocks/data thus discard to the supported 'SSD' controller from the system controller(SATA) communicating the request(s) from the kernel.

Quote:
For TRIM to function you must have a chain of 4 different elements that support it : the OS, the file system, the sata controller driver and the firmware of the ssd.
I would add that the controller firmware for the 'SSD' since the SATA controller(system) does the requested operation(s) as supported with 'SATA revision 3.1' for added TRIM support within the Linux Kernel.

Linux Kernel Interactive Map provides the means to to see kernel interoperability. May help by providing a visual presentation.

Few links from my link list that may help;
SATA
Parallel ATA
TRIM
Flash File System
SSD SSD-optimized file systems
Gparted
 
Old 03-01-2012, 12:01 PM   #5
pittsley
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hello again !

I think there's a misunderstanding, but I'm not sure.

Obviously I don't have as much knowledge on the subject as you. I know all the links you put, I read them, I understood some part of it but not everything. Unfortunately they are really too technical for me (not to mention English is not my native language I just learned it by reading blogs/comics/articles on the web).

Before going further just to be sure that I did not completely misunderstand everything could you tell me if you agree with this ? :

When I delete a file from a file system that supports 'TRIM', if the 'discard' option is present in /etc/fstab then the kernel sends a 'TRIM' command to the SSD controller. If the SATA driver plus the SSD firmware support 'TRIM' then the command has the following result : in the allocation table of the SSD controller, the LBA addresses corresponding to the deleted file are removed.

Is this correct or wrong ?

I'm sorry to bother you with my questions but I won't be able to understand on my own.

Thank you in advance.

Edit : I'm sorry when I said "the LBA addresses corresponding to the deleted file are removed", I should have said "the associations between LBA addresses corresponding to the deleted file and the flash pages of the NAND are removed". At least that's what I understood after reading this kind of articles :

Quote:
This is where the TRIM function comes in. First mooted in 2007 by T13, the technical committee in charge of defining ATA standard specs, it is a command that lets the system tell the storage device that an LBA contains data that is now invalid.

This may seem stupid but it will considerably simplify things for SSD controllers in terms of keeping performance levels up. In terms of the controller, there is no fixed implementation but logically speaking the reference in the LBA / Flash page allocation table is deleted.

Last edited by pittsley; 03-01-2012 at 12:53 PM.
 
Old 03-01-2012, 01:15 PM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 11,204
Blog Entries: 3

Rep: Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433
Member response

Hi,

One suggestion would be to use a web translator like: Google Translate

You are getting a good understanding, just not there yet. First the filesystem must support 'TRIM': Linux Filesystems for Modern SSDs and TRIM Support.

Hopefully when you created the partition it was aligned for use with the 'SSD'. Within the static file '/etc/fstab' you must then explicitly define by enable of 'TRIM' with the 'discard' option for each of the qualified partition(s).

Once you have the 'discard' enabled then the functionality will be through the controller device handler to the 'SSD' controller whenever you are removing/adding data. Primarily the 'TRIM' will 'discard' any padding.

As for release of 'blocks', this is handled by the filesystem utilities. Write of information for a 'SSD' is handled differently then a spinning disk system. A write to the 'SSD' using 'TRIM' to discard padding to next available block. Primary reason for partition alignment for 'SSD', so there are no sector losses thus wasted space.

Please look at these links;
SATA
Parallel ATA
TRIM
Flash File System <<<<Look here
SSD
SSD-optimized file systems; <<<<<Look here
Quote:
Linux systems
The Linux kernel supports the TRIM function starting with version 2.6.33. The ext4 file system is supported when mounted using the "discard" parameter. Linux distributions usually do not set this kind of configuration automatically during installation.[105] The disk utilities (and therefore installation software that make use of them) have the ability to apply proper partition alignment.
Gparted

After reading through the above links for understanding, you should be able to fully see how 'SSD' work with the filesystem.

No need to apologize. We all start out somewhere!

"Knowledge is of two kinds. We Know a subject ourselves, or we know where we can find information upon it."- Samuel Johnson

A tool is but the extension of a man's hand and a machine is but a complex tool. He that invents a machine augments the power of man and the well being of mankind.” - Henry Ward Beecher

HTH!
 
Old 03-01-2012, 02:36 PM   #7
pittsley
LQ Newbie
 
Registered: Mar 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hello,

the reason why I apologize is because I read everything you wrote, I know a lot of the links you put, and I agree with everything. I mean I do not understand everything, there are very technical words that I don't grasp the meaning, but as a whole I agree with everything you said in this topic. And yet I still have this question that seems to be stupid therefore I feel stupid.

I will reread all the links you provided me in this topic, I promise I will, but not now. I'm really really really tired. When I said I've been reading all the documentation that I could find on the web about how an SSD works, how to align partitions, what's CHS/LBA addressing, what's the structure of NAND etc. for the last 2 months, it wasn't a joke. I used all my free time, if I told you how many hours I spent you probably wouldn't believe me. The result is depressing.

I will definitely read your links, I just want to explain one last time why I created this topic, after this I will stop up the topic.

Here's where my question comes.

On this page Anand wrote this :
Quote:
In the Anthology I simulated this worst used case by first filling the drive with data, deleting the partition, then installing the OS and running my benchmarks. This worked very well because it filled every single flash block with data. The OS installation and actual testing added a few sprinkles of randomness that helped make the scenario even more strenuous, which I liked.
In this quote, Anand explains that before TRIM was implemented, to simulate a used SSD, he would simply fill it with data, then he would dele the partition and install an OS. All the data were still there on the NAND leading to poor performance which was Anand's purpose : simulate a used SSD.

Here's the conclusion that I drew as soon as I read this and that I wrote in my .odt feedback :
Formatting a partition on an old SSD (old = wich doesn't support TRIM) doesn't delete the data on the NAND.

Now here's what he further wrote :

Quote:
The problem here is that if a drive properly supports TRIM, the act of formatting the drive will erase all of the wonderful used data I purposefully filled the drive with. My “used” case on a drive supporting TRIM will now just be like testing a drive in a brand new state.
So now he says that if the SSD supports TRIM the act of formatting the drive will erase all the old data.

My conclusion was :
Formatting a new SSD (new = which supports TRIM) deletes all the old data. Why ? I'm not sure but since the only way for the controller of an SSD to be able to know in advance that a data is invalid is the TRIM command, then, the explanation is probably because the kernel sent a TRIM command to tell the SSD controller that all the data should be considered as invalid, afterwards garbage collection deleted all the data.

Anyway what I would like is this : when I format a partition on an SSD, I want all the data it contains to be erased from NAND or at least that the kernel tells my SSD controller "Hey, you see all the data that are on this partition that GParted is about to format ? Well consider them as invalid, you can erase them as soon as you want, I don't mind they aren't useful anymore."

The problem was that during his tests Anand probably didn't use Linux nor GParted but rather Windows and its built-in formatting tool. So I know that when you use Windows to format a partition full of data one way or another all the data are erased from NAND, and your SSD is like brand new. The performance are full back.

However I wondered if it was the same with Linux. If I've got an SSD with one Linux partition full of data, the performance of my SSD will be lowered (because plenty of data = less over-provisioning = more write amplification, those graphics explain it better).

But what happens if I format my partition with a linux utility to reinstall a fresh new Linux distribution ?
Will all the data it contains be erased at the NAND level or at least will the SSD controller be informed that all those data are now invalid like it seems to be in Windows ?
And like Anand did, will I notice that my SSD performance are full back like if it was brand new ?

I opened this topic in order to answer those questions.
I know secure erase but I find it a little overkill, because each time you make a secure erase you burn one p/e (programming/erase) cycle for all the cells of your NAND. I just want the data of the partition I'm formatting to be gone from NAND or the SSD controller to know he can erase them whenever he wants (whenever != at the last moment, I don't want to pay the read-modify-write cycle penalty, all the purpose of TRIM and garbage collection is to delete invalid data before), just those data, not reprogram every single cell.

Now I'm going to rest a little and tomorrow I will start reading all your links, maybe I will understand everything better.

Thank you for your suggestions and for your time, it was really appreciated.

Last edited by pittsley; 03-01-2012 at 02:49 PM.
 
Old 03-01-2012, 04:45 PM   #8
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 11,204
Blog Entries: 3

Rep: Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433
Member response

Hi,

Maybe this will help you to understand how the cells are handled for writes by the SSD controller not the SATA/PATA controller;
Quote:
from Write Amplification: Garbage_Collection;Data is written to the flash memory in units called pages (made up of multiple cells). However, the memory can only be erased in larger units called blocks (made up of multiple pages).[7] If the data in some of the pages of the block are no longer needed (also called stale pages), only the pages with good data in that block are read and re-written into another previously erased empty block.[2] Then the free pages left by not moving the stale data are available for new data. This is a process called garbage collection (GC).[1][12] All SSDs include some level of garbage collection, but they may differ in when and how fast they perform the process.[12] Garbage collection is a big part of write amplification on the SSD.[1][12]
Reads do not require an erase of the flash memory, so they are not generally associated with write amplification. In the limited chance of a read disturb error, the data in that block is read and rewritten, but this would not have any material impact on the write amplification of the drive.[14]
Be sure to look at the cell example for:
Quote:
Pages are written into blocks until they become full. Then the pages with current data are moved to a new block and the old block is erased.[7]
Good visual example that will help clear things.

You just need to remember that the state will not be there once you request a write since the cell will be erased at some point in time then the data in that cell will be written to another valid cell. Paging is the way data/cell blocks are placed on the SSD. One of the main reasons to use a manufacture SSD utilities to hopefully set the state(s) back to a known good level.
Quote:
Here's where my question comes.
Things have changed dramatically in 2 1/2 years. SSD Controller technology has improved since that article was written. I can now see where your confusion comes from. You could do a search for Sandforce controller white papers;

SandForce SSD controller brings newfound speed - Electronic ... many useful links and information that is current that will help.

SandForce - Technology is useful to understand ' DuraClass and DuraWrite technology'. Be sure to look at the Facts section and then Glossary. Sure mostly ad but useful to get keywords for you to search on.

SandForce is providing a robust and reliable SSD controller that provides the means to use the cheaper MLC rather than the costlier SLC technology.
 
  


Reply

Tags
pata, sata, ssd, trim


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
Should TRIM be used on SWAP partition? wulp Linux - Hardware 12 12-07-2012 09:17 AM
TRIM/discard not working any more for ext4 partition on SSD revinary Linux - Hardware 0 11-15-2011 09:19 AM
What is the unix command to trim multiple spaces into single space? manohare Linux - General 4 03-02-2009 07:25 AM
Sony Vaio S5HP "ata1: BUG: timeout without command" while formatting a partition MainThink Linux - Laptop and Netbook 2 10-14-2006 02:08 AM
Java Problem on trim command k1ll3r_x Programming 2 09-12-2005 03:49 PM


All times are GMT -5. The time now is 05:38 AM.

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