Print this page
NEX-19083 backport OS-7314 zil_commit should omit cache thrash
9962 zil_commit should omit cache thrash
Reviewed by: Matt Ahrens <matt@delphix.com>
Reviewed by: Brad Lewis <brad.lewis@delphix.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Joshua M. Clulow <josh@sysmgr.org>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/zil_impl.h
+++ new/usr/src/uts/common/fs/zfs/sys/zil_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
24 24 * Copyright (c) 2014 Integros [integros.com]
25 25 */
26 26
27 27 /* Portions Copyright 2010 Robert Milkowski */
28 28
29 29 #ifndef _SYS_ZIL_IMPL_H
30 30 #define _SYS_ZIL_IMPL_H
31 31
32 32 #include <sys/zil.h>
33 33 #include <sys/dmu_objset.h>
34 34
35 35 #ifdef __cplusplus
36 36 extern "C" {
37 37 #endif
38 38
39 39 /*
40 40 * Possbile states for a given lwb structure.
|
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
41 41 *
42 42 * An lwb will start out in the "closed" state, and then transition to
43 43 * the "opened" state via a call to zil_lwb_write_open(). When
44 44 * transitioning from "closed" to "opened" the zilog's "zl_issuer_lock"
45 45 * must be held.
46 46 *
47 47 * After the lwb is "opened", it can transition into the "issued" state
48 48 * via zil_lwb_write_issue(). Again, the zilog's "zl_issuer_lock" must
49 49 * be held when making this transition.
50 50 *
51 - * After the lwb's zio completes, and the vdev's are flushed, the lwb
52 - * will transition into the "done" state via zil_lwb_write_done(). When
53 - * transitioning from "issued" to "done", the zilog's "zl_lock" must be
54 - * held, *not* the "zl_issuer_lock".
51 + * After the lwb's write zio completes, it transitions into the "write
52 + * done" state via zil_lwb_write_done(); and then into the "flush done"
53 + * state via zil_lwb_flush_vdevs_done(). When transitioning from
54 + * "issued" to "write done", and then from "write done" to "flush done",
55 + * the zilog's "zl_lock" must be held, *not* the "zl_issuer_lock".
55 56 *
56 57 * The zilog's "zl_issuer_lock" can become heavily contended in certain
57 58 * workloads, so we specifically avoid acquiring that lock when
58 59 * transitioning an lwb from "issued" to "done". This allows us to avoid
59 60 * having to acquire the "zl_issuer_lock" for each lwb ZIO completion,
60 61 * which would have added more lock contention on an already heavily
61 62 * contended lock.
62 63 *
63 64 * Additionally, correctness when reading an lwb's state is often
64 65 * acheived by exploiting the fact that these state transitions occur in
65 66 * this specific order; i.e. "closed" to "opened" to "issued" to "done".
66 67 *
67 68 * Thus, if an lwb is in the "closed" or "opened" state, holding the
68 69 * "zl_issuer_lock" will prevent a concurrent thread from transitioning
69 70 * that lwb to the "issued" state. Likewise, if an lwb is already in the
70 71 * "issued" state, holding the "zl_lock" will prevent a concurrent
71 - * thread from transitioning that lwb to the "done" state.
72 + * thread from transitioning that lwb to the "write done" state.
72 73 */
73 74 typedef enum {
74 75 LWB_STATE_CLOSED,
75 76 LWB_STATE_OPENED,
76 77 LWB_STATE_ISSUED,
77 - LWB_STATE_DONE,
78 + LWB_STATE_WRITE_DONE,
79 + LWB_STATE_FLUSH_DONE,
78 80 LWB_NUM_STATES
79 81 } lwb_state_t;
80 82
81 83 /*
82 84 * Log write block (lwb)
83 85 *
84 86 * Prior to an lwb being issued to disk via zil_lwb_write_issue(), it
85 87 * will be protected by the zilog's "zl_issuer_lock". Basically, prior
86 88 * to it being issued, it will only be accessed by the thread that's
87 89 * holding the "zl_issuer_lock". After the lwb is issued, the zilog's
88 90 * "zl_lock" is used to protect the lwb against concurrent access.
89 91 */
90 92 typedef struct lwb {
91 93 zilog_t *lwb_zilog; /* back pointer to log struct */
92 94 blkptr_t lwb_blk; /* on disk address of this log blk */
93 95 boolean_t lwb_slog; /* lwb_blk is on SLOG device */
94 96 int lwb_nused; /* # used bytes in buffer */
95 97 int lwb_sz; /* size of block and buffer */
96 98 lwb_state_t lwb_state; /* the state of this lwb */
97 99 char *lwb_buf; /* log write buffer */
98 100 zio_t *lwb_write_zio; /* zio for the lwb buffer */
99 101 zio_t *lwb_root_zio; /* root zio for lwb write and flushes */
100 102 dmu_tx_t *lwb_tx; /* tx for log block allocation */
101 103 uint64_t lwb_max_txg; /* highest txg in this lwb */
102 104 list_node_t lwb_node; /* zilog->zl_lwb_list linkage */
103 105 list_t lwb_waiters; /* list of zil_commit_waiter's */
104 106 avl_tree_t lwb_vdev_tree; /* vdevs to flush after lwb write */
105 107 kmutex_t lwb_vdev_lock; /* protects lwb_vdev_tree */
106 108 hrtime_t lwb_issued_timestamp; /* when was the lwb issued? */
107 109 } lwb_t;
108 110
109 111 /*
110 112 * ZIL commit waiter.
111 113 *
112 114 * This structure is allocated each time zil_commit() is called, and is
113 115 * used by zil_commit() to communicate with other parts of the ZIL, such
114 116 * that zil_commit() can know when it safe for it return. For more
115 117 * details, see the comment above zil_commit().
116 118 *
117 119 * The "zcw_lock" field is used to protect the commit waiter against
118 120 * concurrent access. This lock is often acquired while already holding
119 121 * the zilog's "zl_issuer_lock" or "zl_lock"; see the functions
120 122 * zil_process_commit_list() and zil_lwb_flush_vdevs_done() as examples
121 123 * of this. Thus, one must be careful not to acquire the
122 124 * "zl_issuer_lock" or "zl_lock" when already holding the "zcw_lock";
123 125 * e.g. see the zil_commit_waiter_timeout() function.
124 126 */
125 127 typedef struct zil_commit_waiter {
126 128 kcondvar_t zcw_cv; /* signalled when "done" */
127 129 kmutex_t zcw_lock; /* protects fields of this struct */
128 130 list_node_t zcw_node; /* linkage in lwb_t:lwb_waiter list */
129 131 lwb_t *zcw_lwb; /* back pointer to lwb when linked */
130 132 boolean_t zcw_done; /* B_TRUE when "done", else B_FALSE */
131 133 int zcw_zio_error; /* contains the zio io_error value */
132 134 } zil_commit_waiter_t;
133 135
134 136 /*
135 137 * Intent log transaction lists
136 138 */
137 139 typedef struct itxs {
138 140 list_t i_sync_list; /* list of synchronous itxs */
139 141 avl_tree_t i_async_tree; /* tree of foids for async itxs */
140 142 } itxs_t;
141 143
142 144 typedef struct itxg {
143 145 kmutex_t itxg_lock; /* lock for this structure */
144 146 uint64_t itxg_txg; /* txg for this chain */
145 147 itxs_t *itxg_itxs; /* sync and async itxs */
146 148 } itxg_t;
147 149
148 150 /* for async nodes we build up an AVL tree of lists of async itxs per file */
149 151 typedef struct itx_async_node {
150 152 uint64_t ia_foid; /* file object id */
151 153 list_t ia_list; /* list of async itxs for this foid */
152 154 avl_node_t ia_node; /* AVL tree linkage */
153 155 } itx_async_node_t;
154 156
155 157 /*
156 158 * Vdev flushing: during a zil_commit(), we build up an AVL tree of the vdevs
157 159 * we've touched so we know which ones need a write cache flush at the end.
158 160 */
159 161 typedef struct zil_vdev_node {
160 162 uint64_t zv_vdev; /* vdev to be flushed */
161 163 avl_node_t zv_node; /* AVL tree linkage */
162 164 } zil_vdev_node_t;
163 165
164 166 #define ZIL_PREV_BLKS 16
165 167
166 168 /*
167 169 * Stable storage intent log management structure. One per dataset.
168 170 */
169 171 struct zilog {
170 172 kmutex_t zl_lock; /* protects most zilog_t fields */
171 173 struct dsl_pool *zl_dmu_pool; /* DSL pool */
172 174 spa_t *zl_spa; /* handle for read/write log */
173 175 const zil_header_t *zl_header; /* log header buffer */
174 176 objset_t *zl_os; /* object set we're logging */
175 177 zil_get_data_t *zl_get_data; /* callback to get object content */
176 178 lwb_t *zl_last_lwb_opened; /* most recent lwb opened */
177 179 hrtime_t zl_last_lwb_latency; /* zio latency of last lwb done */
178 180 uint64_t zl_lr_seq; /* on-disk log record sequence number */
179 181 uint64_t zl_commit_lr_seq; /* last committed on-disk lr seq */
180 182 uint64_t zl_destroy_txg; /* txg of last zil_destroy() */
181 183 uint64_t zl_replayed_seq[TXG_SIZE]; /* last replayed rec seq */
182 184 uint64_t zl_replaying_seq; /* current replay seq number */
183 185 uint32_t zl_suspend; /* log suspend count */
184 186 kcondvar_t zl_cv_suspend; /* log suspend completion */
185 187 uint8_t zl_suspending; /* log is currently suspending */
186 188 uint8_t zl_keep_first; /* keep first log block in destroy */
187 189 uint8_t zl_replay; /* replaying records while set */
188 190 uint8_t zl_stop_sync; /* for debugging */
189 191 kmutex_t zl_issuer_lock; /* single writer, per ZIL, at a time */
190 192 uint8_t zl_logbias; /* latency or throughput */
191 193 uint8_t zl_sync; /* synchronous or asynchronous */
192 194 int zl_parse_error; /* last zil_parse() error */
193 195 uint64_t zl_parse_blk_seq; /* highest blk seq on last parse */
194 196 uint64_t zl_parse_lr_seq; /* highest lr seq on last parse */
195 197 uint64_t zl_parse_blk_count; /* number of blocks parsed */
196 198 uint64_t zl_parse_lr_count; /* number of log records parsed */
197 199 itxg_t zl_itxg[TXG_SIZE]; /* intent log txg chains */
198 200 list_t zl_itx_commit_list; /* itx list to be committed */
199 201 uint64_t zl_cur_used; /* current commit log size used */
200 202 list_t zl_lwb_list; /* in-flight log write list */
201 203 avl_tree_t zl_bp_tree; /* track bps during log parse */
202 204 clock_t zl_replay_time; /* lbolt of when replay started */
203 205 uint64_t zl_replay_blks; /* number of log blocks replayed */
204 206 zil_header_t zl_old_header; /* debugging aid */
205 207 uint_t zl_prev_blks[ZIL_PREV_BLKS]; /* size - sector rounded */
206 208 uint_t zl_prev_rotor; /* rotor for zl_prev[] */
207 209 txg_node_t zl_dirty_link; /* protected by dp_dirty_zilogs list */
208 210 uint64_t zl_dirty_max_txg; /* highest txg used to dirty zilog */
209 211 };
210 212
211 213 typedef struct zil_bp_node {
212 214 dva_t zn_dva;
213 215 avl_node_t zn_node;
214 216 } zil_bp_node_t;
215 217
216 218 /*
217 219 * Maximum amount of write data that can be put into single log block.
218 220 */
219 221 #define ZIL_MAX_LOG_DATA (SPA_OLD_MAXBLOCKSIZE - sizeof (zil_chain_t) - \
220 222 sizeof (lr_write_t))
221 223
222 224 /*
223 225 * Maximum amount of log space we agree to waste to reduce number of
224 226 * WR_NEED_COPY chunks to reduce zl_get_data() overhead (~12%).
225 227 */
226 228 #define ZIL_MAX_WASTE_SPACE (ZIL_MAX_LOG_DATA / 8)
227 229
228 230 /*
229 231 * Maximum amount of write data for WR_COPIED. Fall back to WR_NEED_COPY
230 232 * as more space efficient if we can't fit at least two log records into
231 233 * maximum sized log block.
232 234 */
233 235 #define ZIL_MAX_COPIED_DATA ((SPA_OLD_MAXBLOCKSIZE - \
234 236 sizeof (zil_chain_t)) / 2 - sizeof (lr_write_t))
235 237
236 238 #ifdef __cplusplus
237 239 }
238 240 #endif
239 241
240 242 #endif /* _SYS_ZIL_IMPL_H */
|
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX