dsl_pool.c (177698) | dsl_pool.c (185029) |
---|---|
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 --- 5 unchanged lines hidden (view full) --- 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/* | 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 --- 5 unchanged lines hidden (view full) --- 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/* |
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 | 23 * Use is subject to license terms. 24 */ 25 |
26#pragma ident "%Z%%M% %I% %E% SMI" 27 | |
28#include <sys/dsl_pool.h> 29#include <sys/dsl_dataset.h> 30#include <sys/dsl_dir.h> 31#include <sys/dsl_synctask.h> 32#include <sys/dmu_tx.h> 33#include <sys/dmu_objset.h> 34#include <sys/arc.h> 35#include <sys/zap.h> 36#include <sys/zio.h> 37#include <sys/zfs_context.h> 38#include <sys/fs/zfs.h> | 26#include <sys/dsl_pool.h> 27#include <sys/dsl_dataset.h> 28#include <sys/dsl_dir.h> 29#include <sys/dsl_synctask.h> 30#include <sys/dmu_tx.h> 31#include <sys/dmu_objset.h> 32#include <sys/arc.h> 33#include <sys/zap.h> 34#include <sys/zio.h> 35#include <sys/zfs_context.h> 36#include <sys/fs/zfs.h> |
37#include <sys/zfs_znode.h> 38#include <sys/spa_impl.h> |
|
39 | 39 |
40int zfs_no_write_throttle = 0; 41int zfs_write_limit_shift = 3; /* 1/8th of physical memory */ 42int zfs_txg_synctime = 5; /* target secs to sync a txg */ 43 44uint64_t zfs_write_limit_min = 32 << 20; /* min write limit is 32MB */ 45uint64_t zfs_write_limit_max = 0; /* max data payload per txg */ 46uint64_t zfs_write_limit_inflated = 0; 47uint64_t zfs_write_limit_override = 0; 48extern uint64_t zfs_write_limit_min; 49 50kmutex_t zfs_write_limit_lock; 51 52static pgcnt_t old_physmem = 0; 53 |
|
40static int | 54static int |
41dsl_pool_open_mos_dir(dsl_pool_t *dp, dsl_dir_t **ddp) | 55dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **ddp) |
42{ 43 uint64_t obj; 44 int err; 45 46 err = zap_lookup(dp->dp_meta_objset, 47 dp->dp_root_dir->dd_phys->dd_child_dir_zapobj, | 56{ 57 uint64_t obj; 58 int err; 59 60 err = zap_lookup(dp->dp_meta_objset, 61 dp->dp_root_dir->dd_phys->dd_child_dir_zapobj, |
48 MOS_DIR_NAME, sizeof (obj), 1, &obj); | 62 name, sizeof (obj), 1, &obj); |
49 if (err) 50 return (err); 51 | 63 if (err) 64 return (err); 65 |
52 return (dsl_dir_open_obj(dp, obj, MOS_DIR_NAME, dp, ddp)); | 66 return (dsl_dir_open_obj(dp, obj, name, dp, ddp)); |
53} 54 55static dsl_pool_t * 56dsl_pool_open_impl(spa_t *spa, uint64_t txg) 57{ 58 dsl_pool_t *dp; 59 blkptr_t *bp = spa_get_rootblkptr(spa); 60 61 dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP); 62 dp->dp_spa = spa; 63 dp->dp_meta_rootbp = *bp; 64 rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL); | 67} 68 69static dsl_pool_t * 70dsl_pool_open_impl(spa_t *spa, uint64_t txg) 71{ 72 dsl_pool_t *dp; 73 blkptr_t *bp = spa_get_rootblkptr(spa); 74 75 dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP); 76 dp->dp_spa = spa; 77 dp->dp_meta_rootbp = *bp; 78 rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL); |
79 dp->dp_write_limit = zfs_write_limit_min; |
|
65 txg_init(dp, txg); 66 67 txg_list_create(&dp->dp_dirty_datasets, 68 offsetof(dsl_dataset_t, ds_dirty_link)); 69 txg_list_create(&dp->dp_dirty_dirs, 70 offsetof(dsl_dir_t, dd_dirty_link)); 71 txg_list_create(&dp->dp_sync_tasks, 72 offsetof(dsl_sync_task_group_t, dstg_node)); | 80 txg_init(dp, txg); 81 82 txg_list_create(&dp->dp_dirty_datasets, 83 offsetof(dsl_dataset_t, ds_dirty_link)); 84 txg_list_create(&dp->dp_dirty_dirs, 85 offsetof(dsl_dir_t, dd_dirty_link)); 86 txg_list_create(&dp->dp_sync_tasks, 87 offsetof(dsl_sync_task_group_t, dstg_node)); |
73 list_create(&dp->dp_synced_objsets, sizeof (dsl_dataset_t), | 88 list_create(&dp->dp_synced_datasets, sizeof (dsl_dataset_t), |
74 offsetof(dsl_dataset_t, ds_synced_link)); 75 | 89 offsetof(dsl_dataset_t, ds_synced_link)); 90 |
91 mutex_init(&dp->dp_lock, NULL, MUTEX_DEFAULT, NULL); 92 mutex_init(&dp->dp_scrub_cancel_lock, NULL, MUTEX_DEFAULT, NULL); 93 |
|
76 return (dp); 77} 78 79int 80dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp) 81{ 82 int err; 83 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); | 94 return (dp); 95} 96 97int 98dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp) 99{ 100 int err; 101 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); |
102 dsl_dir_t *dd; 103 dsl_dataset_t *ds; |
|
84 objset_impl_t *osi; 85 | 104 objset_impl_t *osi; 105 |
86 rw_enter(&dp->dp_config_rwlock, RW_READER); | 106 rw_enter(&dp->dp_config_rwlock, RW_WRITER); |
87 err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp, &osi); 88 if (err) 89 goto out; 90 dp->dp_meta_objset = &osi->os; 91 92 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 93 DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1, 94 &dp->dp_root_dir_obj); 95 if (err) 96 goto out; 97 98 err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj, 99 NULL, dp, &dp->dp_root_dir); 100 if (err) 101 goto out; 102 | 107 err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp, &osi); 108 if (err) 109 goto out; 110 dp->dp_meta_objset = &osi->os; 111 112 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 113 DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1, 114 &dp->dp_root_dir_obj); 115 if (err) 116 goto out; 117 118 err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj, 119 NULL, dp, &dp->dp_root_dir); 120 if (err) 121 goto out; 122 |
103 err = dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir); | 123 err = dsl_pool_open_special_dir(dp, MOS_DIR_NAME, &dp->dp_mos_dir); |
104 if (err) 105 goto out; 106 | 124 if (err) 125 goto out; 126 |
127 if (spa_version(spa) >= SPA_VERSION_ORIGIN) { 128 err = dsl_pool_open_special_dir(dp, ORIGIN_DIR_NAME, &dd); 129 if (err) 130 goto out; 131 err = dsl_dataset_hold_obj(dp, dd->dd_phys->dd_head_dataset_obj, 132 FTAG, &ds); 133 if (err) 134 goto out; 135 err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj, 136 dp, &dp->dp_origin_snap); 137 if (err) 138 goto out; 139 dsl_dataset_rele(ds, FTAG); 140 dsl_dir_close(dd, dp); 141 } 142 143 /* get scrub status */ 144 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 145 DMU_POOL_SCRUB_FUNC, sizeof (uint32_t), 1, 146 &dp->dp_scrub_func); 147 if (err == 0) { 148 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 149 DMU_POOL_SCRUB_QUEUE, sizeof (uint64_t), 1, 150 &dp->dp_scrub_queue_obj); 151 if (err) 152 goto out; 153 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 154 DMU_POOL_SCRUB_MIN_TXG, sizeof (uint64_t), 1, 155 &dp->dp_scrub_min_txg); 156 if (err) 157 goto out; 158 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 159 DMU_POOL_SCRUB_MAX_TXG, sizeof (uint64_t), 1, 160 &dp->dp_scrub_max_txg); 161 if (err) 162 goto out; 163 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 164 DMU_POOL_SCRUB_BOOKMARK, sizeof (uint64_t), 4, 165 &dp->dp_scrub_bookmark); 166 if (err) 167 goto out; 168 err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 169 DMU_POOL_SCRUB_ERRORS, sizeof (uint64_t), 1, 170 &spa->spa_scrub_errors); 171 if (err) 172 goto out; 173 if (spa_version(spa) < SPA_VERSION_DSL_SCRUB) { 174 /* 175 * A new-type scrub was in progress on an old 176 * pool. Restart from the beginning, since the 177 * old software may have changed the pool in the 178 * meantime. 179 */ 180 dsl_pool_scrub_restart(dp); 181 } 182 } else { 183 /* 184 * It's OK if there is no scrub in progress (and if 185 * there was an I/O error, ignore it). 186 */ 187 err = 0; 188 } 189 |
|
107out: 108 rw_exit(&dp->dp_config_rwlock); 109 if (err) 110 dsl_pool_close(dp); 111 else 112 *dpp = dp; 113 114 return (err); 115} 116 117void 118dsl_pool_close(dsl_pool_t *dp) 119{ | 190out: 191 rw_exit(&dp->dp_config_rwlock); 192 if (err) 193 dsl_pool_close(dp); 194 else 195 *dpp = dp; 196 197 return (err); 198} 199 200void 201dsl_pool_close(dsl_pool_t *dp) 202{ |
120 /* drop our reference from dsl_pool_open() */ | 203 /* drop our references from dsl_pool_open() */ 204 205 /* 206 * Since we held the origin_snap from "syncing" context (which 207 * includes pool-opening context), it actually only got a "ref" 208 * and not a hold, so just drop that here. 209 */ 210 if (dp->dp_origin_snap) 211 dsl_dataset_drop_ref(dp->dp_origin_snap, dp); |
121 if (dp->dp_mos_dir) 122 dsl_dir_close(dp->dp_mos_dir, dp); 123 if (dp->dp_root_dir) 124 dsl_dir_close(dp->dp_root_dir, dp); 125 126 /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */ 127 if (dp->dp_meta_objset) 128 dmu_objset_evict(NULL, dp->dp_meta_objset->os); 129 130 txg_list_destroy(&dp->dp_dirty_datasets); 131 txg_list_destroy(&dp->dp_dirty_dirs); 132 txg_list_destroy(&dp->dp_sync_tasks); | 212 if (dp->dp_mos_dir) 213 dsl_dir_close(dp->dp_mos_dir, dp); 214 if (dp->dp_root_dir) 215 dsl_dir_close(dp->dp_root_dir, dp); 216 217 /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */ 218 if (dp->dp_meta_objset) 219 dmu_objset_evict(NULL, dp->dp_meta_objset->os); 220 221 txg_list_destroy(&dp->dp_dirty_datasets); 222 txg_list_destroy(&dp->dp_dirty_dirs); 223 txg_list_destroy(&dp->dp_sync_tasks); |
133 list_destroy(&dp->dp_synced_objsets); | 224 list_destroy(&dp->dp_synced_datasets); |
134 | 225 |
135 arc_flush(); | 226 arc_flush(dp->dp_spa); |
136 txg_fini(dp); 137 rw_destroy(&dp->dp_config_rwlock); | 227 txg_fini(dp); 228 rw_destroy(&dp->dp_config_rwlock); |
229 mutex_destroy(&dp->dp_lock); 230 mutex_destroy(&dp->dp_scrub_cancel_lock); |
|
138 kmem_free(dp, sizeof (dsl_pool_t)); 139} 140 141dsl_pool_t * | 231 kmem_free(dp, sizeof (dsl_pool_t)); 232} 233 234dsl_pool_t * |
142dsl_pool_create(spa_t *spa, uint64_t txg) | 235dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg) |
143{ 144 int err; 145 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); 146 dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg); | 236{ 237 int err; 238 dsl_pool_t *dp = dsl_pool_open_impl(spa, txg); 239 dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg); |
240 objset_impl_t *osip; 241 dsl_dataset_t *ds; 242 uint64_t dsobj; 243 244 /* create and open the MOS (meta-objset) */ |
|
147 dp->dp_meta_objset = &dmu_objset_create_impl(spa, 148 NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx)->os; 149 150 /* create the pool directory */ 151 err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 152 DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx); 153 ASSERT3U(err, ==, 0); 154 155 /* create and open the root dir */ | 245 dp->dp_meta_objset = &dmu_objset_create_impl(spa, 246 NULL, &dp->dp_meta_rootbp, DMU_OST_META, tx)->os; 247 248 /* create the pool directory */ 249 err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT, 250 DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx); 251 ASSERT3U(err, ==, 0); 252 253 /* create and open the root dir */ |
156 dsl_dataset_create_root(dp, &dp->dp_root_dir_obj, tx); | 254 dp->dp_root_dir_obj = dsl_dir_create_sync(dp, NULL, NULL, tx); |
157 VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj, 158 NULL, dp, &dp->dp_root_dir)); 159 160 /* create and open the meta-objset dir */ | 255 VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj, 256 NULL, dp, &dp->dp_root_dir)); 257 258 /* create and open the meta-objset dir */ |
161 (void) dsl_dir_create_sync(dp->dp_root_dir, MOS_DIR_NAME, tx); 162 VERIFY(0 == dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir)); | 259 (void) dsl_dir_create_sync(dp, dp->dp_root_dir, MOS_DIR_NAME, tx); 260 VERIFY(0 == dsl_pool_open_special_dir(dp, 261 MOS_DIR_NAME, &dp->dp_mos_dir)); |
163 | 262 |
263 if (spa_version(spa) >= SPA_VERSION_DSL_SCRUB) 264 dsl_pool_create_origin(dp, tx); 265 266 /* create the root dataset */ 267 dsobj = dsl_dataset_create_sync_dd(dp->dp_root_dir, NULL, 0, tx); 268 269 /* create the root objset */ 270 VERIFY(0 == dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds)); 271 osip = dmu_objset_create_impl(dp->dp_spa, ds, 272 dsl_dataset_get_blkptr(ds), DMU_OST_ZFS, tx); 273#ifdef _KERNEL 274 zfs_create_fs(&osip->os, kcred, zplprops, tx); 275#endif 276 dsl_dataset_rele(ds, FTAG); 277 |
|
164 dmu_tx_commit(tx); 165 166 return (dp); 167} 168 169void 170dsl_pool_sync(dsl_pool_t *dp, uint64_t txg) 171{ 172 zio_t *zio; 173 dmu_tx_t *tx; 174 dsl_dir_t *dd; 175 dsl_dataset_t *ds; 176 dsl_sync_task_group_t *dstg; 177 objset_impl_t *mosi = dp->dp_meta_objset->os; | 278 dmu_tx_commit(tx); 279 280 return (dp); 281} 282 283void 284dsl_pool_sync(dsl_pool_t *dp, uint64_t txg) 285{ 286 zio_t *zio; 287 dmu_tx_t *tx; 288 dsl_dir_t *dd; 289 dsl_dataset_t *ds; 290 dsl_sync_task_group_t *dstg; 291 objset_impl_t *mosi = dp->dp_meta_objset->os; |
292 hrtime_t start, write_time; 293 uint64_t data_written; |
|
178 int err; 179 180 tx = dmu_tx_create_assigned(dp, txg); 181 | 294 int err; 295 296 tx = dmu_tx_create_assigned(dp, txg); 297 |
298 dp->dp_read_overhead = 0; |
|
182 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 183 while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) { 184 if (!list_link_active(&ds->ds_synced_link)) | 299 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 300 while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) { 301 if (!list_link_active(&ds->ds_synced_link)) |
185 list_insert_tail(&dp->dp_synced_objsets, ds); | 302 list_insert_tail(&dp->dp_synced_datasets, ds); |
186 else 187 dmu_buf_rele(ds->ds_dbuf, ds); 188 dsl_dataset_sync(ds, zio, tx); 189 } | 303 else 304 dmu_buf_rele(ds->ds_dbuf, ds); 305 dsl_dataset_sync(ds, zio, tx); 306 } |
307 DTRACE_PROBE(pool_sync__1setup); 308 309 start = gethrtime(); |
|
190 err = zio_wait(zio); | 310 err = zio_wait(zio); |
311 write_time = gethrtime() - start; |
|
191 ASSERT(err == 0); | 312 ASSERT(err == 0); |
313 DTRACE_PROBE(pool_sync__2rootzio); |
|
192 193 while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg)) 194 dsl_sync_task_group_sync(dstg, tx); | 314 315 while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg)) 316 dsl_sync_task_group_sync(dstg, tx); |
317 DTRACE_PROBE(pool_sync__3task); 318 319 start = gethrtime(); |
|
195 while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg)) 196 dsl_dir_sync(dd, tx); | 320 while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg)) 321 dsl_dir_sync(dd, tx); |
322 write_time += gethrtime() - start; |
|
197 | 323 |
324 if (spa_sync_pass(dp->dp_spa) == 1) 325 dsl_pool_scrub_sync(dp, tx); 326 327 start = gethrtime(); |
|
198 if (list_head(&mosi->os_dirty_dnodes[txg & TXG_MASK]) != NULL || 199 list_head(&mosi->os_free_dnodes[txg & TXG_MASK]) != NULL) { 200 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 201 dmu_objset_sync(mosi, zio, tx); 202 err = zio_wait(zio); 203 ASSERT(err == 0); 204 dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", ""); 205 spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp); 206 } | 328 if (list_head(&mosi->os_dirty_dnodes[txg & TXG_MASK]) != NULL || 329 list_head(&mosi->os_free_dnodes[txg & TXG_MASK]) != NULL) { 330 zio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED); 331 dmu_objset_sync(mosi, zio, tx); 332 err = zio_wait(zio); 333 ASSERT(err == 0); 334 dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", ""); 335 spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp); 336 } |
337 write_time += gethrtime() - start; 338 DTRACE_PROBE2(pool_sync__4io, hrtime_t, write_time, 339 hrtime_t, dp->dp_read_overhead); 340 write_time -= dp->dp_read_overhead; |
|
207 208 dmu_tx_commit(tx); | 341 342 dmu_tx_commit(tx); |
343 344 data_written = dp->dp_space_towrite[txg & TXG_MASK]; 345 dp->dp_space_towrite[txg & TXG_MASK] = 0; 346 ASSERT(dp->dp_tempreserved[txg & TXG_MASK] == 0); 347 348 /* 349 * If the write limit max has not been explicitly set, set it 350 * to a fraction of available physical memory (default 1/8th). 351 * Note that we must inflate the limit because the spa 352 * inflates write sizes to account for data replication. 353 * Check this each sync phase to catch changing memory size. 354 */ 355 if (physmem != old_physmem && zfs_write_limit_shift) { 356 mutex_enter(&zfs_write_limit_lock); 357 old_physmem = physmem; 358 zfs_write_limit_max = ptob(physmem) >> zfs_write_limit_shift; 359 zfs_write_limit_inflated = MAX(zfs_write_limit_min, 360 spa_get_asize(dp->dp_spa, zfs_write_limit_max)); 361 mutex_exit(&zfs_write_limit_lock); 362 } 363 364 /* 365 * Attempt to keep the sync time consistent by adjusting the 366 * amount of write traffic allowed into each transaction group. 367 * Weight the throughput calculation towards the current value: 368 * thru = 3/4 old_thru + 1/4 new_thru 369 */ 370 ASSERT(zfs_write_limit_min > 0); 371 if (data_written > zfs_write_limit_min / 8 && write_time > 0) { 372 uint64_t throughput = (data_written * NANOSEC) / write_time; 373 if (dp->dp_throughput) 374 dp->dp_throughput = throughput / 4 + 375 3 * dp->dp_throughput / 4; 376 else 377 dp->dp_throughput = throughput; 378 dp->dp_write_limit = MIN(zfs_write_limit_inflated, 379 MAX(zfs_write_limit_min, 380 dp->dp_throughput * zfs_txg_synctime)); 381 } |
|
209} 210 211void 212dsl_pool_zil_clean(dsl_pool_t *dp) 213{ 214 dsl_dataset_t *ds; 215 | 382} 383 384void 385dsl_pool_zil_clean(dsl_pool_t *dp) 386{ 387 dsl_dataset_t *ds; 388 |
216 while (ds = list_head(&dp->dp_synced_objsets)) { 217 list_remove(&dp->dp_synced_objsets, ds); | 389 while (ds = list_head(&dp->dp_synced_datasets)) { 390 list_remove(&dp->dp_synced_datasets, ds); |
218 ASSERT(ds->ds_user_ptr != NULL); 219 zil_clean(((objset_impl_t *)ds->ds_user_ptr)->os_zil); 220 dmu_buf_rele(ds->ds_dbuf, ds); 221 } 222} 223 224/* 225 * TRUE if the current thread is the tx_sync_thread or if we --- 23 unchanged lines hidden (view full) --- 249 */ 250 space = spa_get_dspace(dp->dp_spa); 251 resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1); 252 if (netfree) 253 resv >>= 1; 254 255 return (space - resv); 256} | 391 ASSERT(ds->ds_user_ptr != NULL); 392 zil_clean(((objset_impl_t *)ds->ds_user_ptr)->os_zil); 393 dmu_buf_rele(ds->ds_dbuf, ds); 394 } 395} 396 397/* 398 * TRUE if the current thread is the tx_sync_thread or if we --- 23 unchanged lines hidden (view full) --- 422 */ 423 space = spa_get_dspace(dp->dp_spa); 424 resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1); 425 if (netfree) 426 resv >>= 1; 427 428 return (space - resv); 429} |
430 431int 432dsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx) 433{ 434 uint64_t reserved = 0; 435 uint64_t write_limit = (zfs_write_limit_override ? 436 zfs_write_limit_override : dp->dp_write_limit); 437 438 if (zfs_no_write_throttle) { 439 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], 440 space); 441 return (0); 442 } 443 444 /* 445 * Check to see if we have exceeded the maximum allowed IO for 446 * this transaction group. We can do this without locks since 447 * a little slop here is ok. Note that we do the reserved check 448 * with only half the requested reserve: this is because the 449 * reserve requests are worst-case, and we really don't want to 450 * throttle based off of worst-case estimates. 451 */ 452 if (write_limit > 0) { 453 reserved = dp->dp_space_towrite[tx->tx_txg & TXG_MASK] 454 + dp->dp_tempreserved[tx->tx_txg & TXG_MASK] / 2; 455 456 if (reserved && reserved > write_limit) 457 return (ERESTART); 458 } 459 460 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], space); 461 462 /* 463 * If this transaction group is over 7/8ths capacity, delay 464 * the caller 1 clock tick. This will slow down the "fill" 465 * rate until the sync process can catch up with us. 466 */ 467 if (reserved && reserved > (write_limit - (write_limit >> 3))) 468 txg_delay(dp, tx->tx_txg, 1); 469 470 return (0); 471} 472 473void 474dsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx) 475{ 476 ASSERT(dp->dp_tempreserved[tx->tx_txg & TXG_MASK] >= space); 477 atomic_add_64(&dp->dp_tempreserved[tx->tx_txg & TXG_MASK], -space); 478} 479 480void 481dsl_pool_memory_pressure(dsl_pool_t *dp) 482{ 483 uint64_t space_inuse = 0; 484 int i; 485 486 if (dp->dp_write_limit == zfs_write_limit_min) 487 return; 488 489 for (i = 0; i < TXG_SIZE; i++) { 490 space_inuse += dp->dp_space_towrite[i]; 491 space_inuse += dp->dp_tempreserved[i]; 492 } 493 dp->dp_write_limit = MAX(zfs_write_limit_min, 494 MIN(dp->dp_write_limit, space_inuse / 4)); 495} 496 497void 498dsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx) 499{ 500 if (space > 0) { 501 mutex_enter(&dp->dp_lock); 502 dp->dp_space_towrite[tx->tx_txg & TXG_MASK] += space; 503 mutex_exit(&dp->dp_lock); 504 } 505} 506 507/* ARGSUSED */ 508static int 509upgrade_clones_cb(spa_t *spa, uint64_t dsobj, const char *dsname, void *arg) 510{ 511 dmu_tx_t *tx = arg; 512 dsl_dataset_t *ds, *prev = NULL; 513 int err; 514 dsl_pool_t *dp = spa_get_dsl(spa); 515 516 err = dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds); 517 if (err) 518 return (err); 519 520 while (ds->ds_phys->ds_prev_snap_obj != 0) { 521 err = dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj, 522 FTAG, &prev); 523 if (err) { 524 dsl_dataset_rele(ds, FTAG); 525 return (err); 526 } 527 528 if (prev->ds_phys->ds_next_snap_obj != ds->ds_object) 529 break; 530 dsl_dataset_rele(ds, FTAG); 531 ds = prev; 532 prev = NULL; 533 } 534 535 if (prev == NULL) { 536 prev = dp->dp_origin_snap; 537 538 /* 539 * The $ORIGIN can't have any data, or the accounting 540 * will be wrong. 541 */ 542 ASSERT(prev->ds_phys->ds_bp.blk_birth == 0); 543 544 /* The origin doesn't get attached to itself */ 545 if (ds->ds_object == prev->ds_object) { 546 dsl_dataset_rele(ds, FTAG); 547 return (0); 548 } 549 550 dmu_buf_will_dirty(ds->ds_dbuf, tx); 551 ds->ds_phys->ds_prev_snap_obj = prev->ds_object; 552 ds->ds_phys->ds_prev_snap_txg = prev->ds_phys->ds_creation_txg; 553 554 dmu_buf_will_dirty(ds->ds_dir->dd_dbuf, tx); 555 ds->ds_dir->dd_phys->dd_origin_obj = prev->ds_object; 556 557 dmu_buf_will_dirty(prev->ds_dbuf, tx); 558 prev->ds_phys->ds_num_children++; 559 560 if (ds->ds_phys->ds_next_snap_obj == 0) { 561 ASSERT(ds->ds_prev == NULL); 562 VERIFY(0 == dsl_dataset_hold_obj(dp, 563 ds->ds_phys->ds_prev_snap_obj, ds, &ds->ds_prev)); 564 } 565 } 566 567 ASSERT(ds->ds_dir->dd_phys->dd_origin_obj == prev->ds_object); 568 ASSERT(ds->ds_phys->ds_prev_snap_obj == prev->ds_object); 569 570 if (prev->ds_phys->ds_next_clones_obj == 0) { 571 prev->ds_phys->ds_next_clones_obj = 572 zap_create(dp->dp_meta_objset, 573 DMU_OT_NEXT_CLONES, DMU_OT_NONE, 0, tx); 574 } 575 VERIFY(0 == zap_add_int(dp->dp_meta_objset, 576 prev->ds_phys->ds_next_clones_obj, ds->ds_object, tx)); 577 578 dsl_dataset_rele(ds, FTAG); 579 if (prev != dp->dp_origin_snap) 580 dsl_dataset_rele(prev, FTAG); 581 return (0); 582} 583 584void 585dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx) 586{ 587 ASSERT(dmu_tx_is_syncing(tx)); 588 ASSERT(dp->dp_origin_snap != NULL); 589 590 (void) dmu_objset_find_spa(dp->dp_spa, NULL, upgrade_clones_cb, 591 tx, DS_FIND_CHILDREN); 592} 593 594void 595dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx) 596{ 597 uint64_t dsobj; 598 dsl_dataset_t *ds; 599 600 ASSERT(dmu_tx_is_syncing(tx)); 601 ASSERT(dp->dp_origin_snap == NULL); 602 603 /* create the origin dir, ds, & snap-ds */ 604 rw_enter(&dp->dp_config_rwlock, RW_WRITER); 605 dsobj = dsl_dataset_create_sync(dp->dp_root_dir, ORIGIN_DIR_NAME, 606 NULL, 0, kcred, tx); 607 VERIFY(0 == dsl_dataset_hold_obj(dp, dsobj, FTAG, &ds)); 608 dsl_dataset_snapshot_sync(ds, ORIGIN_DIR_NAME, kcred, tx); 609 VERIFY(0 == dsl_dataset_hold_obj(dp, ds->ds_phys->ds_prev_snap_obj, 610 dp, &dp->dp_origin_snap)); 611 dsl_dataset_rele(ds, FTAG); 612 rw_exit(&dp->dp_config_rwlock); 613} |
|