Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Do I have to enable "TRIM" for SDCard ?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
destroyedlolo
l33t
l33t


Joined: 17 Jun 2011
Posts: 683
Location: Close to Annecy (France)

PostPosted: Thu Mar 07, 2019 9:39 pm    Post subject: Do I have to enable "TRIM" for SDCard ? Reply with quote

Hi all,

I'm running Gentoo on my BananaPI. All "hot" data are on a mechanical SATA drive, but the system is still on the SDCard which is written only during system upgrade.

Anyway, do I need to mount them using the discard/trim option ?

Code:

laurent@torchwood ~ $ lsblk --discard
NAME        DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda                0        0B       0B         0
├─sda1             0        0B       0B         0
└─sda2             0        0B       0B         0
mmcblk0            0        0B       0B         0
├─mmcblk0p1        0        0B       0B         0
└─mmcblk0p2        0        0B       0B         0


Thanks

Laurent
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 42569
Location: 56N 3W

PostPosted: Thu Mar 07, 2019 9:54 pm    Post subject: Reply with quote

destroyedlolo,

Some sdcards support trim, some don't.
Try
Code:
fstrim -av

That's the other option if your card supports trim but you don't use the discard mount option.
You can run fstrim every update or add it as a cron job.

Code:
roy@Aarch64 ~ $ sudo fstrim -av
/: 42.4 GiB (45475172352 bytes) trimmed on /dev/mmcblk1p2

_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.


Last edited by NeddySeagoon on Thu Mar 07, 2019 9:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5592

PostPosted: Thu Mar 07, 2019 9:56 pm    Post subject: Reply with quote

Very unlikely that it supports discard, unless it's a *really* high end sdcard (which kinda defeats the purpose of them - they're meant to be cheap & dirty).

That option won't increase its lifespan in any case, due to the usage pattern. You're more likely to suffer bitrot over time.
Back to top
View user's profile Send private message
destroyedlolo
l33t
l33t


Joined: 17 Jun 2011
Posts: 683
Location: Close to Annecy (France)

PostPosted: Thu Mar 07, 2019 10:02 pm    Post subject: Reply with quote

ok, thanks for your input : I let it as it is :)
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 42569
Location: 56N 3W

PostPosted: Thu Mar 07, 2019 10:20 pm    Post subject: Reply with quote

destroyedlolo,

Trimming solid state storage is good for write speeds and is almost harmless to life.
It may increase 'write amplification' but that depends on what the device does in response to the trim command.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Leio
Developer
Developer


Joined: 27 Feb 2003
Posts: 480
Location: Estonia

PostPosted: Fri Mar 08, 2019 8:18 am    Post subject: Reply with quote

The usual suggestion is to not use discard, but do a periodical (once a week or so) manual fstrim. For some older drives continuous discard may cause problems, not sure what the case is with the actual majority of todays drives and sd cards.
If going the periodical fstrim route, then for systemd you can simply do
Code:
systemctl enable --now fstrim.timer

and for OpenRC you'd need your own cronjob doing fstrim -av or fstrim -a.

If after some bigger deletions on the SD card a manual fstrim -av doesn't report anything freed, then I'd suspect it doesn't support it (or the interface you connect the sd card with doesn't).
_________________
GNOME team lead; GStreamer; MIPS/ARM64
Back to top
View user's profile Send private message
destroyedlolo
l33t
l33t


Joined: 17 Jun 2011
Posts: 683
Location: Close to Annecy (France)

PostPosted: Fri Mar 08, 2019 9:33 am    Post subject: Reply with quote

Hi Neddy,

NeddySeagoon wrote:
Trimming solid state storage is good for write speeds and is almost harmless to life.


Ha, I'm surprised as I read somewhere that the goal of that is to "clear freed blocs in order to avoid to stress unused cells when the system update a cluster".
I read that to write to a Flash memory, it has first to clear cells and then "burns" cells set to 1, which is obviously useless when speaking about freed/unused blocs.
Is it not true ?

Thanks
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 42569
Location: 56N 3W

PostPosted: Fri Mar 08, 2019 7:30 pm    Post subject: Reply with quote

destroyedlolo,

That's an over simplification.

When you issue the trim command, you tell the block device that the data in the trimmed space is no longer required and can be erased.
The 'can be' is important, its not a must be. Its up to the drive when it does the erase. All you can be sure of it that it will be in good time before the block is rewritten.
How long that is depends on how many blocks are in use.

Now it starts to got complicated. Solid state storage has several block sizes. Read block, write block and erase block.
The write block size is usually 4k. The read block size is usually 4k too but both may be faked to be 512B. Don't do that. Writing 512B involves a read/modify/write. The drive will try to gather 512B writes into 4k chunks but there is a limit to how long it will wait.
Those sizes are very visible to users.

The third block size in the erase block size. SSDs have to erase a number of write blocks all at the same time. That's OK if the entire erase block has been trimmed.
What is a single write block (or more) are till in use. There are two choices.
Relocate the in use write block(s) or do nothing and wait because the in use space my be trimmed later. Its up to the drive firmware.

As you say, a block to be rewritten must be erased before the write can take place because the write operation can only flip bits one way.
Erase is a slow operation, so write speed is reduced if you always do an erase immediately before a write. Not before every write, after an erase block is erased, you can fill it with 16, 64, whatever write blocks.
Trim aims to perform the erase ahead of the time when it would be forced, so the waiting for an erase cycle never happens, its always like writing to a new drive for the first time.
Trimming already trimmed or erased space is harmless. The drive keeps track of these things.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum