Trim support for HC1 and HK USB-SATA adapter

Moderators: mdrjr, odroid

Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Sun Sep 10, 2017 3:10 pm

I've recently tried to run fstrim on two ssds, one connected to the HC1 and the other to HardKernel's USB-SATA bridge attached to a XU4 and in both cases I got:
Code: Select all
# fstrim /media/ssd/ssd250/
fstrim: /media/ssd/ssd250/: the discard operation is not supported


On the XU4 I'm running 4.9.33, on the HC1 I'm running the latest 4.9 kernel.

I am able to fstrim the emmc.

Is this a hardware limitation of going through usb-sata, or am I doing something wrong?
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby DarkBahamut » Mon Sep 11, 2017 1:52 am

A quick google suggests fstrim can't be used on USB disks, even when it should work (IE. the bridge chip correctly does SCSI/ATA translation) - https://bugs.launchpad.net/ubuntu/+sour ... ug/1336541

As an alternative I heard mention that this might work instead - https://github.com/Distrotech/hdparm/tree/master/wiper
DarkBahamut
 
Posts: 242
Joined: Tue Jan 19, 2016 10:19 am
languages_spoken: english
ODROIDs: XU4

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Mon Sep 11, 2017 1:56 am

Oh, I didn't know about that. What about if the disk is seen as uas? I'll look into wiper, thanks
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Mon Sep 11, 2017 3:53 pm

I've tried wiper.sh, but I'm not sure if it really works or not:
Code: Select all
root@odroid:~/development/hdparm/wiper# ./wiper.sh --verbose --commit /dev/sda1

wiper.sh: Linux SATA SSD TRIM utility, version 3.5, by Mark Lord.
rootdev=/dev/mmcblk1p2
/dev/sda1: fstype=ext3
Preparing for offline TRIM of free space on /dev/sda1 (ext3 non-mounted).

This operation could silently destroy your data.  Are you sure (y/N)? y
Syncing disks..
Beginning TRIM operations..
get_trimlist=/sbin/dumpe2fs /dev/sda1

/dev/sda:
trimming 750578 sectors from 83 ranges
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
succeeded
Done.



At every run it reports the same number of sectors to be trimmed. I was thinking it would only report non-trimmed data. There is nothing in dmesg though.
Also, it can't trim with the filesystem mounted:
Code: Select all
/dev/sda4: cannot TRIM ext3 filesystem when mounted read-write, aborting.
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby DarkBahamut » Mon Sep 11, 2017 9:24 pm

mad_ady wrote:Oh, I didn't know about that. What about if the disk is seen as uas? I'll look into wiper, thanks


Yeah, UAS doesn't guarantee any trim support unfortunately. If I test my UAS enclosure (ASM1053) on windows, trim commands are refused.

Code: Select all
PS C:\WINDOWS\system32> Optimize-Volume -DriveLetter L -ReTrim -Verbose
VERBOSE: Invoking retrim on New Volume (L:)...
VERBOSE: Retrim:  100% complete.
Optimize-Volume : The volume optimization operation requested is not supported by the hardware backing the volume.


The JMS578 used on the HC1 has reports online that trim does work however, but support seems to vary depending on the application and firmware backing the bridge. Fingers crossed it should work on the HC1!

As for testing wiper, there's an article here that talks about using hdparm to do before and after sector reads to ensure they get cleared. Hopefully that comes back with good news :)
DarkBahamut
 
Posts: 242
Joined: Tue Jan 19, 2016 10:19 am
languages_spoken: english
ODROIDs: XU4

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Mon Sep 11, 2017 9:42 pm

@DarkBahamut: I wonder if a poor man's trim could be
Code: Select all
dd if=/dev/zero of=/path/to/mountpoint/zero bs=1M
rm /path/to/mountpoint/zero

It would fill all the free space on the partition with zeros, and then you delete the zero file. Most of the data would be written as zero on the ssd, except some control structures for inodes, which would not be zero. Is writing zero on the ssd the same as trimming it?
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby LiquidAcid » Mon Sep 11, 2017 9:53 pm

mad_ady wrote:Is writing zero on the ssd the same as trimming it?

No.
LiquidAcid
 
Posts: 1078
Joined: Fri Oct 11, 2013 11:07 pm
languages_spoken: english
ODROIDs: X2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Mon Sep 11, 2017 10:06 pm

Ok, thanks for clearing that misconception :)
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby dchang0 » Fri Sep 22, 2017 6:48 pm

Are there any plans to add the JMS578's passthrough TRIM support to the HardKernel USB3.0 to SATA Bridge Board Plus?

If so, would it be user-upgradeable firmware allowing existing owners of the board to gain the feature, or would we have to buy a new revision of the board?
dchang0
 
Posts: 107
Joined: Tue Dec 22, 2015 1:29 pm
languages_spoken: english
ODROIDs: C1+, XU4Q

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby odroid » Sat Sep 23, 2017 6:43 am

@dchang0
We have no such information about any possible passthrough TRIM support from JMicron.
User avatar
odroid
Site Admin
 
Posts: 25353
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby dchang0 » Sat Sep 23, 2017 7:09 am

Hmm. According to this review of the Inateck bridge using the same JMS578 chipset, passthrough TRIM is supported on their product (see the table at the bottom of the page, left-hand column):

https://www.anandtech.com/show/10779/in ... ges-review

I do not see mention of TRIM support on JMicron's spec sheet for the JMS578.
dchang0
 
Posts: 107
Joined: Tue Dec 22, 2015 1:29 pm
languages_spoken: english
ODROIDs: C1+, XU4Q

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby odroid » Sat Sep 23, 2017 8:30 am

Thank you for the link.
We will check it with JMicron.
User avatar
odroid
Site Admin
 
Posts: 25353
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby neal » Fri Oct 13, 2017 11:12 am

I have a USB3.0 to SATA Bridge Board Plus that has JMS578 chip inside http://www.hardkernel.com/main/products/prdt_info.php?g_code=G150462654346
and tried this link under Windows 10 http://salutepc.altervista.org/ssd-on-u ... linux.html
It is work. and HC1 has the same version of f/w with it. so I can say it supports trim.

But, I have no luck with HC1 and also x86 desktop which is running under Ubuntu 64bit.
I think that uas kernel driver doesn't translate command ata from scsi.

When I try the command, I can see the log by kernel.
Code: Select all
root@odroid:~# uname -a
Linux odroid 4.9.50+ #21 SMP PREEMPT Fri Oct 13 09:22:57 KST 2017 armv7l armv7l armv7l GNU/Linux

# mount -t ext4 /dev/sda1 /media/hdd -o discard

"EXT4-fs (sda1): mounting with "discard" option, but the device does not support discard
"EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: discard

# fstrim -v /media/hdd

lt-fstrim: /media/hdd: the discard operation is not supported


and kernel source code has returned '-EOPNOTSUPP' at KERNEL_SRC_ROOT/fs/ext4/ioctl.c line 747
because QUEUE_FLAG_DISCARD is not defined at KERNEL_SRC_ROOT/include/linux/blkdev.h line 495
Code: Select all
if (!blk_queue_discard(q)) {
    return -EOPNOTSUPP;
}

Code: Select all
#define QUEUE_FLAG_DISCARD    14      /* support DISCARD */

I'm not familiar with that kernel. but I want to know where is lack of this to support it.
neal
 
Posts: 67
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby LiquidAcid » Fri Oct 13, 2017 8:46 pm

You're not reading the code correctly. QUEUE_FLAG_DISCARD is always defined. The SCSI subsystem just doesn't set the bit (or explicitly clear it), see sd_config_discard() and surrounding code.
LiquidAcid
 
Posts: 1078
Joined: Fri Oct 11, 2013 11:07 pm
languages_spoken: english
ODROIDs: X2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby neal » Tue Dec 05, 2017 3:22 pm

Hi all,

I've tested fstrim command after update new jms578 f/w under HC1 today.
https://wiki.odroid.com/odroid-xu4/software/jms578_fw_update
It works.
my kernel version is
Code: Select all
root@odroid:~# uname -a
Linux odroid 4.14.0+ #8 SMP PREEMPT Wed Nov 29 18:39:48 KST 2017 armv7l armv7l armv7l GNU/Linux
root@odroid:~#
neal
 
Posts: 67
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Tue Dec 05, 2017 4:01 pm

I see that the same controller is available in the SATA board as well (http://www.hardkernel.com/main/products ... 0462654346).
Previous version:
Code: Select all
# ./JMS578FwUpdate  -d /dev/sdb -v
Bridge Firmware Version: v204.74.231.239




Have you tried it on the SATA adapter as well? I have only one, which is in production and I'm reluctant to brick it :)
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby neal » Tue Dec 05, 2017 4:37 pm

mad_ady wrote:Have you tried it on the SATA adapter as well? I have only one, which is in production and I'm reluctant to brick it :)

Yes. I have tried it. and It is still the SATA adapter updated. ;)
If you want to back to the previous version of f/w, you need to use '-b' option to make backup
neal
 
Posts: 67
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Tue Dec 05, 2017 5:19 pm

Thanks for checking.
Two more things I want to ask you:
1. What's the difference between updating with and without NVRAM? What is stored in that NVRAM?
2. After a frimware upgrade - do I need to unplug/replug the disk or unmount and remount it? Do I need to reboot the Odroid? Does it cause a reset of the controller and the disk gets reattached?
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby neal » Tue Dec 05, 2017 5:42 pm

mad_ady wrote:1. What's the difference between updating with and without NVRAM? What is stored in that NVRAM?

There are some information USB PID, VID, S/N and spin-down time or so stored.
mad_ady wrote:2. After a frimware upgrade - do I need to unplug/replug the disk or unmount and remount it? Do I need to reboot the Odroid? Does it cause a reset of the controller and the disk gets reattached?

Yes, you just need to system reboot. but No need unplug/replug the disk.
It will reset the controller and disk get reattached.
neal
 
Posts: 67
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Thu Dec 07, 2017 5:23 pm

I tried to do the flashing in the USB-SATA controller, but failed:
Code: Select all
root@aldebaran:~/JMS578FwUpdater# ./JMS578FwUpdate  -d /dev/sdb -f ./JMS578_Hardkernel_v173.01.00.01.bin -b ./backup.bin
Update Firmware file name: ./JMS578_Hardkernel_v173.01.00.01.bin
Backup Firmware file name: ./backup.bin
Read Back to Backup Error!!
root@aldebaran:~/JMS578FwUpdater# ./JMS578FwUpdate  -d /dev/sdb -f ./JMS578_Hardkernel_v173.01.00.01.bin -b ./backup.bin -nNV
Update Firmware file name: ./JMS578_Hardkernel_v173.01.00.01.bin
Backup Firmware file name: ./backup.bin
CAUTION: Update firmware without NVRAM.
Read Back to Backup Error!!


I'm running kernel 4.9.58. Maybe it's not compatible with the USB-SATA controller?
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby neal » Thu Dec 07, 2017 5:43 pm

You should check device "-d /dev/sdb(/dev/sda)" option with "-v" if it shows us current version correctly.
neal
 
Posts: 67
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Thu Dec 07, 2017 5:52 pm

It does report the version:
Code: Select all
root@aldebaran:~/JMS578FwUpdater# ./JMS578FwUpdate  -d /dev/sdb -v
Bridge Firmware Version: v204.74.231.239

You have new mail in /var/mail/root


But... if I try it on other disks without the same chipset, it reports the same thing :(
Code: Select all
root@aldebaran:~/JMS578FwUpdater# ./JMS578FwUpdate  -d /dev/sda -v
Bridge Firmware Version: v204.74.231.239

root@aldebaran:~/JMS578FwUpdater# ./JMS578FwUpdate  -d /dev/sdc -v
Bridge Firmware Version: v204.74.231.239



/dev/sdb is the correct disk connected to the HK USB-Sata adapter.
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby neal » Thu Dec 07, 2017 6:01 pm

Yes. In my case the same situation. so I tried to pull out all HDD except one plug on JMS578 and then do it again.
neal
 
Posts: 67
Joined: Fri Apr 14, 2017 10:02 am
languages_spoken: english

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Thu Dec 07, 2017 6:44 pm

Ok, I'll try again tomorrow with only this adapter plugged in.
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Fri Dec 08, 2017 4:44 pm

Ok, I moved the adapter and disk to a development XU4 and I still can't update the firmware:
Code: Select all
odroid@odroid:~/JMS578FwUpdater> sudo ./JMS578FwUpdate -v
[sudo] password for odroid:
JMicron Firmware Update Tool v0.0.0.1
Copyright (C) 2017 JMicron Corp.

odroid@odroid:~/JMS578FwUpdater> sudo ./JMS578FwUpdate -d /dev/sda -v
Bridge Firmware Version: v12.149.213.239

odroid@odroid:~/JMS578FwUpdater> sudo ./JMS578FwUpdate -d /dev/sda -f JMS578_Hardkernel_v173.01.00.01.bin  -b backup.bin -nNV
Update Firmware file name: JMS578_Hardkernel_v173.01.00.01.bin
Backup Firmware file name: backup.bin
CAUTION: Update firmware without NVRAM.
Read Back to Backup Error!!
odroid@odroid:~/JMS578FwUpdater> ls -l
total 612
-rwxr-xr-x 1 odroid odroid  50688 Nov  1 05:34 JMS578-v0.1.0.5.bin
-rwxr-xr-x 1 odroid odroid 519032 Nov  1 05:34 JMS578FwUpdate
-rw-r--r-- 1 odroid odroid  50688 Dec  5 01:36 JMS578_Hardkernel_v173.01.00.01.bin



The strange thing is that on a previous boot I got a completely different bridge firmware version:
Code: Select all
odroid@odroid:~/JMS578FwUpdater> sudo ./JMS578FwUpdate -v -d /dev/sda
Bridge Firmware Version: v232.127.180.239


which differs from the version reported on my original Odroid...

Maybe I'm running an older revision of the HK USB-SATA adapter?
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby odroid » Fri Dec 08, 2017 4:57 pm

I think so.
The old adapter had GL3321G2 chipset instead of JMS578. :(
http://www.hardkernel.com/main/products ... 5197048960
User avatar
odroid
Site Admin
 
Posts: 25353
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Trim support for HC1 and HK USB-SATA adapter

Unread postby mad_ady » Fri Dec 08, 2017 5:12 pm

You're right! Now I understand. I have the regular one (the old one). I never realized you released a "plus" version.
Oh well - mystery solved. At least it didn't brick it, which is a nice thing!
Thanks and sorry for the mixup.
User avatar
mad_ady
 
Posts: 2895
Joined: Wed Jul 15, 2015 5:00 pm
Location: Bucharest, Romania
languages_spoken: english
ODROIDs: XU4, C1+, C2


Return to Ubuntu

Who is online

Users browsing this forum: No registered users and 3 guests