OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Remy on January 25, 2020, 10:22:35 am

Title: Trim command
Post by: Remy 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 
Title: Re: Trim command
Post by: Dave Yeo 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.
Title: Re: Trim command
Post by: Dariusz Piatkowski 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/ (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 (http://man7.org/linux/man-pages/man8/fstrim.8.html)
Title: Re: Trim command
Post by: Dave Yeo 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.
Title: Re: Trim command
Post by: Remy 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.
Title: Re: Trim command
Post by: Remy 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
Title: Re: Trim command
Post by: Dave Yeo 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.
Title: Re: Trim command
Post by: Dariusz Piatkowski 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 (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) (http://en.wikipedia.org/wiki/Trim_(computing))
Title: Re: Trim command
Post by: Lars 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?
Title: Re: Trim command
Post by: Lars 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.
Title: Re: Trim command
Post by: Lars 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.
Title: Re: Trim command
Post by: Olafur Gunnlaugsson 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
Title: Re: Trim command
Post by: Lars 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.
Title: Re: Trim command
Post by: Olafur Gunnlaugsson 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.
Title: Re: Trim command
Post by: Dave Yeo 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.
Title: Re: Trim command
Post by: Remy on May 05, 2020, 07:49:06 pm
Just to share my experience following Dave's last update.

I have a SSD with 3 partitions
1 - ArcaOS boot partition
2 - recovery partition
3 - work/home/programs and unixroot partition
Worked like this more than 6 months  (I suppose SSD garbage did its work since this date)     

I burned a DVD with the latest linux mint  (64bits)
I boot from dvd and then mount 2 different os/2 jfs partitions ( 2 and 3 ) and run fstrim on them ...
There is very less write operation on my boot partition 1 (and would like be careful with it and not tried yet)

Afer getting back which seems good result, I boot OS/2 (ArcaOS).
Boot was faster but working on my fird partition was very faster. Looks to be very good and it's worth it

See fstrim result.     
Title: Re: Trim command
Post by: Andy Willis on May 06, 2020, 06:29:08 am
It would be wise to do a backup but I did do fstrim on both my boot and data (jfs) partitions a couple months ago using fstrim booted from mint USB stick successfully.
Title: Re: Trim command
Post by: Dave Yeo on May 06, 2020, 06:55:27 am
I've even done it on Fat32 and HPFS, apparently successfully a few times.
Title: Re: Trim command
Post by: Eugene Tucker on May 06, 2020, 11:11:28 pm
It would be tremendous if this could be ported to Arca OS or any other OS/2 variant.
Title: Re: Trim command
Post by: Dave Yeo on May 07, 2020, 02:03:11 am
It would be tremendous if this could be ported to Arca OS or any other OS/2 variant.

I think it is on Arca Noae's road map for JFS. When they'll find time is another matter.