@@ -140,6 +140,86 @@ the backing devices to passthrough mode.
140
140
writeback mode). It currently doesn't do anything intelligent if it fails to
141
141
read some of the dirty data, though.
142
142
143
+ SSD LONGEVITY: PER-PROCESS CACHE HINTING WITH IO PRIORITY
144
+ ---------------------------------------------------------
145
+
146
+ Processes can be assigned an IO priority using `ionice ` and bcache will
147
+ either try to writeback or bypass the cache based on the IO priority
148
+ level assigned to the process and the configuration of the syfs ioprio
149
+ hints. If configured properly for your workload, this can both increase
150
+ performance and reduce SSD wear (erase/write cycles).
151
+
152
+ Having idle IOs bypass the cache can increase performance elsewhere
153
+ since you probably don't care about their performance. In addition,
154
+ this prevents idle IOs from promoting into (polluting) your cache and
155
+ evicting blocks that are more important elsewhere.
156
+
157
+ Default sysfs values:
158
+ 2,7: ioprio_bypass is hinted for process IOs at-or-below best-effort-7.
159
+ 0,0: ioprio_writeback hinting is disabled by default.
160
+
161
+ Cache hinting is configured by writing 'class,level' pairs to sysfs.
162
+ In this example, we write the following:
163
+
164
+ echo 2,7 > /sys/block/bcache0/bcache/ioprio_bypass
165
+ echo 2,0 > /sys/block/bcache0/bcache/ioprio_writeback
166
+
167
+ Thus, processes with the following IO class (ionice -c) and level (-n)
168
+ will the behave as shown in this table:
169
+
170
+ (-c) IO Class (-n) Class level Action
171
+ -----------------------------------------------------
172
+ (1) Realtime 0-7 Writeback
173
+ (2) Best-effort 0 Writeback
174
+ (2) Best-effort 1-6 Normal, as if hinting were disabled
175
+ (2) Best-effort 7 Bypass cache
176
+ (3) Idle n/a Bypass cache
177
+
178
+ For processes at-or-below best-effort-7 (ionice -c2 -n7), the
179
+ ioprio_bypass behavior is as follows:
180
+
181
+ * Reads will come from the backing device and will not promote into
182
+ (pollute) your cache. If the block being read was already in the cache,
183
+ then it will be read from the cache (and remain cached).
184
+
185
+ * If you are using writeback mode, then low-priority bypass-hinted writes
186
+ will go directly to the backing device. If the write was dirty in
187
+ cache, it will cache-invalidate and write directly to the backing
188
+ device. If a high-priority task later writes the same block then it
189
+ will writeback so no performance is lost for write-after-write.
190
+
191
+ For read-after-bypassed-write, the block will be read from the backing
192
+ device (not cached) so there may be a miss penalty when a low-priority
193
+ process write bypasses the cache followed by a high-priority read that
194
+ would otherwise have hit. In practice, this is not an issue; to date,
195
+ none have wanted low-priority writes and high-priority reads of the
196
+ same block.
197
+
198
+ For processes in our example at-or-above best-effort-0 (ionice -c2 -n0),
199
+ the ioprio_writeback behavior is as follows:
200
+
201
+ * The writeback hint has no effect unless your 'cache_mode' is writeback.
202
+ Assuming writeback mode, all writes at this priority will writeback.
203
+ Of course this will increase SSD wear, so only use writeback hinting
204
+ if you need it.
205
+
206
+ * Reads are unaffected by ioprio_writeback, except that read-after-write
207
+ will of course read from the cache.
208
+
209
+ Linux assigns processes the best-effort class with a level of 4 if
210
+ no process is assigned Thus, without `ionice ` your processes will
211
+ follow normal bcache should_writeback/should_bypass symantecs as if the
212
+ ioprio_writeback/ioprio_bypass sysfs flags were disabled.
213
+
214
+ Also note that in order to be hinted by ioprio_writeback/ioprio_bypass,
215
+ the process must have a valid ioprio setting as returned by
216
+ get_task_io_context()->ioprio. Thus, a process without an IO context
217
+ will be ignored by the ioprio_writeback/ioprio_bypass hints even if your
218
+ sysfs hints specify that best-effort-4 should be flagged for bypass
219
+ or writeback. If in doubt, explicitly set the process IO priority with
220
+ `ionice `.
221
+
222
+ See `man ionice ` for more detail about per-process IO priority in Linux.
143
223
144
224
Howto/cookbook
145
225
--------------
0 commit comments