]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
d164b209 | 22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
34dc7c2f BB |
23 | * Use is subject to license terms. |
24 | */ | |
25 | ||
cc92e9d0 | 26 | /* |
492f64e9 | 27 | * Copyright (c) 2012, 2018 by Delphix. All rights reserved. |
cc92e9d0 GW |
28 | */ |
29 | ||
34dc7c2f | 30 | #include <sys/zfs_context.h> |
34dc7c2f | 31 | #include <sys/vdev_impl.h> |
330847ff | 32 | #include <sys/spa_impl.h> |
34dc7c2f BB |
33 | #include <sys/zio.h> |
34 | #include <sys/avl.h> | |
e8b96c60 | 35 | #include <sys/dsl_pool.h> |
3dfb57a3 | 36 | #include <sys/metaslab_impl.h> |
e8b96c60 MA |
37 | #include <sys/spa.h> |
38 | #include <sys/spa_impl.h> | |
330847ff | 39 | #include <sys/kstat.h> |
a6255b7f | 40 | #include <sys/abd.h> |
34dc7c2f BB |
41 | |
42 | /* | |
e8b96c60 MA |
43 | * ZFS I/O Scheduler |
44 | * --------------- | |
45 | * | |
46 | * ZFS issues I/O operations to leaf vdevs to satisfy and complete zios. The | |
47 | * I/O scheduler determines when and in what order those operations are | |
48 | * issued. The I/O scheduler divides operations into five I/O classes | |
49 | * prioritized in the following order: sync read, sync write, async read, | |
50 | * async write, and scrub/resilver. Each queue defines the minimum and | |
51 | * maximum number of concurrent operations that may be issued to the device. | |
52 | * In addition, the device has an aggregate maximum. Note that the sum of the | |
53 | * per-queue minimums must not exceed the aggregate maximum. If the | |
54 | * sum of the per-queue maximums exceeds the aggregate maximum, then the | |
55 | * number of active i/os may reach zfs_vdev_max_active, in which case no | |
56 | * further i/os will be issued regardless of whether all per-queue | |
57 | * minimums have been met. | |
58 | * | |
59 | * For many physical devices, throughput increases with the number of | |
60 | * concurrent operations, but latency typically suffers. Further, physical | |
61 | * devices typically have a limit at which more concurrent operations have no | |
62 | * effect on throughput or can actually cause it to decrease. | |
63 | * | |
64 | * The scheduler selects the next operation to issue by first looking for an | |
65 | * I/O class whose minimum has not been satisfied. Once all are satisfied and | |
66 | * the aggregate maximum has not been hit, the scheduler looks for classes | |
67 | * whose maximum has not been satisfied. Iteration through the I/O classes is | |
68 | * done in the order specified above. No further operations are issued if the | |
69 | * aggregate maximum number of concurrent operations has been hit or if there | |
70 | * are no operations queued for an I/O class that has not hit its maximum. | |
71 | * Every time an i/o is queued or an operation completes, the I/O scheduler | |
72 | * looks for new operations to issue. | |
73 | * | |
74 | * All I/O classes have a fixed maximum number of outstanding operations | |
75 | * except for the async write class. Asynchronous writes represent the data | |
76 | * that is committed to stable storage during the syncing stage for | |
77 | * transaction groups (see txg.c). Transaction groups enter the syncing state | |
78 | * periodically so the number of queued async writes will quickly burst up and | |
79 | * then bleed down to zero. Rather than servicing them as quickly as possible, | |
80 | * the I/O scheduler changes the maximum number of active async write i/os | |
81 | * according to the amount of dirty data in the pool (see dsl_pool.c). Since | |
82 | * both throughput and latency typically increase with the number of | |
83 | * concurrent operations issued to physical devices, reducing the burstiness | |
84 | * in the number of concurrent operations also stabilizes the response time of | |
85 | * operations from other -- and in particular synchronous -- queues. In broad | |
86 | * strokes, the I/O scheduler will issue more concurrent operations from the | |
87 | * async write queue as there's more dirty data in the pool. | |
88 | * | |
89 | * Async Writes | |
90 | * | |
91 | * The number of concurrent operations issued for the async write I/O class | |
92 | * follows a piece-wise linear function defined by a few adjustable points. | |
93 | * | |
94 | * | o---------| <-- zfs_vdev_async_write_max_active | |
95 | * ^ | /^ | | |
96 | * | | / | | | |
97 | * active | / | | | |
98 | * I/O | / | | | |
99 | * count | / | | | |
100 | * | / | | | |
101 | * |------------o | | <-- zfs_vdev_async_write_min_active | |
102 | * 0|____________^______|_________| | |
103 | * 0% | | 100% of zfs_dirty_data_max | |
104 | * | | | |
105 | * | `-- zfs_vdev_async_write_active_max_dirty_percent | |
106 | * `--------- zfs_vdev_async_write_active_min_dirty_percent | |
107 | * | |
108 | * Until the amount of dirty data exceeds a minimum percentage of the dirty | |
109 | * data allowed in the pool, the I/O scheduler will limit the number of | |
110 | * concurrent operations to the minimum. As that threshold is crossed, the | |
111 | * number of concurrent operations issued increases linearly to the maximum at | |
112 | * the specified maximum percentage of the dirty data allowed in the pool. | |
113 | * | |
114 | * Ideally, the amount of dirty data on a busy pool will stay in the sloped | |
115 | * part of the function between zfs_vdev_async_write_active_min_dirty_percent | |
116 | * and zfs_vdev_async_write_active_max_dirty_percent. If it exceeds the | |
117 | * maximum percentage, this indicates that the rate of incoming data is | |
118 | * greater than the rate that the backend storage can handle. In this case, we | |
119 | * must further throttle incoming writes (see dmu_tx_delay() for details). | |
34dc7c2f | 120 | */ |
d3cc8b15 | 121 | |
34dc7c2f | 122 | /* |
e8b96c60 MA |
123 | * The maximum number of i/os active to each device. Ideally, this will be >= |
124 | * the sum of each queue's max_active. It must be at least the sum of each | |
125 | * queue's min_active. | |
34dc7c2f | 126 | */ |
e8b96c60 | 127 | uint32_t zfs_vdev_max_active = 1000; |
34dc7c2f | 128 | |
cb682a17 | 129 | /* |
e8b96c60 MA |
130 | * Per-queue limits on the number of i/os active to each device. If the |
131 | * number of active i/os is < zfs_vdev_max_active, then the min_active comes | |
132 | * into play. We will send min_active from each queue, and then select from | |
133 | * queues in the order defined by zio_priority_t. | |
134 | * | |
135 | * In general, smaller max_active's will lead to lower latency of synchronous | |
136 | * operations. Larger max_active's may lead to higher overall throughput, | |
137 | * depending on underlying storage. | |
138 | * | |
139 | * The ratio of the queues' max_actives determines the balance of performance | |
140 | * between reads, writes, and scrubs. E.g., increasing | |
141 | * zfs_vdev_scrub_max_active will cause the scrub or resilver to complete | |
142 | * more quickly, but reads and writes to have higher latency and lower | |
143 | * throughput. | |
cb682a17 | 144 | */ |
e8b96c60 MA |
145 | uint32_t zfs_vdev_sync_read_min_active = 10; |
146 | uint32_t zfs_vdev_sync_read_max_active = 10; | |
147 | uint32_t zfs_vdev_sync_write_min_active = 10; | |
148 | uint32_t zfs_vdev_sync_write_max_active = 10; | |
149 | uint32_t zfs_vdev_async_read_min_active = 1; | |
150 | uint32_t zfs_vdev_async_read_max_active = 3; | |
06226b59 | 151 | uint32_t zfs_vdev_async_write_min_active = 2; |
e8b96c60 MA |
152 | uint32_t zfs_vdev_async_write_max_active = 10; |
153 | uint32_t zfs_vdev_scrub_min_active = 1; | |
154 | uint32_t zfs_vdev_scrub_max_active = 2; | |
a1d477c2 MA |
155 | uint32_t zfs_vdev_removal_min_active = 1; |
156 | uint32_t zfs_vdev_removal_max_active = 2; | |
619f0976 GW |
157 | uint32_t zfs_vdev_initializing_min_active = 1; |
158 | uint32_t zfs_vdev_initializing_max_active = 1; | |
1b939560 BB |
159 | uint32_t zfs_vdev_trim_min_active = 1; |
160 | uint32_t zfs_vdev_trim_max_active = 2; | |
34dc7c2f | 161 | |
e8b96c60 MA |
162 | /* |
163 | * When the pool has less than zfs_vdev_async_write_active_min_dirty_percent | |
164 | * dirty data, use zfs_vdev_async_write_min_active. When it has more than | |
165 | * zfs_vdev_async_write_active_max_dirty_percent, use | |
166 | * zfs_vdev_async_write_max_active. The value is linearly interpolated | |
167 | * between min and max. | |
168 | */ | |
169 | int zfs_vdev_async_write_active_min_dirty_percent = 30; | |
170 | int zfs_vdev_async_write_active_max_dirty_percent = 60; | |
34dc7c2f BB |
171 | |
172 | /* | |
45d1cae3 BB |
173 | * To reduce IOPs, we aggregate small adjacent I/Os into one large I/O. |
174 | * For read I/Os, we also aggregate across small adjacency gaps; for writes | |
175 | * we include spans of optional I/Os to aid aggregation at the disk even when | |
176 | * they aren't able to help us aggregate at this level. | |
34dc7c2f | 177 | */ |
d4a72f23 | 178 | int zfs_vdev_aggregation_limit = 1 << 20; |
1af240f3 | 179 | int zfs_vdev_aggregation_limit_non_rotating = SPA_OLD_MAXBLOCKSIZE; |
9babb374 | 180 | int zfs_vdev_read_gap_limit = 32 << 10; |
45d1cae3 | 181 | int zfs_vdev_write_gap_limit = 4 << 10; |
34dc7c2f | 182 | |
3dfb57a3 DB |
183 | /* |
184 | * Define the queue depth percentage for each top-level. This percentage is | |
185 | * used in conjunction with zfs_vdev_async_max_active to determine how many | |
186 | * allocations a specific top-level vdev should handle. Once the queue depth | |
187 | * reaches zfs_vdev_queue_depth_pct * zfs_vdev_async_write_max_active / 100 | |
188 | * then allocator will stop allocating blocks on that top-level device. | |
189 | * The default kernel setting is 1000% which will yield 100 allocations per | |
190 | * device. For userland testing, the default setting is 300% which equates | |
191 | * to 30 allocations per device. | |
192 | */ | |
193 | #ifdef _KERNEL | |
194 | int zfs_vdev_queue_depth_pct = 1000; | |
195 | #else | |
196 | int zfs_vdev_queue_depth_pct = 300; | |
197 | #endif | |
198 | ||
492f64e9 PD |
199 | /* |
200 | * When performing allocations for a given metaslab, we want to make sure that | |
201 | * there are enough IOs to aggregate together to improve throughput. We want to | |
202 | * ensure that there are at least 128k worth of IOs that can be aggregated, and | |
203 | * we assume that the average allocation size is 4k, so we need the queue depth | |
204 | * to be 32 per allocator to get good aggregation of sequential writes. | |
205 | */ | |
206 | int zfs_vdev_def_queue_depth = 32; | |
207 | ||
1b939560 BB |
208 | /* |
209 | * Allow TRIM I/Os to be aggregated. This should normally not be needed since | |
210 | * TRIM I/O for extents up to zfs_trim_extent_bytes_max (128M) can be submitted | |
211 | * by the TRIM code in zfs_trim.c. | |
212 | */ | |
213 | int zfs_vdev_aggregate_trim = 0; | |
3dfb57a3 | 214 | |
34dc7c2f | 215 | int |
e8b96c60 | 216 | vdev_queue_offset_compare(const void *x1, const void *x2) |
34dc7c2f | 217 | { |
ee36c709 GN |
218 | const zio_t *z1 = (const zio_t *)x1; |
219 | const zio_t *z2 = (const zio_t *)x2; | |
34dc7c2f | 220 | |
ee36c709 | 221 | int cmp = AVL_CMP(z1->io_offset, z2->io_offset); |
34dc7c2f | 222 | |
ee36c709 GN |
223 | if (likely(cmp)) |
224 | return (cmp); | |
34dc7c2f | 225 | |
ee36c709 | 226 | return (AVL_PCMP(z1, z2)); |
34dc7c2f BB |
227 | } |
228 | ||
ec8501ee JG |
229 | static inline avl_tree_t * |
230 | vdev_queue_class_tree(vdev_queue_t *vq, zio_priority_t p) | |
231 | { | |
232 | return (&vq->vq_class[p].vqc_queued_tree); | |
233 | } | |
234 | ||
235 | static inline avl_tree_t * | |
236 | vdev_queue_type_tree(vdev_queue_t *vq, zio_type_t t) | |
237 | { | |
1b939560 | 238 | ASSERT(t == ZIO_TYPE_READ || t == ZIO_TYPE_WRITE || t == ZIO_TYPE_TRIM); |
ec8501ee JG |
239 | if (t == ZIO_TYPE_READ) |
240 | return (&vq->vq_read_offset_tree); | |
1b939560 | 241 | else if (t == ZIO_TYPE_WRITE) |
ec8501ee | 242 | return (&vq->vq_write_offset_tree); |
1b939560 BB |
243 | else |
244 | return (&vq->vq_trim_offset_tree); | |
ec8501ee JG |
245 | } |
246 | ||
34dc7c2f | 247 | int |
e8b96c60 | 248 | vdev_queue_timestamp_compare(const void *x1, const void *x2) |
34dc7c2f | 249 | { |
ee36c709 GN |
250 | const zio_t *z1 = (const zio_t *)x1; |
251 | const zio_t *z2 = (const zio_t *)x2; | |
34dc7c2f | 252 | |
ee36c709 | 253 | int cmp = AVL_CMP(z1->io_timestamp, z2->io_timestamp); |
34dc7c2f | 254 | |
ee36c709 GN |
255 | if (likely(cmp)) |
256 | return (cmp); | |
34dc7c2f | 257 | |
ee36c709 | 258 | return (AVL_PCMP(z1, z2)); |
34dc7c2f BB |
259 | } |
260 | ||
e8b96c60 MA |
261 | static int |
262 | vdev_queue_class_min_active(zio_priority_t p) | |
263 | { | |
264 | switch (p) { | |
265 | case ZIO_PRIORITY_SYNC_READ: | |
266 | return (zfs_vdev_sync_read_min_active); | |
267 | case ZIO_PRIORITY_SYNC_WRITE: | |
268 | return (zfs_vdev_sync_write_min_active); | |
269 | case ZIO_PRIORITY_ASYNC_READ: | |
270 | return (zfs_vdev_async_read_min_active); | |
271 | case ZIO_PRIORITY_ASYNC_WRITE: | |
272 | return (zfs_vdev_async_write_min_active); | |
273 | case ZIO_PRIORITY_SCRUB: | |
274 | return (zfs_vdev_scrub_min_active); | |
a1d477c2 MA |
275 | case ZIO_PRIORITY_REMOVAL: |
276 | return (zfs_vdev_removal_min_active); | |
619f0976 GW |
277 | case ZIO_PRIORITY_INITIALIZING: |
278 | return (zfs_vdev_initializing_min_active); | |
1b939560 BB |
279 | case ZIO_PRIORITY_TRIM: |
280 | return (zfs_vdev_trim_min_active); | |
e8b96c60 MA |
281 | default: |
282 | panic("invalid priority %u", p); | |
283 | return (0); | |
284 | } | |
285 | } | |
286 | ||
287 | static int | |
acbad6ff | 288 | vdev_queue_max_async_writes(spa_t *spa) |
e8b96c60 MA |
289 | { |
290 | int writes; | |
b7faa7aa G |
291 | uint64_t dirty = 0; |
292 | dsl_pool_t *dp = spa_get_dsl(spa); | |
e8b96c60 MA |
293 | uint64_t min_bytes = zfs_dirty_data_max * |
294 | zfs_vdev_async_write_active_min_dirty_percent / 100; | |
295 | uint64_t max_bytes = zfs_dirty_data_max * | |
296 | zfs_vdev_async_write_active_max_dirty_percent / 100; | |
297 | ||
b7faa7aa G |
298 | /* |
299 | * Async writes may occur before the assignment of the spa's | |
300 | * dsl_pool_t if a self-healing zio is issued prior to the | |
301 | * completion of dmu_objset_open_impl(). | |
302 | */ | |
303 | if (dp == NULL) | |
304 | return (zfs_vdev_async_write_max_active); | |
305 | ||
acbad6ff AR |
306 | /* |
307 | * Sync tasks correspond to interactive user actions. To reduce the | |
308 | * execution time of those actions we push data out as fast as possible. | |
309 | */ | |
b7faa7aa | 310 | if (spa_has_pending_synctask(spa)) |
acbad6ff | 311 | return (zfs_vdev_async_write_max_active); |
acbad6ff | 312 | |
b7faa7aa | 313 | dirty = dp->dp_dirty_total; |
e8b96c60 MA |
314 | if (dirty < min_bytes) |
315 | return (zfs_vdev_async_write_min_active); | |
316 | if (dirty > max_bytes) | |
317 | return (zfs_vdev_async_write_max_active); | |
318 | ||
319 | /* | |
320 | * linear interpolation: | |
321 | * slope = (max_writes - min_writes) / (max_bytes - min_bytes) | |
322 | * move right by min_bytes | |
323 | * move up by min_writes | |
324 | */ | |
325 | writes = (dirty - min_bytes) * | |
326 | (zfs_vdev_async_write_max_active - | |
327 | zfs_vdev_async_write_min_active) / | |
328 | (max_bytes - min_bytes) + | |
329 | zfs_vdev_async_write_min_active; | |
330 | ASSERT3U(writes, >=, zfs_vdev_async_write_min_active); | |
331 | ASSERT3U(writes, <=, zfs_vdev_async_write_max_active); | |
332 | return (writes); | |
333 | } | |
334 | ||
335 | static int | |
336 | vdev_queue_class_max_active(spa_t *spa, zio_priority_t p) | |
337 | { | |
338 | switch (p) { | |
339 | case ZIO_PRIORITY_SYNC_READ: | |
340 | return (zfs_vdev_sync_read_max_active); | |
341 | case ZIO_PRIORITY_SYNC_WRITE: | |
342 | return (zfs_vdev_sync_write_max_active); | |
343 | case ZIO_PRIORITY_ASYNC_READ: | |
344 | return (zfs_vdev_async_read_max_active); | |
345 | case ZIO_PRIORITY_ASYNC_WRITE: | |
acbad6ff | 346 | return (vdev_queue_max_async_writes(spa)); |
e8b96c60 MA |
347 | case ZIO_PRIORITY_SCRUB: |
348 | return (zfs_vdev_scrub_max_active); | |
a1d477c2 MA |
349 | case ZIO_PRIORITY_REMOVAL: |
350 | return (zfs_vdev_removal_max_active); | |
619f0976 GW |
351 | case ZIO_PRIORITY_INITIALIZING: |
352 | return (zfs_vdev_initializing_max_active); | |
1b939560 BB |
353 | case ZIO_PRIORITY_TRIM: |
354 | return (zfs_vdev_trim_max_active); | |
e8b96c60 MA |
355 | default: |
356 | panic("invalid priority %u", p); | |
357 | return (0); | |
358 | } | |
359 | } | |
360 | ||
361 | /* | |
362 | * Return the i/o class to issue from, or ZIO_PRIORITY_MAX_QUEUEABLE if | |
363 | * there is no eligible class. | |
364 | */ | |
365 | static zio_priority_t | |
366 | vdev_queue_class_to_issue(vdev_queue_t *vq) | |
367 | { | |
368 | spa_t *spa = vq->vq_vdev->vdev_spa; | |
369 | zio_priority_t p; | |
370 | ||
371 | if (avl_numnodes(&vq->vq_active_tree) >= zfs_vdev_max_active) | |
372 | return (ZIO_PRIORITY_NUM_QUEUEABLE); | |
373 | ||
374 | /* find a queue that has not reached its minimum # outstanding i/os */ | |
375 | for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) { | |
ec8501ee | 376 | if (avl_numnodes(vdev_queue_class_tree(vq, p)) > 0 && |
e8b96c60 MA |
377 | vq->vq_class[p].vqc_active < |
378 | vdev_queue_class_min_active(p)) | |
379 | return (p); | |
380 | } | |
381 | ||
382 | /* | |
383 | * If we haven't found a queue, look for one that hasn't reached its | |
384 | * maximum # outstanding i/os. | |
385 | */ | |
386 | for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) { | |
ec8501ee | 387 | if (avl_numnodes(vdev_queue_class_tree(vq, p)) > 0 && |
e8b96c60 MA |
388 | vq->vq_class[p].vqc_active < |
389 | vdev_queue_class_max_active(spa, p)) | |
390 | return (p); | |
391 | } | |
392 | ||
393 | /* No eligible queued i/os */ | |
394 | return (ZIO_PRIORITY_NUM_QUEUEABLE); | |
395 | } | |
396 | ||
34dc7c2f BB |
397 | void |
398 | vdev_queue_init(vdev_t *vd) | |
399 | { | |
400 | vdev_queue_t *vq = &vd->vdev_queue; | |
e8b96c60 | 401 | zio_priority_t p; |
34dc7c2f BB |
402 | |
403 | mutex_init(&vq->vq_lock, NULL, MUTEX_DEFAULT, NULL); | |
e8b96c60 | 404 | vq->vq_vdev = vd; |
36b454ab | 405 | taskq_init_ent(&vd->vdev_queue.vq_io_search.io_tqent); |
34dc7c2f | 406 | |
e8b96c60 MA |
407 | avl_create(&vq->vq_active_tree, vdev_queue_offset_compare, |
408 | sizeof (zio_t), offsetof(struct zio, io_queue_node)); | |
ec8501ee | 409 | avl_create(vdev_queue_type_tree(vq, ZIO_TYPE_READ), |
02730c33 BB |
410 | vdev_queue_offset_compare, sizeof (zio_t), |
411 | offsetof(struct zio, io_offset_node)); | |
ec8501ee | 412 | avl_create(vdev_queue_type_tree(vq, ZIO_TYPE_WRITE), |
02730c33 BB |
413 | vdev_queue_offset_compare, sizeof (zio_t), |
414 | offsetof(struct zio, io_offset_node)); | |
1b939560 BB |
415 | avl_create(vdev_queue_type_tree(vq, ZIO_TYPE_TRIM), |
416 | vdev_queue_offset_compare, sizeof (zio_t), | |
417 | offsetof(struct zio, io_offset_node)); | |
34dc7c2f | 418 | |
e8b96c60 | 419 | for (p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) { |
ec8501ee JG |
420 | int (*compfn) (const void *, const void *); |
421 | ||
e8b96c60 | 422 | /* |
1b939560 | 423 | * The synchronous/trim i/o queues are dispatched in FIFO rather |
ec8501ee JG |
424 | * than LBA order. This provides more consistent latency for |
425 | * these i/os. | |
e8b96c60 | 426 | */ |
1b939560 BB |
427 | if (p == ZIO_PRIORITY_SYNC_READ || |
428 | p == ZIO_PRIORITY_SYNC_WRITE || | |
429 | p == ZIO_PRIORITY_TRIM) { | |
ec8501ee | 430 | compfn = vdev_queue_timestamp_compare; |
1b939560 | 431 | } else { |
ec8501ee | 432 | compfn = vdev_queue_offset_compare; |
1b939560 | 433 | } |
ec8501ee | 434 | avl_create(vdev_queue_class_tree(vq, p), compfn, |
02730c33 | 435 | sizeof (zio_t), offsetof(struct zio, io_queue_node)); |
e8b96c60 | 436 | } |
9f500936 | 437 | |
d6c6590c | 438 | vq->vq_last_offset = 0; |
34dc7c2f BB |
439 | } |
440 | ||
441 | void | |
442 | vdev_queue_fini(vdev_t *vd) | |
443 | { | |
444 | vdev_queue_t *vq = &vd->vdev_queue; | |
445 | ||
1c27024e | 446 | for (zio_priority_t p = 0; p < ZIO_PRIORITY_NUM_QUEUEABLE; p++) |
ec8501ee | 447 | avl_destroy(vdev_queue_class_tree(vq, p)); |
e8b96c60 | 448 | avl_destroy(&vq->vq_active_tree); |
ec8501ee JG |
449 | avl_destroy(vdev_queue_type_tree(vq, ZIO_TYPE_READ)); |
450 | avl_destroy(vdev_queue_type_tree(vq, ZIO_TYPE_WRITE)); | |
1b939560 | 451 | avl_destroy(vdev_queue_type_tree(vq, ZIO_TYPE_TRIM)); |
34dc7c2f BB |
452 | |
453 | mutex_destroy(&vq->vq_lock); | |
454 | } | |
455 | ||
456 | static void | |
457 | vdev_queue_io_add(vdev_queue_t *vq, zio_t *zio) | |
458 | { | |
330847ff | 459 | spa_t *spa = zio->io_spa; |
d1261452 | 460 | spa_history_kstat_t *shk = &spa->spa_stats.io_history; |
330847ff | 461 | |
e8b96c60 | 462 | ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE); |
ec8501ee JG |
463 | avl_add(vdev_queue_class_tree(vq, zio->io_priority), zio); |
464 | avl_add(vdev_queue_type_tree(vq, zio->io_type), zio); | |
330847ff | 465 | |
d1261452 JG |
466 | if (shk->kstat != NULL) { |
467 | mutex_enter(&shk->lock); | |
468 | kstat_waitq_enter(shk->kstat->ks_data); | |
469 | mutex_exit(&shk->lock); | |
330847ff | 470 | } |
34dc7c2f BB |
471 | } |
472 | ||
473 | static void | |
474 | vdev_queue_io_remove(vdev_queue_t *vq, zio_t *zio) | |
475 | { | |
330847ff | 476 | spa_t *spa = zio->io_spa; |
d1261452 | 477 | spa_history_kstat_t *shk = &spa->spa_stats.io_history; |
330847ff | 478 | |
e8b96c60 | 479 | ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE); |
ec8501ee JG |
480 | avl_remove(vdev_queue_class_tree(vq, zio->io_priority), zio); |
481 | avl_remove(vdev_queue_type_tree(vq, zio->io_type), zio); | |
330847ff | 482 | |
d1261452 JG |
483 | if (shk->kstat != NULL) { |
484 | mutex_enter(&shk->lock); | |
485 | kstat_waitq_exit(shk->kstat->ks_data); | |
486 | mutex_exit(&shk->lock); | |
330847ff MA |
487 | } |
488 | } | |
489 | ||
490 | static void | |
491 | vdev_queue_pending_add(vdev_queue_t *vq, zio_t *zio) | |
492 | { | |
493 | spa_t *spa = zio->io_spa; | |
d1261452 | 494 | spa_history_kstat_t *shk = &spa->spa_stats.io_history; |
330847ff | 495 | |
e8b96c60 MA |
496 | ASSERT(MUTEX_HELD(&vq->vq_lock)); |
497 | ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE); | |
498 | vq->vq_class[zio->io_priority].vqc_active++; | |
499 | avl_add(&vq->vq_active_tree, zio); | |
330847ff | 500 | |
d1261452 JG |
501 | if (shk->kstat != NULL) { |
502 | mutex_enter(&shk->lock); | |
503 | kstat_runq_enter(shk->kstat->ks_data); | |
504 | mutex_exit(&shk->lock); | |
330847ff MA |
505 | } |
506 | } | |
507 | ||
508 | static void | |
509 | vdev_queue_pending_remove(vdev_queue_t *vq, zio_t *zio) | |
510 | { | |
511 | spa_t *spa = zio->io_spa; | |
d1261452 | 512 | spa_history_kstat_t *shk = &spa->spa_stats.io_history; |
330847ff | 513 | |
e8b96c60 MA |
514 | ASSERT(MUTEX_HELD(&vq->vq_lock)); |
515 | ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE); | |
516 | vq->vq_class[zio->io_priority].vqc_active--; | |
517 | avl_remove(&vq->vq_active_tree, zio); | |
330847ff | 518 | |
d1261452 JG |
519 | if (shk->kstat != NULL) { |
520 | kstat_io_t *ksio = shk->kstat->ks_data; | |
330847ff | 521 | |
d1261452 | 522 | mutex_enter(&shk->lock); |
330847ff MA |
523 | kstat_runq_exit(ksio); |
524 | if (zio->io_type == ZIO_TYPE_READ) { | |
525 | ksio->reads++; | |
526 | ksio->nread += zio->io_size; | |
527 | } else if (zio->io_type == ZIO_TYPE_WRITE) { | |
528 | ksio->writes++; | |
529 | ksio->nwritten += zio->io_size; | |
530 | } | |
d1261452 | 531 | mutex_exit(&shk->lock); |
330847ff | 532 | } |
34dc7c2f BB |
533 | } |
534 | ||
535 | static void | |
536 | vdev_queue_agg_io_done(zio_t *aio) | |
537 | { | |
e8b96c60 MA |
538 | if (aio->io_type == ZIO_TYPE_READ) { |
539 | zio_t *pio; | |
3dfb57a3 DB |
540 | zio_link_t *zl = NULL; |
541 | while ((pio = zio_walk_parents(aio, &zl)) != NULL) { | |
a6255b7f DQ |
542 | abd_copy_off(pio->io_abd, aio->io_abd, |
543 | 0, pio->io_offset - aio->io_offset, pio->io_size); | |
e8b96c60 MA |
544 | } |
545 | } | |
34dc7c2f | 546 | |
a6255b7f | 547 | abd_free(aio->io_abd); |
34dc7c2f BB |
548 | } |
549 | ||
9babb374 BB |
550 | /* |
551 | * Compute the range spanned by two i/os, which is the endpoint of the last | |
552 | * (lio->io_offset + lio->io_size) minus start of the first (fio->io_offset). | |
553 | * Conveniently, the gap between fio and lio is given by -IO_SPAN(lio, fio); | |
554 | * thus fio and lio are adjacent if and only if IO_SPAN(lio, fio) == 0. | |
555 | */ | |
556 | #define IO_SPAN(fio, lio) ((lio)->io_offset + (lio)->io_size - (fio)->io_offset) | |
557 | #define IO_GAP(fio, lio) (-IO_SPAN(lio, fio)) | |
34dc7c2f BB |
558 | |
559 | static zio_t * | |
e8b96c60 | 560 | vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio) |
34dc7c2f | 561 | { |
e8b96c60 | 562 | zio_t *first, *last, *aio, *dio, *mandatory, *nio; |
a76f3d04 | 563 | zio_link_t *zl = NULL; |
e8b96c60 MA |
564 | uint64_t maxgap = 0; |
565 | uint64_t size; | |
a58df6f5 | 566 | uint64_t limit; |
2d678f77 | 567 | int maxblocksize; |
e8b96c60 | 568 | boolean_t stretch = B_FALSE; |
ec8501ee | 569 | avl_tree_t *t = vdev_queue_type_tree(vq, zio->io_type); |
e8b96c60 | 570 | enum zio_flag flags = zio->io_flags & ZIO_FLAG_AGG_INHERIT; |
a6255b7f | 571 | abd_t *abd; |
e8b96c60 | 572 | |
2d678f77 | 573 | maxblocksize = spa_maxblocksize(vq->vq_vdev->vdev_spa); |
1af240f3 AM |
574 | if (vq->vq_vdev->vdev_nonrot) |
575 | limit = zfs_vdev_aggregation_limit_non_rotating; | |
576 | else | |
577 | limit = zfs_vdev_aggregation_limit; | |
578 | limit = MAX(MIN(limit, maxblocksize), 0); | |
34dc7c2f | 579 | |
a58df6f5 BB |
580 | if (zio->io_flags & ZIO_FLAG_DONT_AGGREGATE || limit == 0) |
581 | return (NULL); | |
34dc7c2f | 582 | |
1b939560 BB |
583 | /* |
584 | * While TRIM commands could be aggregated based on offset this | |
585 | * behavior is disabled until it's determined to be beneficial. | |
586 | */ | |
587 | if (zio->io_type == ZIO_TYPE_TRIM && !zfs_vdev_aggregate_trim) | |
588 | return (NULL); | |
589 | ||
e8b96c60 | 590 | first = last = zio; |
34dc7c2f | 591 | |
e8b96c60 MA |
592 | if (zio->io_type == ZIO_TYPE_READ) |
593 | maxgap = zfs_vdev_read_gap_limit; | |
fb5f0bc8 | 594 | |
e8b96c60 MA |
595 | /* |
596 | * We can aggregate I/Os that are sufficiently adjacent and of | |
597 | * the same flavor, as expressed by the AGG_INHERIT flags. | |
598 | * The latter requirement is necessary so that certain | |
599 | * attributes of the I/O, such as whether it's a normal I/O | |
600 | * or a scrub/resilver, can be preserved in the aggregate. | |
601 | * We can include optional I/Os, but don't allow them | |
602 | * to begin a range as they add no benefit in that situation. | |
603 | */ | |
45d1cae3 | 604 | |
e8b96c60 MA |
605 | /* |
606 | * We keep track of the last non-optional I/O. | |
607 | */ | |
608 | mandatory = (first->io_flags & ZIO_FLAG_OPTIONAL) ? NULL : first; | |
45d1cae3 | 609 | |
e8b96c60 MA |
610 | /* |
611 | * Walk backwards through sufficiently contiguous I/Os | |
8542ef85 | 612 | * recording the last non-optional I/O. |
e8b96c60 MA |
613 | */ |
614 | while ((dio = AVL_PREV(t, first)) != NULL && | |
615 | (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags && | |
a58df6f5 | 616 | IO_SPAN(dio, last) <= limit && |
a1d477c2 MA |
617 | IO_GAP(dio, first) <= maxgap && |
618 | dio->io_type == zio->io_type) { | |
e8b96c60 MA |
619 | first = dio; |
620 | if (mandatory == NULL && !(first->io_flags & ZIO_FLAG_OPTIONAL)) | |
621 | mandatory = first; | |
622 | } | |
45d1cae3 | 623 | |
e8b96c60 MA |
624 | /* |
625 | * Skip any initial optional I/Os. | |
626 | */ | |
627 | while ((first->io_flags & ZIO_FLAG_OPTIONAL) && first != last) { | |
628 | first = AVL_NEXT(t, first); | |
629 | ASSERT(first != NULL); | |
630 | } | |
9babb374 | 631 | |
45d1cae3 | 632 | |
e8b96c60 MA |
633 | /* |
634 | * Walk forward through sufficiently contiguous I/Os. | |
8542ef85 MA |
635 | * The aggregation limit does not apply to optional i/os, so that |
636 | * we can issue contiguous writes even if they are larger than the | |
637 | * aggregation limit. | |
e8b96c60 MA |
638 | */ |
639 | while ((dio = AVL_NEXT(t, last)) != NULL && | |
640 | (dio->io_flags & ZIO_FLAG_AGG_INHERIT) == flags && | |
8542ef85 MA |
641 | (IO_SPAN(first, dio) <= limit || |
642 | (dio->io_flags & ZIO_FLAG_OPTIONAL)) && | |
2d678f77 | 643 | IO_SPAN(first, dio) <= maxblocksize && |
a1d477c2 MA |
644 | IO_GAP(last, dio) <= maxgap && |
645 | dio->io_type == zio->io_type) { | |
e8b96c60 MA |
646 | last = dio; |
647 | if (!(last->io_flags & ZIO_FLAG_OPTIONAL)) | |
648 | mandatory = last; | |
649 | } | |
650 | ||
651 | /* | |
652 | * Now that we've established the range of the I/O aggregation | |
653 | * we must decide what to do with trailing optional I/Os. | |
654 | * For reads, there's nothing to do. While we are unable to | |
655 | * aggregate further, it's possible that a trailing optional | |
656 | * I/O would allow the underlying device to aggregate with | |
657 | * subsequent I/Os. We must therefore determine if the next | |
658 | * non-optional I/O is close enough to make aggregation | |
659 | * worthwhile. | |
660 | */ | |
661 | if (zio->io_type == ZIO_TYPE_WRITE && mandatory != NULL) { | |
662 | zio_t *nio = last; | |
663 | while ((dio = AVL_NEXT(t, nio)) != NULL && | |
664 | IO_GAP(nio, dio) == 0 && | |
665 | IO_GAP(mandatory, dio) <= zfs_vdev_write_gap_limit) { | |
666 | nio = dio; | |
667 | if (!(nio->io_flags & ZIO_FLAG_OPTIONAL)) { | |
668 | stretch = B_TRUE; | |
669 | break; | |
45d1cae3 BB |
670 | } |
671 | } | |
e8b96c60 | 672 | } |
45d1cae3 | 673 | |
e8b96c60 | 674 | if (stretch) { |
8542ef85 MA |
675 | /* |
676 | * We are going to include an optional io in our aggregated | |
677 | * span, thus closing the write gap. Only mandatory i/os can | |
678 | * start aggregated spans, so make sure that the next i/o | |
679 | * after our span is mandatory. | |
680 | */ | |
e8b96c60 MA |
681 | dio = AVL_NEXT(t, last); |
682 | dio->io_flags &= ~ZIO_FLAG_OPTIONAL; | |
683 | } else { | |
8542ef85 | 684 | /* do not include the optional i/o */ |
e8b96c60 MA |
685 | while (last != mandatory && last != first) { |
686 | ASSERT(last->io_flags & ZIO_FLAG_OPTIONAL); | |
687 | last = AVL_PREV(t, last); | |
688 | ASSERT(last != NULL); | |
45d1cae3 | 689 | } |
34dc7c2f BB |
690 | } |
691 | ||
e8b96c60 MA |
692 | if (first == last) |
693 | return (NULL); | |
694 | ||
e8b96c60 | 695 | size = IO_SPAN(first, last); |
2d678f77 | 696 | ASSERT3U(size, <=, maxblocksize); |
e8b96c60 | 697 | |
a6255b7f DQ |
698 | abd = abd_alloc_for_io(size, B_TRUE); |
699 | if (abd == NULL) | |
6fe53787 BB |
700 | return (NULL); |
701 | ||
e8b96c60 | 702 | aio = zio_vdev_delegated_io(first->io_vd, first->io_offset, |
a6255b7f | 703 | abd, size, first->io_type, zio->io_priority, |
e8b96c60 MA |
704 | flags | ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE, |
705 | vdev_queue_agg_io_done, NULL); | |
706 | aio->io_timestamp = first->io_timestamp; | |
707 | ||
708 | nio = first; | |
709 | do { | |
710 | dio = nio; | |
711 | nio = AVL_NEXT(t, dio); | |
712 | ASSERT3U(dio->io_type, ==, aio->io_type); | |
713 | ||
714 | if (dio->io_flags & ZIO_FLAG_NODATA) { | |
715 | ASSERT3U(dio->io_type, ==, ZIO_TYPE_WRITE); | |
a6255b7f DQ |
716 | abd_zero_off(aio->io_abd, |
717 | dio->io_offset - aio->io_offset, dio->io_size); | |
e8b96c60 | 718 | } else if (dio->io_type == ZIO_TYPE_WRITE) { |
a6255b7f DQ |
719 | abd_copy_off(aio->io_abd, dio->io_abd, |
720 | dio->io_offset - aio->io_offset, 0, dio->io_size); | |
e8b96c60 | 721 | } |
d164b209 | 722 | |
e8b96c60 MA |
723 | zio_add_child(dio, aio); |
724 | vdev_queue_io_remove(vq, dio); | |
a76f3d04 BB |
725 | } while (dio != last); |
726 | ||
727 | /* | |
728 | * We need to drop the vdev queue's lock to avoid a deadlock that we | |
729 | * could encounter since this I/O will complete immediately. | |
730 | */ | |
731 | mutex_exit(&vq->vq_lock); | |
732 | while ((dio = zio_walk_parents(aio, &zl)) != NULL) { | |
e8b96c60 MA |
733 | zio_vdev_io_bypass(dio); |
734 | zio_execute(dio); | |
a76f3d04 BB |
735 | } |
736 | mutex_enter(&vq->vq_lock); | |
34dc7c2f | 737 | |
e8b96c60 MA |
738 | return (aio); |
739 | } | |
740 | ||
741 | static zio_t * | |
742 | vdev_queue_io_to_issue(vdev_queue_t *vq) | |
743 | { | |
744 | zio_t *zio, *aio; | |
745 | zio_priority_t p; | |
746 | avl_index_t idx; | |
ec8501ee | 747 | avl_tree_t *tree; |
e8b96c60 MA |
748 | |
749 | again: | |
750 | ASSERT(MUTEX_HELD(&vq->vq_lock)); | |
751 | ||
752 | p = vdev_queue_class_to_issue(vq); | |
34dc7c2f | 753 | |
e8b96c60 MA |
754 | if (p == ZIO_PRIORITY_NUM_QUEUEABLE) { |
755 | /* No eligible queued i/os */ | |
756 | return (NULL); | |
34dc7c2f BB |
757 | } |
758 | ||
e8b96c60 | 759 | /* |
619f0976 GW |
760 | * For LBA-ordered queues (async / scrub / initializing), issue the |
761 | * i/o which follows the most recently issued i/o in LBA (offset) order. | |
e8b96c60 | 762 | * |
1b939560 | 763 | * For FIFO queues (sync/trim), issue the i/o with the lowest timestamp. |
e8b96c60 | 764 | */ |
ec8501ee | 765 | tree = vdev_queue_class_tree(vq, p); |
50b25b21 | 766 | vq->vq_io_search.io_timestamp = 0; |
d6c6590c GN |
767 | vq->vq_io_search.io_offset = vq->vq_last_offset - 1; |
768 | VERIFY3P(avl_find(tree, &vq->vq_io_search, &idx), ==, NULL); | |
ec8501ee | 769 | zio = avl_nearest(tree, idx, AVL_AFTER); |
e8b96c60 | 770 | if (zio == NULL) |
ec8501ee | 771 | zio = avl_first(tree); |
e8b96c60 MA |
772 | ASSERT3U(zio->io_priority, ==, p); |
773 | ||
774 | aio = vdev_queue_aggregate(vq, zio); | |
775 | if (aio != NULL) | |
776 | zio = aio; | |
777 | else | |
778 | vdev_queue_io_remove(vq, zio); | |
34dc7c2f | 779 | |
45d1cae3 BB |
780 | /* |
781 | * If the I/O is or was optional and therefore has no data, we need to | |
782 | * simply discard it. We need to drop the vdev queue's lock to avoid a | |
783 | * deadlock that we could encounter since this I/O will complete | |
784 | * immediately. | |
785 | */ | |
e8b96c60 | 786 | if (zio->io_flags & ZIO_FLAG_NODATA) { |
45d1cae3 | 787 | mutex_exit(&vq->vq_lock); |
e8b96c60 MA |
788 | zio_vdev_io_bypass(zio); |
789 | zio_execute(zio); | |
45d1cae3 BB |
790 | mutex_enter(&vq->vq_lock); |
791 | goto again; | |
792 | } | |
793 | ||
e8b96c60 | 794 | vdev_queue_pending_add(vq, zio); |
d6c6590c | 795 | vq->vq_last_offset = zio->io_offset + zio->io_size; |
34dc7c2f | 796 | |
e8b96c60 | 797 | return (zio); |
34dc7c2f BB |
798 | } |
799 | ||
800 | zio_t * | |
801 | vdev_queue_io(zio_t *zio) | |
802 | { | |
803 | vdev_queue_t *vq = &zio->io_vd->vdev_queue; | |
804 | zio_t *nio; | |
805 | ||
34dc7c2f BB |
806 | if (zio->io_flags & ZIO_FLAG_DONT_QUEUE) |
807 | return (zio); | |
808 | ||
e8b96c60 MA |
809 | /* |
810 | * Children i/os inherent their parent's priority, which might | |
811 | * not match the child's i/o type. Fix it up here. | |
812 | */ | |
813 | if (zio->io_type == ZIO_TYPE_READ) { | |
1b939560 BB |
814 | ASSERT(zio->io_priority != ZIO_PRIORITY_TRIM); |
815 | ||
e8b96c60 MA |
816 | if (zio->io_priority != ZIO_PRIORITY_SYNC_READ && |
817 | zio->io_priority != ZIO_PRIORITY_ASYNC_READ && | |
a1d477c2 | 818 | zio->io_priority != ZIO_PRIORITY_SCRUB && |
619f0976 | 819 | zio->io_priority != ZIO_PRIORITY_REMOVAL && |
1b939560 | 820 | zio->io_priority != ZIO_PRIORITY_INITIALIZING) { |
e8b96c60 | 821 | zio->io_priority = ZIO_PRIORITY_ASYNC_READ; |
1b939560 BB |
822 | } |
823 | } else if (zio->io_type == ZIO_TYPE_WRITE) { | |
824 | ASSERT(zio->io_priority != ZIO_PRIORITY_TRIM); | |
825 | ||
e8b96c60 | 826 | if (zio->io_priority != ZIO_PRIORITY_SYNC_WRITE && |
a1d477c2 | 827 | zio->io_priority != ZIO_PRIORITY_ASYNC_WRITE && |
619f0976 | 828 | zio->io_priority != ZIO_PRIORITY_REMOVAL && |
1b939560 | 829 | zio->io_priority != ZIO_PRIORITY_INITIALIZING) { |
e8b96c60 | 830 | zio->io_priority = ZIO_PRIORITY_ASYNC_WRITE; |
1b939560 BB |
831 | } |
832 | } else { | |
833 | ASSERT(zio->io_type == ZIO_TYPE_TRIM); | |
834 | ASSERT(zio->io_priority == ZIO_PRIORITY_TRIM); | |
e8b96c60 | 835 | } |
34dc7c2f | 836 | |
e8b96c60 | 837 | zio->io_flags |= ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE; |
34dc7c2f BB |
838 | |
839 | mutex_enter(&vq->vq_lock); | |
cb682a17 | 840 | zio->io_timestamp = gethrtime(); |
34dc7c2f | 841 | vdev_queue_io_add(vq, zio); |
e8b96c60 | 842 | nio = vdev_queue_io_to_issue(vq); |
34dc7c2f BB |
843 | mutex_exit(&vq->vq_lock); |
844 | ||
845 | if (nio == NULL) | |
846 | return (NULL); | |
847 | ||
848 | if (nio->io_done == vdev_queue_agg_io_done) { | |
849 | zio_nowait(nio); | |
850 | return (NULL); | |
851 | } | |
852 | ||
853 | return (nio); | |
854 | } | |
855 | ||
856 | void | |
857 | vdev_queue_io_done(zio_t *zio) | |
858 | { | |
859 | vdev_queue_t *vq = &zio->io_vd->vdev_queue; | |
e8b96c60 | 860 | zio_t *nio; |
34dc7c2f BB |
861 | |
862 | mutex_enter(&vq->vq_lock); | |
863 | ||
330847ff | 864 | vdev_queue_pending_remove(vq, zio); |
34dc7c2f | 865 | |
cb682a17 MA |
866 | zio->io_delta = gethrtime() - zio->io_timestamp; |
867 | vq->vq_io_complete_ts = gethrtime(); | |
cc92e9d0 GW |
868 | vq->vq_io_delta_ts = vq->vq_io_complete_ts - zio->io_timestamp; |
869 | ||
e8b96c60 | 870 | while ((nio = vdev_queue_io_to_issue(vq)) != NULL) { |
34dc7c2f BB |
871 | mutex_exit(&vq->vq_lock); |
872 | if (nio->io_done == vdev_queue_agg_io_done) { | |
873 | zio_nowait(nio); | |
874 | } else { | |
875 | zio_vdev_io_reissue(nio); | |
876 | zio_execute(nio); | |
877 | } | |
878 | mutex_enter(&vq->vq_lock); | |
879 | } | |
880 | ||
881 | mutex_exit(&vq->vq_lock); | |
882 | } | |
c28b2279 | 883 | |
a8b2e306 TC |
884 | void |
885 | vdev_queue_change_io_priority(zio_t *zio, zio_priority_t priority) | |
886 | { | |
887 | vdev_queue_t *vq = &zio->io_vd->vdev_queue; | |
888 | avl_tree_t *tree; | |
889 | ||
c26cf096 TH |
890 | /* |
891 | * ZIO_PRIORITY_NOW is used by the vdev cache code and the aggregate zio | |
892 | * code to issue IOs without adding them to the vdev queue. In this | |
893 | * case, the zio is already going to be issued as quickly as possible | |
894 | * and so it doesn't need any reprioitization to help. | |
895 | */ | |
896 | if (zio->io_priority == ZIO_PRIORITY_NOW) | |
897 | return; | |
898 | ||
a8b2e306 TC |
899 | ASSERT3U(zio->io_priority, <, ZIO_PRIORITY_NUM_QUEUEABLE); |
900 | ASSERT3U(priority, <, ZIO_PRIORITY_NUM_QUEUEABLE); | |
901 | ||
902 | if (zio->io_type == ZIO_TYPE_READ) { | |
903 | if (priority != ZIO_PRIORITY_SYNC_READ && | |
904 | priority != ZIO_PRIORITY_ASYNC_READ && | |
905 | priority != ZIO_PRIORITY_SCRUB) | |
906 | priority = ZIO_PRIORITY_ASYNC_READ; | |
907 | } else { | |
908 | ASSERT(zio->io_type == ZIO_TYPE_WRITE); | |
909 | if (priority != ZIO_PRIORITY_SYNC_WRITE && | |
910 | priority != ZIO_PRIORITY_ASYNC_WRITE) | |
911 | priority = ZIO_PRIORITY_ASYNC_WRITE; | |
912 | } | |
913 | ||
914 | mutex_enter(&vq->vq_lock); | |
915 | ||
916 | /* | |
917 | * If the zio is in none of the queues we can simply change | |
918 | * the priority. If the zio is waiting to be submitted we must | |
919 | * remove it from the queue and re-insert it with the new priority. | |
920 | * Otherwise, the zio is currently active and we cannot change its | |
921 | * priority. | |
922 | */ | |
923 | tree = vdev_queue_class_tree(vq, zio->io_priority); | |
924 | if (avl_find(tree, zio, NULL) == zio) { | |
925 | avl_remove(vdev_queue_class_tree(vq, zio->io_priority), zio); | |
926 | zio->io_priority = priority; | |
927 | avl_add(vdev_queue_class_tree(vq, zio->io_priority), zio); | |
928 | } else if (avl_find(&vq->vq_active_tree, zio, NULL) != zio) { | |
929 | zio->io_priority = priority; | |
930 | } | |
931 | ||
932 | mutex_exit(&vq->vq_lock); | |
933 | } | |
934 | ||
9f500936 | 935 | /* |
d6c6590c | 936 | * As these two methods are only used for load calculations we're not |
9f500936 | 937 | * concerned if we get an incorrect value on 32bit platforms due to lack of |
938 | * vq_lock mutex use here, instead we prefer to keep it lock free for | |
939 | * performance. | |
940 | */ | |
941 | int | |
942 | vdev_queue_length(vdev_t *vd) | |
943 | { | |
944 | return (avl_numnodes(&vd->vdev_queue.vq_active_tree)); | |
945 | } | |
946 | ||
947 | uint64_t | |
d6c6590c | 948 | vdev_queue_last_offset(vdev_t *vd) |
9f500936 | 949 | { |
d6c6590c | 950 | return (vd->vdev_queue.vq_last_offset); |
9f500936 | 951 | } |
952 | ||
93ce2b4c | 953 | #if defined(_KERNEL) |
c28b2279 | 954 | module_param(zfs_vdev_aggregation_limit, int, 0644); |
c409e464 BB |
955 | MODULE_PARM_DESC(zfs_vdev_aggregation_limit, "Max vdev I/O aggregation size"); |
956 | ||
1af240f3 AM |
957 | module_param(zfs_vdev_aggregation_limit_non_rotating, int, 0644); |
958 | MODULE_PARM_DESC(zfs_vdev_aggregation_limit_non_rotating, | |
959 | "Max vdev I/O aggregation size for non-rotating media"); | |
960 | ||
1b939560 BB |
961 | module_param(zfs_vdev_aggregate_trim, int, 0644); |
962 | MODULE_PARM_DESC(zfs_vdev_aggregate_trim, "Allow TRIM I/O to be aggregated"); | |
963 | ||
c409e464 BB |
964 | module_param(zfs_vdev_read_gap_limit, int, 0644); |
965 | MODULE_PARM_DESC(zfs_vdev_read_gap_limit, "Aggregate read I/O over gap"); | |
966 | ||
967 | module_param(zfs_vdev_write_gap_limit, int, 0644); | |
968 | MODULE_PARM_DESC(zfs_vdev_write_gap_limit, "Aggregate write I/O over gap"); | |
e8b96c60 MA |
969 | |
970 | module_param(zfs_vdev_max_active, int, 0644); | |
971 | MODULE_PARM_DESC(zfs_vdev_max_active, "Maximum number of active I/Os per vdev"); | |
972 | ||
973 | module_param(zfs_vdev_async_write_active_max_dirty_percent, int, 0644); | |
974 | MODULE_PARM_DESC(zfs_vdev_async_write_active_max_dirty_percent, | |
d1d7e268 | 975 | "Async write concurrency max threshold"); |
e8b96c60 MA |
976 | |
977 | module_param(zfs_vdev_async_write_active_min_dirty_percent, int, 0644); | |
978 | MODULE_PARM_DESC(zfs_vdev_async_write_active_min_dirty_percent, | |
d1d7e268 | 979 | "Async write concurrency min threshold"); |
e8b96c60 MA |
980 | |
981 | module_param(zfs_vdev_async_read_max_active, int, 0644); | |
982 | MODULE_PARM_DESC(zfs_vdev_async_read_max_active, | |
d1d7e268 | 983 | "Max active async read I/Os per vdev"); |
e8b96c60 MA |
984 | |
985 | module_param(zfs_vdev_async_read_min_active, int, 0644); | |
986 | MODULE_PARM_DESC(zfs_vdev_async_read_min_active, | |
d1d7e268 | 987 | "Min active async read I/Os per vdev"); |
e8b96c60 MA |
988 | |
989 | module_param(zfs_vdev_async_write_max_active, int, 0644); | |
990 | MODULE_PARM_DESC(zfs_vdev_async_write_max_active, | |
d1d7e268 | 991 | "Max active async write I/Os per vdev"); |
e8b96c60 MA |
992 | |
993 | module_param(zfs_vdev_async_write_min_active, int, 0644); | |
994 | MODULE_PARM_DESC(zfs_vdev_async_write_min_active, | |
d1d7e268 | 995 | "Min active async write I/Os per vdev"); |
e8b96c60 | 996 | |
619f0976 GW |
997 | module_param(zfs_vdev_initializing_max_active, int, 0644); |
998 | MODULE_PARM_DESC(zfs_vdev_initializing_max_active, | |
999 | "Max active initializing I/Os per vdev"); | |
1000 | ||
1001 | module_param(zfs_vdev_initializing_min_active, int, 0644); | |
1002 | MODULE_PARM_DESC(zfs_vdev_initializing_min_active, | |
1003 | "Min active initializing I/Os per vdev"); | |
1004 | ||
1005 | module_param(zfs_vdev_removal_max_active, int, 0644); | |
1006 | MODULE_PARM_DESC(zfs_vdev_removal_max_active, | |
1007 | "Max active removal I/Os per vdev"); | |
1008 | ||
1009 | module_param(zfs_vdev_removal_min_active, int, 0644); | |
1010 | MODULE_PARM_DESC(zfs_vdev_removal_min_active, | |
1011 | "Min active removal I/Os per vdev"); | |
1012 | ||
e8b96c60 | 1013 | module_param(zfs_vdev_scrub_max_active, int, 0644); |
619f0976 GW |
1014 | MODULE_PARM_DESC(zfs_vdev_scrub_max_active, |
1015 | "Max active scrub I/Os per vdev"); | |
e8b96c60 MA |
1016 | |
1017 | module_param(zfs_vdev_scrub_min_active, int, 0644); | |
619f0976 GW |
1018 | MODULE_PARM_DESC(zfs_vdev_scrub_min_active, |
1019 | "Min active scrub I/Os per vdev"); | |
e8b96c60 MA |
1020 | |
1021 | module_param(zfs_vdev_sync_read_max_active, int, 0644); | |
1022 | MODULE_PARM_DESC(zfs_vdev_sync_read_max_active, | |
d1d7e268 | 1023 | "Max active sync read I/Os per vdev"); |
e8b96c60 MA |
1024 | |
1025 | module_param(zfs_vdev_sync_read_min_active, int, 0644); | |
1026 | MODULE_PARM_DESC(zfs_vdev_sync_read_min_active, | |
d1d7e268 | 1027 | "Min active sync read I/Os per vdev"); |
e8b96c60 MA |
1028 | |
1029 | module_param(zfs_vdev_sync_write_max_active, int, 0644); | |
1030 | MODULE_PARM_DESC(zfs_vdev_sync_write_max_active, | |
d1d7e268 | 1031 | "Max active sync write I/Os per vdev"); |
e8b96c60 MA |
1032 | |
1033 | module_param(zfs_vdev_sync_write_min_active, int, 0644); | |
1034 | MODULE_PARM_DESC(zfs_vdev_sync_write_min_active, | |
3757bff3 | 1035 | "Min active sync write I/Os per vdev"); |
3dfb57a3 | 1036 | |
1b939560 BB |
1037 | module_param(zfs_vdev_trim_max_active, int, 0644); |
1038 | MODULE_PARM_DESC(zfs_vdev_trim_max_active, | |
1039 | "Max active trim/discard I/Os per vdev"); | |
1040 | ||
1041 | module_param(zfs_vdev_trim_min_active, int, 0644); | |
1042 | MODULE_PARM_DESC(zfs_vdev_trim_min_active, | |
1043 | "Min active trim/discard I/Os per vdev"); | |
1044 | ||
3dfb57a3 DB |
1045 | module_param(zfs_vdev_queue_depth_pct, int, 0644); |
1046 | MODULE_PARM_DESC(zfs_vdev_queue_depth_pct, | |
1047 | "Queue depth percentage for each top-level vdev"); | |
c28b2279 | 1048 | #endif |