Enabling trim support on XU4 eMMC (and now SD cards)

Post Reply
DarkBahamut
Posts: 328
Joined: Tue Jan 19, 2016 10:19 am
languages_spoken: english
ODROIDs: XU4, N1
Contact:

Enabling trim support on XU4 eMMC (and now SD cards)

Unread post by DarkBahamut » Sun Aug 21, 2016 9:16 am

For a while now I've been wanting to get trim working on my XU4. Trim can be very useful for keeping flash storage performance up over time but my XU4 has always reported the feature as not supported on the stock 3.10 kernel, even though it's eMMC 5.0 chip should work with it just fine. After a little bit of digging a small kernel change appears to enable support.

Code: Select all

diff --git a/drivers/mmc/host/dw_mmc-exynos.h b/drivers/mmc/host/dw_mmc-exynos.h
index 58ce6d8..5baf7a3 100644
--- a/drivers/mmc/host/dw_mmc-exynos.h
+++ b/drivers/mmc/host/dw_mmc-exynos.h
@@ -83,7 +83,7 @@
 #define EXYNOS4412_FIXED_CIU_CLK_DIV	4
 
 #define EXYNOS_DEF_MMC_0_CAPS	(MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR | \
-				MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23)
+				MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23 | MMC_CAP_ERASE)
 #define EXYNOS_DEF_MMC_1_CAPS	MMC_CAP_CMD23
 #define EXYNOS_DEF_MMC_2_CAPS	(MMC_CAP_CMD23 | MMC_CAP_UHS_SDR104)
 
--
Before patch (stock):

Code: Select all

darkbahamut@odroid:/sys/block/mmcblk0/queue$ cat discard_max_bytes 
0
darkbahamut@odroid:/sys/block/mmcblk0/queue$ sudo fstrim -v /
fstrim: /: the discard operation is not supported
After patch:

Code: Select all

darkbahamut@odroid:/sys/block/mmcblk0/queue$ cat discard_max_bytes 
2199023255040
darkbahamut@odroid:/sys/block/mmcblk0/queue$ sudo fstrim -v /
/: 21.9 GiB (23528411136 bytes) trimmed
Sequential write performance (32GB eMMC):

Before trim: 62.1MB/s
After trim: 72.6MB/s

So far in my testing it all seems to work as expected. The trim completes and there is a performance gain after running it and giving it a few minutes to recover. My eMMC wasn't in too bad shape before but sequential write performance went up around 15% and of course the real benefit is in maintaining that performance, rather than it decreasing over time :)
Last edited by DarkBahamut on Mon Jan 09, 2017 1:02 am, edited 1 time in total.

User avatar
rooted
Posts: 6440
Joined: Fri Dec 19, 2014 9:12 am
languages_spoken: english
Location: Gulf of Mexico, US
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by rooted » Sun Aug 21, 2016 11:21 am

Nice job, assuming this works correctly it should find it's way into the HK git.
Last edited by rooted on Sun Aug 21, 2016 2:00 pm, edited 1 time in total.

User avatar
memeka
Posts: 4242
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by memeka » Sun Aug 21, 2016 1:42 pm

i can confirm trim works similarly on 4.8 kernel (unpatched)

User avatar
meveric
Posts: 9773
Joined: Mon Feb 25, 2013 2:41 pm
languages_spoken: german, english
ODROIDs: X2, U2, U3, XU-Lite, XU3, XU3-Lite, C1, XU4, C2, C1+, XU4Q, HC1, N1, Go
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by meveric » Sun Aug 21, 2016 9:52 pm

I can also confirm this is working, my old 64GB eMMC went from 10~20 MB/sec back to around 60 MB/sec write speed! :)
http://forum.odroid.com/viewtopic.php?p=156507#p156507
Donate to support my work on the ODROID GameStation Turbo Image for U2/U3 XU3/XU4 X2 X C1 as well as many other releases.
Check out the Games and Emulators section to find some of my work or check the files in my repository to find the software i build for ODROIDs.
If you want to add my repository to your image read my HOWTO integrate my repo into your image.

DarkBahamut
Posts: 328
Joined: Tue Jan 19, 2016 10:19 am
languages_spoken: english
ODROIDs: XU4, N1
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by DarkBahamut » Mon Aug 22, 2016 2:58 am

Great to see it recovered a well used eMMC back up in speed, looks to be working nicely then :)

Setting up a job for fstrim to run at least weekly should keep them running pretty well long term now.

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by mdrjr » Mon Aug 22, 2016 9:44 pm

Hello,

Would you mind sending a .patch with email so I can give you credits on the git commit ? Or maybe just PM me your email :)

DarkBahamut
Posts: 328
Joined: Tue Jan 19, 2016 10:19 am
languages_spoken: english
ODROIDs: XU4, N1
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by DarkBahamut » Tue Aug 23, 2016 4:56 am

Sure, it's actually just my forum username @gmail.com :)

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by mdrjr » Tue Aug 23, 2016 11:28 am

DarkBahamut wrote:Sure, it's actually just my forum username @gmail.com :)
Thank you for picking this one :)

https://github.com/hardkernel/linux/com ... 8200e9a176

It will be live in a few minutes for everyone :)

distortedvoice
Posts: 7
Joined: Sat Jun 04, 2016 4:27 pm
languages_spoken: english
ODROIDs: .
XU4 - GST Jessie - OC 1.6GHz/2.1GHz - dual heatsinks
Odroid GO
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by distortedvoice » Fri Oct 07, 2016 4:25 am

Very nice! This got my XU4 back up to speed! Much appreciated!

DarkBahamut
Posts: 328
Joined: Tue Jan 19, 2016 10:19 am
languages_spoken: english
ODROIDs: XU4, N1
Contact:

Re: Enabling trim support on XU4 eMMC

Unread post by DarkBahamut » Mon Jan 09, 2017 1:00 am

I never really used SD cards in my XU4 before but I noticed that after starting to use one more recently that discard/trim wasn't supported on those either, but it should be usable on most modern SD cards. Applying the same little change to the other mmc host fixes the issue and should enable trim support on SD cards. Useful for anyone using an SD card with an XU3/4 :)

Before:

Code: Select all

sudo fstrim -v /media/sdcard
fstrim: /media/sdcard: the discard operation is not supported
After:

Code: Select all

darkbahamut@odroid:~$ cat /sys/block/mmcblk1/queue/discard_max_bytes
2199023255040
sudo fstrim -v /media/sdcard
/media/sdcard: 57.5 GiB (61703729152 bytes) trimmed
Patch:

Code: Select all

From 0f8ee7c86d606adc70fb19e5cc6e3bd5fdfef28b Mon Sep 17 00:00:00 2001
From: DarkBahamut <darkbahamut@gmail.com>
Date: Sun, 8 Jan 2017 15:51:06 +0000
Subject: [PATCH] Enable discard (trim) support on SD cards

---
 drivers/mmc/host/dw_mmc-exynos.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/host/dw_mmc-exynos.h b/drivers/mmc/host/dw_mmc-exynos.h
index 5baf7a3..c681223 100644
--- a/drivers/mmc/host/dw_mmc-exynos.h
+++ b/drivers/mmc/host/dw_mmc-exynos.h
@@ -85,7 +85,7 @@
 #define EXYNOS_DEF_MMC_0_CAPS	(MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR | \
 				MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23 | MMC_CAP_ERASE)
 #define EXYNOS_DEF_MMC_1_CAPS	MMC_CAP_CMD23
-#define EXYNOS_DEF_MMC_2_CAPS	(MMC_CAP_CMD23 | MMC_CAP_UHS_SDR104)
+#define EXYNOS_DEF_MMC_2_CAPS	(MMC_CAP_CMD23 | MMC_CAP_UHS_SDR104 | MMC_CAP_ERASE)
 
 #define MAX_TUNING_RETRIES	6
 #define MAX_TUNING_LOOP		(MAX_TUNING_RETRIES * 8 * 2)
-- 
2.7.4


mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: Enabling trim support on XU4 eMMC (and now SD cards)

Unread post by mdrjr » Tue Jan 10, 2017 7:55 am

Hello DarkBahamut,

Thanks again, :) I'm just merged it on our kernel.

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: field3d and 2 guests