[SOLVED] why TRIM command is tied to the drive letter in Windows?

Status
Not open for further replies.

Pextaxmx

Reputable
Jun 15, 2020
418
59
4,840
Say I have a 1 Tb SSD with full of garbage data.
I "clean" the drive in Diskpart and make a 100 Gb size partition and leave the remaining capacity unclaimed.
Install Windows and run TRIM for the C drive.

Now what does the SSD do? Does it flag the garbage sectors as garbage for the entire drive or somehow it only TRIMs 100 Gb worth sectors?
 
Solution
In my scenario, full 1 Tb of garbage untrimmed, partition 100 Gb out of 1 Tb, and format only that 100 Gb volume, does it somehow TRIM only the 100Gb? If so how does it choose which sector to TRIM if the firmware always shuffle the locations per wear leveling policy?

The OS tells the drive which LBA ranges are to be TRIM-ed. The firmware then looks up its FTL (Flash Translation Layer) to determine which physical sectors are associated with the specified logical sectors and then marks them as free. The firmware doesn't know anything about partitions or drive letters or file systems. Also, when an LBA is "shuffled" to a new physical sector, the previous physical sector is automatically freed up.

The relevant ATA command is DATA...

USAFRet

Titan
Moderator
even if the drive used to be full of garbage and that un-partitioned space is result of "clean" operation in diskpart? I am even more confused now.
Partitions on an SSD are not the same as with an HDD.
They are not physically defined spaces.

The drive firmware shuffles data around, among ALL the cells. This is for wear leveling.

TRIM simply identifies data that is no longer used, and the garbage collection removes it.
'data', not whole files. Like if you delete a paragraph from a Word doc....the bits that the paragraph used to consume are now liable to be removed. But the Word doc still remains.


The partitions you see in Disk Management are merely logical representations. A cute visual.
Not a physical delineation like what happens with an HDD.
 
  • Like
Reactions: CountMike

Pextaxmx

Reputable
Jun 15, 2020
418
59
4,840
TRIM simply identifies data that is no longer used, and the garbage collection removes it.
How does it identify data that is no longer used? Is that informed by the OS or the firmware already know what to TRIM (if so why it needs separate command for that?)?

If it is by the OS, then it should only TRIM 100 GB worth of data (even though those data are spreaded over the entire 1TB space) because there might be another OS, different file system in another partition.

If it is by the firmware, why it is linked to the drive letter in Windows? In this case, if I have C and D volume in the same SSD, trimming C and trimming D is same thing?
 

USAFRet

Titan
Moderator
How does it identify data that is no longer used? Is that informed by the OS or the firmware already know what to TRIM (if so why it needs separate command for that?)?

If it is by the OS, then it should only TRIM 100 GB worth of data (even though those data are spreaded over the entire 1TB space) because there might be another OS, different file system in another partition.

If it is by the firmware, why it is linked to the drive letter in Windows? In this case, if I have C and D volume in the same SSD, trimming C and trimming D is same thing?
You do not need to invoke the TRIM command manually.
Windows, and I expect the other major OSs, do this automatically.
You just have to have it enabled. The drive firmware does all the work.
 

Pextaxmx

Reputable
Jun 15, 2020
418
59
4,840
My understanding is that partitioning a drive does not invoke TRIM. Windows only invokes TRIM after a partition is formatted or a file is permanently deleted. The remaining 900GB of space will not be TRIM-ed until it is formatted.

ICBW, though.

In my scenario, full 1 Tb of garbage untrimmed, partition 100 Gb out of 1 Tb, and format only that 100 Gb volume, does it somehow TRIM only the 100Gb? If so how does it choose which sector to TRIM if the firmware always shuffle the locations per wear leveling policy?
 
TRIM works on the ENTIRE drive at all times. As said above SSD's do not work the same as spinning drives. On an SSD the resident firmware moves pages of data around as it needs to to provide the wear leveling. You do not know (or even need to know) where your data is physically stored. When and where to TRIM is controlled entirely by the onboard firmware, over which you have no control.
 
In my scenario, full 1 Tb of garbage untrimmed, partition 100 Gb out of 1 Tb, and format only that 100 Gb volume, does it somehow TRIM only the 100Gb? If so how does it choose which sector to TRIM if the firmware always shuffle the locations per wear leveling policy?

The OS tells the drive which LBA ranges are to be TRIM-ed. The firmware then looks up its FTL (Flash Translation Layer) to determine which physical sectors are associated with the specified logical sectors and then marks them as free. The firmware doesn't know anything about partitions or drive letters or file systems. Also, when an LBA is "shuffled" to a new physical sector, the previous physical sector is automatically freed up.

The relevant ATA command is DATA SET MANAGEMENT.

https://documents.westerndigital.co...paper-generic-benefit-for-hard-disk-drive.pdf

I think one way to ensure that the unallocated space is TRIM-ed would be to create a simple volume, quick format it and then delete it. Alternatively, you could create a simple volume without formatting it, assign a drive letter, and then send the RETRIM command to this drive letter via PowerShell ... I think.

Code:
Optimize-Volume -DriveLetter YourDriveLetter -ReTrim -Verbose
 
Last edited:
  • Like
Reactions: Pextaxmx
Solution

Pextaxmx

Reputable
Jun 15, 2020
418
59
4,840
The OS tells the drive which LBA ranges are to be TRIM-ed. The firmware then looks up its FTL (Flash Translation Layer) to determine which physical sectors are associated with the specified logical sectors and then marks them as free. The firmware doesn't know anything about partitions or drive letters or file systems. Also, when an LBA is "shuffled" to a new physical sector, the previous physical sector is automatically freed up.

The relevant ATA command is DATA SET MANAGEMENT.

https://documents.westerndigital.co...paper-generic-benefit-for-hard-disk-drive.pdf

I think one way to ensure that the unallocated space is TRIM-ed would be to create a simple volume, quick format it and then delete it. Alternatively, you could create a simple volume without formatting it, assign a drive letter, and then send the RETRIM command to this drive letter via PowerShell ... I think.

Code:
Optimize-Volume -DriveLetter YourDriveLetter -ReTrim -Verbose
Ahh... this makes so much sense. So partial size partition only trims partial drive and the firmware has the map which sectors to trim for the given moment. Explains why trimming in Windows is linked to a drive letter. And explains how to keep another partition unaffected. And yes, making a full size volume and sending trim is what I would do before re-purposing the SSD.
 

Pextaxmx

Reputable
Jun 15, 2020
418
59
4,840
I'm not so sure about that.

The drive and its firmware does not care about "windows partitions". Data is shuffled around amongst the cells as the drive firmware sees fit.

But I could be wrong.

The key point you missed:

The firmware then looks up its FTL (Flash Translation Layer) to determine which physical sectors are associated with the specified logical sectors and then marks them as free.
 
Status
Not open for further replies.