Author Topic: Trim command  (Read 691 times)

Remy

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 12
  • Posts: 208
    • View Profile
Trim command
« on: January 25, 2020, 10:22:35 am »
SSD may working slower after some time according how the SSD is used.

Do you know if ArcaOs or someone else  could implement a TRIM command under OS/2 ?
I found following link telling about TRIM
http://www.t13.org/Documents/MinutesDefault.aspx?keyword=trim

But I do not having the needed skills....

Cheers 

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2291
    • View Profile
Re: Trim command
« Reply #1 on: January 25, 2020, 06:09:22 pm »
Hi Remy, The Linux JFS does support trim so in theory a partition can be mounted under Linux and trimmed. It should be fine as IBM worked pretty hard to keep the JFS's compatible and if you mount a JFS volume under Mint, it is readable and writeable, the system even mounts it with case insensitivity.
Of course there is a danger so a good backup is required.
Likewise the trim code could be ported except for the license problem :) Too bad that whoever was working on OpenJFS moved on. And of course working on a file driver is hazardous as bugs will wipe out users data.
I've also wondered if simply backing up the SSD and writing zero's to the whole thing would trim it. As long as the controller is smart enough to notice the blocks that are pure zero's, I'd think it would work.
The other thing with SSD's and many modern hard drives is partitioning so that the JFS 4k blocks line up with the internal 4k blocks so that if writing eg one byte, it only affects one hardware block.

Dariusz Piatkowski

  • Hero Member
  • *****
  • Thank You
  • -Given: 13
  • -Receive: 15
  • Posts: 645
    • View Profile
Re: Trim command
« Reply #2 on: January 25, 2020, 06:39:50 pm »
Hi Remy,

When I was gearing up to toss a SSD into my machine I had asked the very same question. The general concensus was that OS/2 did not need this functionality b/c the SSD device itself would be handling this function. That answer never quite sat well with me though.

I am pretty certain that in the past when these devices were new technology the drivers and/or additional utility software itself implemented this functionality along with the OS. For example, the Samsung SSD FAQ (https://www.samsung.com/semiconductor/minisite/ssd/support/faqs-03/) clearly states the following:

Code: [Select]
Q - Does Windows XP support the TRIM feature?

A - No, only Windows 7 and above supports the TRIM feature. The Samsung SSD Magician software enables you to manually use TRIM on both Windows XP and Windows Vista.

The newer hardware on the other hand does appear to have some of this baked-in, or to be more precise it is the combination of OS FS and the hardware that makes it work. Basically, the current OSes have updated FS software which automatically notifies the SSD hardware when a particular block is no longer in use by the OS. That in turn allows the SSD firmware to "trim" accordingly, allowing the SSD firmware to implement wear levelling across it's entire storage cell body.

My experience is only based on working with the Samsung SSD: Evo850 and Pro970 (that's in my Win10 box).

Now, there is a Linux TRIM solution, it is the fstrim command which does not require the OS FS to have teh smarts to auto-trim...not sure if this requires any sort of enhanced device driver functionality, but perhaps worth looking over to see if we could port it?

Here is a link to the fstrim man page => http://man7.org/linux/man-pages/man8/fstrim.8.html

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2291
    • View Profile
Re: Trim command
« Reply #3 on: January 25, 2020, 07:39:00 pm »
The question is how many file systems the hardware understands. Likely FAT(32) and perhaps NTFS but doubtfully JFS or HPFS. As when files are deleted, usually just the directory entry is changed, the hardware can't know if a block is used or not unless it understands the file system. I think the hardware would also understand a zeroed out block to be empty and perhaps work like a sparse file (I once saved a multi megabyte file to a 140 kb floppy, it worked as the file was mostly empty)
The fstrim command looks interesting, the fact that it works on mounted file systems means it knows what blocks are used and it should work on OS/2 JFS. Once again backups are required in case of the Linux JFS not quite being compatible to the OS/2 JFS.

Remy

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 12
  • Posts: 208
    • View Profile
Re: Trim command
« Reply #4 on: January 25, 2020, 07:45:11 pm »
Yes, it seems fstrim could be best option.

About SSD, most have "ssd garbage collection" but it doesn't work very well while trim or fstrim should allow full SSD speed for long time.

Remy

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 12
  • Posts: 208
    • View Profile
Re: Trim command
« Reply #5 on: January 28, 2020, 12:37:08 am »
From  what I could read here is that HPFS has trim now through linux (fstrim)
https://www.phoronix.com/scan.php?page=news_item&px=hpfs-fstrim-added

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2291
    • View Profile
Re: Trim command
« Reply #6 on: January 28, 2020, 04:06:10 am »
So I thought I'd test fstrim. Booted a live USB stick to Mint, mounted the 3 JFS partitions on my SSD and ran sudo fstrim -a -v. It almost instantly went through all 3 partitions and reported that they were trimmed. Doesn't seem right as it was so quick, I'd expect it to go through the file system to decide which blocks were not in use. Perhaps my cheap stick doesn't properly support trim.
OK, reading up on it, the SSD does support trim, and also fairly efficient foreground garbage collection. I get the impression that the partition's need to be used to be trimmed. Windows tells the SSD about every block that is deleted it seems.

Dariusz Piatkowski

  • Hero Member
  • *****
  • Thank You
  • -Given: 13
  • -Receive: 15
  • Posts: 645
    • View Profile
Re: Trim command
« Reply #7 on: January 28, 2020, 05:02:16 am »
Guys, I too spent a little time digging into this.

Here is a great site that puts all of these moving pieces into a good perspective (for me it did anyways) => http://wiki.archlinux.org/index.php/Solid_state_drive

@Dave, my understanding of TRIM OS FS/utility/SSD firmware interaction is as follows:

1) if the FS implements on-the-fly trim marking that allows the SSD firmware to account for any released FS space rigth away

2) if the FS is missing that support a utility such as fstrim can be used, in the link above two modes are described: continuous and periodic

Either way, once the release of the space is done at FS level, it is up to the drive firmware to actually do the re-clamation with the proper cell utilization balancing.

Here is another good link to a more generic review of the TRIM command => http://en.wikipedia.org/wiki/Trim_(computing)

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 481
    • View Profile
Re: Trim command
« Reply #8 on: January 28, 2020, 09:05:02 am »
Putting this all together:
Assuming the trim command needs a starting block and a length (or multiple of these) to do its job I would assume that every filesystem driver (IFS) needs an entry point into the disk driver (ADD) to tell it which blocks can be trimmed.
During operation the FS will be able to collect which areas can be trimmed.
Or did I misunderstand something?

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 481
    • View Profile
Re: Trim command
« Reply #9 on: January 28, 2020, 09:11:39 am »
If a tool is used,then the FS will still need explicit support for trimming (knowing or finding the blocks to trim). A tool just means an entry point into the IFS to perform the job on request.
Because FAT16 support is built into the Kernel, trimming support would require Kernel changes.
Or use Valerius Version of FAT32.IFS and have that handle all FAT16 partitions.

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 481
    • View Profile
Re: Trim command
« Reply #10 on: January 28, 2020, 09:17:56 am »
If you have an SSD with two partitions,say HPFS and JFS formatted,do you need to run fstrim separately on each partition? I assume so.

Olafur Gunnlaugsson

  • Full Member
  • ***
  • Thank You
  • -Given: 35
  • -Receive: 16
  • Posts: 171
    • View Profile
Re: Trim command
« Reply #11 on: January 28, 2020, 12:39:34 pm »
If a tool is used,then the FS will still need explicit support for trimming (knowing or finding the blocks to trim).

No, witness the WinXP era NTFS/FAT32 TRIM tools supplied by the likes of Samsung

Lars

  • Sr. Member
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 45
  • Posts: 481
    • View Profile
Re: Trim command
« Reply #12 on: January 28, 2020, 03:35:14 pm »
Maybe trimming support was introduced in NTFS and FAT32 with later WinXP service packs?
You cannot trim if you don't know what sectors are used or not.

Olafur Gunnlaugsson

  • Full Member
  • ***
  • Thank You
  • -Given: 35
  • -Receive: 16
  • Posts: 171
    • View Profile
Re: Trim command
« Reply #13 on: January 28, 2020, 10:24:29 pm »
Maybe trimming support was introduced in NTFS and FAT32 with later WinXP service packs?
You cannot trim if you don't know what sectors are used or not.
It was introduced in a Vista service pack, and initially at the least only for NTFS, no idea if it is supported in xFATx by MS. It is still a manual process on NFTS by the way, the OS does not trim the drive unless you ask it.

P.S. It is not just SSD's, shingled hard drives from WD and Toshiba also support the Trim command, makes sense on a shingled drive if you think about it. The WD shingled drives are usually large "archive" drives, while Toshiba shingled drives are usually small budget 2.5 external drives.

Dave Yeo

  • Hero Member
  • *****
  • Thank You
  • -Given: 11
  • -Receive: 164
  • Posts: 2291
    • View Profile
Re: Trim command
« Reply #14 on: January 30, 2020, 06:07:48 am »
Well, I reinstalled Mint, mounted my OS/2 volumes and ran sudo fstrim -a -v and this time it reported how much was trimmed, so I assume it worked.