1 |
On Monday, 13 April 2020 12:39:11 BST Rich Freeman wrote: |
2 |
> On Mon, Apr 13, 2020 at 1:32 AM <tuxic@××××××.de> wrote: |
3 |
> > fstrim clears blocks, which currently are not in use and which |
4 |
> > contents is != 0. |
5 |
> > |
6 |
> >... |
7 |
> > |
8 |
> > BUT: Clearing blocks is an action, which includes writes to the cells of |
9 |
> > the SSD. |
10 |
> |
11 |
> I see a whole bunch of discussion, but it seems like many here don't |
12 |
> actually understand what fstrim actually does. |
13 |
> |
14 |
> It doesn't "clear" anything, and it doesn't care what the contents of |
15 |
> a block are. It doesn't write to the cells of the SSD per se. |
16 |
> |
17 |
> It issues the TRIM command to the drive for any unused blocks (or a |
18 |
> subset of them if you use non-default options). It doesn't care what |
19 |
> the contents of the blocks are when it does so - it shouldn't even try |
20 |
> to read the blocks to know what their content is. |
21 |
> |
22 |
> Trimming a block won't clear it at all. It doesn't write to the cells |
23 |
> of the SSD either - at least not the ones being trimmed. It just |
24 |
> tells the drive controller that the blocks are no longer in use. |
25 |
> |
26 |
> Now, the drive controller needs to keep track of which blocks are in |
27 |
> use (which it does whether you use fstrim or not), and that data is |
28 |
> probably stored in some kind of flash so that it is persistent, but |
29 |
> presumably that is managed in such a manner that it is unlikely to |
30 |
> fail before the rest of the drive fails. |
31 |
> |
32 |
> On a well-implemented drive trimming actually REDUCES writes. When |
33 |
> you trim a block the drive controller will stop trying to preserve its |
34 |
> contents. If you don't trim it, then the controller will preserve its |
35 |
> contents. Preserving the content of unused blocks necessarily |
36 |
> involves more writing to the drive than just treating as |
37 |
> zero-fillled/etc. |
38 |
> |
39 |
> Now, where you're probably getting at the concept of clearing and |
40 |
> zeroing data is that if you try to read a trimmed block the drive |
41 |
> controller probably won't even bother to read the block from the ssd |
42 |
> and will just return zeros. Those zeros were never written to flash - |
43 |
> they're just like a zero-filled file in a filesystem. If you write a |
44 |
> bazillion zeros to a file on ext4 it will just record in the |
45 |
> filesystem data that you have a bunch of blocks of zero and it won't |
46 |
> allocate any actual space on disk - reading that file requires no |
47 |
> reading of the actual disk beyond the metadata because they're not |
48 |
> stored in actual extents. Indeed blocks are more of a virtual thing |
49 |
> on an SSD (or even hard drive these days), so if a logical block isn't |
50 |
> mapped to a physical storage area there isn't anything to read in the |
51 |
> first place. |
52 |
> |
53 |
> However, when you trimmed the file the drive didn't go find some area |
54 |
> of flash and fill it with zeros. It just marked it as unused or |
55 |
> removed its logical mapping to physical storage. |
56 |
> |
57 |
> In theory you should be able to use discard or trim the filesystem |
58 |
> every 5 minutes with no negative effects at all. In theory. However, |
59 |
> many controllers (especially old ones) aren't well-implemented and may |
60 |
> not handle this efficiently. A trim operation is still an operation |
61 |
> the controller has to deal with, and so deferring it to a time when |
62 |
> the drive is idle could improve performance, especially for drives |
63 |
> that don't do a lot of writes. If a drive has a really lousy |
64 |
> controller then trims might cause its stupid firmware to do stupid |
65 |
> things. However, this isn't really anything intrinsic to the concept |
66 |
> of trimming. |
67 |
> |
68 |
> Fundamentally trimming is just giving the drive more information about |
69 |
> the importance of the data it is storing. Just about any filesystem |
70 |
> benefits from having more information about what it is storing if it |
71 |
> is well-implemented. In a perfect world we'd just enable discard on |
72 |
> our mounts and be done with it. |
73 |
> |
74 |
> I'd probably just look up the recommendations for your particular |
75 |
> drive around trimming and follow those. Somebody may have benchmarked |
76 |
> it to determine how brain-dead it is. If you bought a more name-brand |
77 |
> SSD you're probably more likely to benefit from more frequent |
78 |
> trimming. |
79 |
> |
80 |
> I'm personally using zfs which didn't support trim/discard until very |
81 |
> recently, and I'm not on 0.8 yet, so for me it is a bit of a moot |
82 |
> point. I plan to enable it once I can do so. |
83 |
|
84 |
What Rich said, plus: |
85 |
|
86 |
I have noticed when prolonged fstrim takes place on an old SSD drive of mine |
87 |
it becomes unresponsive. As Rich said this is not because data is being |
88 |
physically deleted, only a flag is switched from 1 to 0 to indicate its |
89 |
availability for further writes. |
90 |
|
91 |
As I understand the firmware performs wear-leveling when it needs to in the |
92 |
HPA allocated blocks, rather than waiting for the user/OS to run fstrim to |
93 |
obtain some more 'free' space. |