Gentoo Archives: gentoo-user

From: Kai Krakow <hurikhan77@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: {OT} Allow work from home?
Date: Tue, 23 Feb 2016 22:56:14
Message-Id: 20160223235555.572630df@jupiter.sol.kaishome.de
In Reply to: Re: [gentoo-user] Re: {OT} Allow work from home? by lee
1 Am Sat, 20 Feb 2016 11:24:56 +0100
2 schrieb lee <lee@××××××××.de>:
3
4 > > It uses some very clever ideas to place files into groups and into
5 > > proper order - other than using file mod and access times like other
6 > > defrag tools do (which even make the problem worse by doing so
7 > > because this destroys locality of data even more).
8 >
9 > I've never heard of MyDefrag, I might try it out. Does it make
10 > updating any faster?
11
12 Ah well, difficult question... Short answer: It uses countermeasures
13 against performance after updates decreasing too fast. It does this by
14 using a "gapped" on-disk file layout - leaving some gaps for Windows to
15 put temporary files. By this, files don't become a far spread as
16 usually during updates. But yes, it improves installation time.
17
18 Apparently it's unmaintained since a few years but it still does a good
19 job. It was built upon a theory by a student about how to properly
20 reorganize file layout on a spinning disk to stay at high performance
21 as best as possible.
22
23 > > But even SSDs can use _proper_ defragmentation from time to time for
24 > > increased lifetime and performance (this is due to how the FTL works
25 > > and because erase blocks are huge, I won't get into detail unless
26 > > someone asks). This is why mydefrag also supports flash
27 > > optimization. It works by moving as few files as possible while
28 > > coalescing free space into big chunks which in turn relaxes
29 > > pressure on the FTL and allows to have more free and continuous
30 > > erase blocks which reduces early flash chip wear. A filled SSD with
31 > > long usage history can certainly gain back some performance from
32 > > this.
33 >
34 > How does it improve performance? It seems to me that, for practical
35 > use, almost all of the better performance with SSDs is due to reduced
36 > latency. And IIUC, it doesn't matter for the latency where data is
37 > stored on an SSD. If its performance degrades over time when data is
38 > written to it, the SSD sucks, and the manufacturer should have done a
39 > better job. Why else would I buy an SSD. If it needs to reorganise
40 > the data stored on it, the firmware should do that.
41
42 There are different factors which have impact on performance, not just
43 seek times (which, as you write, is the worst performance breaker):
44
45 * management overhead: the OS has to do more house keeping, which
46 (a) introduces more IOPS (which is the only relevant limiting
47 factor for SSD) and (b) introduces more CPU cycles and data
48 structure locking within the OS routines during performing IO which
49 comes down to more CPU cycles spend during IO
50
51 * erasing a block is where SSDs really suck at performance wise, plus
52 blocks are essentially read-only once written - that's how flash
53 works, a flash data block needs to be erased prior to being
54 rewritten - and that is (compared to the rest of its performance) a
55 really REALLY HUGE time factor
56
57 * erase blocks are huge compared to common filesystem block sizes
58 (erase block = 1 or 2 MB vs. file system block being 4-64k usually)
59 which happens to result in this effect:
60
61 - OS replaces a file by writing a new, deleting the old
62 (common during updates), or the user deletes files
63 - OS marks some blocks as free in its FS structures, it depends on
64 the file size and its fragmentation if this gives you a
65 continuous area of free blocks or many small blocks scattered
66 across the disk: it results in free space fragmentation
67 - free space fragments happen to become small over time, much
68 smaller then the erase block size
69 - if your system has TRIM/discard support it will tell the SSD
70 firmware: here, I no longer use those 4k blocks
71 - as you already figured out: those small blocks marked as free do
72 not properly align with the erase block size - so actually, you
73 may end up with a lot of free space but essentially no complete
74 erase block is marked as free
75 - this situation means: the SSD firmware cannot reclaim this free
76 space to do "free block erasure" in advance so if you write
77 another block of small data you may end up with the SSD going
78 into a direct "read/modify/erase/write" cycle instead of just
79 "read/modify/write" and deferring the erasing until later - ah
80 yes, that's probably becoming slow then
81 - what do we learn: (a) defragment free space from time to time,
82 (b) enable TRIM/discard to reclaim blocks in advance, (c) you may
83 want to over-provision your SSD: just don't ever use 10-15% of
84 your SSD, trim that space, and leave it there for the firmware to
85 shuffle erase blocks around
86 - the latter point also increases life-time for obvious reasons as
87 SSDs only support a limited count of write-cycles per block
88 - this "shuffling around" blocks is called wear-levelling: the
89 firmware chooses a block candidate with the least write cycles
90 for doing "read/modify/write"
91
92 So, SSDs actually do this "reorganization" as you call it - but they
93 are limited to it within the bounds of erase block sizes - and the
94 firmware knows nothing about the on-disk format and its smaller blocks,
95 so it can do nothing to go down to a finer grained reorganization.
96
97 These facts are apparently unknown to most people, that's why they are
98 denying a SSD could become slow or needs some specialized form of
99 "defragmentation". The usual recommendation is to do a "secure erase"
100 of the disk if it becomes slow - which I consider pretty harmful as it
101 rewrites ALL blocks (reducing their write-cycle counter/lifetime), plus
102 it's time consuming and could be avoided.
103
104 BTW: OS makers (and FS designers) actually optimize their systems for
105 that kind of reorganization of the SSD firmware. NTFS may use different
106 allocation strategies on SSD (just a guess) and in Linux there is F2FS
107 which actually exploits this reorganization for increased performance
108 and lifetime, Ext4 and Btrfs use different allocation strategies and
109 prefer spreading file data instead of free space (which is just the
110 opposite of what's done for HDD). So, with a modern OS you are much
111 less prone to the effects described above.
112
113 --
114 Regards,
115 Kai
116
117 Replies to list-only preferred.

Replies

Subject Author
Re: [gentoo-user] Re: {OT} Allow work from home? lee <lee@××××××××.de>