1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 53547Smaybee * Common Development and Distribution License (the "License"). 63547Smaybee * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 21789Sahrens /* 22*11539SChunli.Zhang@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 23789Sahrens * Use is subject to license terms. 24789Sahrens */ 25789Sahrens 26789Sahrens #ifndef _SYS_DMU_IMPL_H 27789Sahrens #define _SYS_DMU_IMPL_H 28789Sahrens 29789Sahrens #include <sys/txg_impl.h> 30789Sahrens #include <sys/zio.h> 31789Sahrens #include <sys/dnode.h> 32789Sahrens #include <sys/zfs_context.h> 33789Sahrens 34789Sahrens #ifdef __cplusplus 35789Sahrens extern "C" { 36789Sahrens #endif 37789Sahrens 38789Sahrens /* 39789Sahrens * This is the locking strategy for the DMU. Numbers in parenthesis are 40789Sahrens * cases that use that lock order, referenced below: 41789Sahrens * 42789Sahrens * ARC is self-contained 43789Sahrens * bplist is self-contained 44789Sahrens * refcount is self-contained 45789Sahrens * txg is self-contained (hopefully!) 46789Sahrens * zst_lock 47789Sahrens * zf_rwlock 48789Sahrens * 49789Sahrens * XXX try to improve evicting path? 50789Sahrens * 51789Sahrens * dp_config_rwlock > os_obj_lock > dn_struct_rwlock > 527595SMatthew.Ahrens@Sun.COM * dn_dbufs_mtx > hash_mutexes > db_mtx > dd_lock > leafs 53789Sahrens * 54789Sahrens * dp_config_rwlock 55789Sahrens * must be held before: everything 56789Sahrens * protects dd namespace changes 57789Sahrens * protects property changes globally 58789Sahrens * held from: 59789Sahrens * dsl_dir_open/r: 60789Sahrens * dsl_dir_create_sync/w: 61789Sahrens * dsl_dir_sync_destroy/w: 62789Sahrens * dsl_dir_rename_sync/w: 63789Sahrens * dsl_prop_changed_notify/r: 64789Sahrens * 65789Sahrens * os_obj_lock 66789Sahrens * must be held before: 67789Sahrens * everything except dp_config_rwlock 68789Sahrens * protects os_obj_next 69789Sahrens * held from: 70789Sahrens * dmu_object_alloc: dn_dbufs_mtx, db_mtx, hash_mutexes, dn_struct_rwlock 71789Sahrens * 72789Sahrens * dn_struct_rwlock 73789Sahrens * must be held before: 74789Sahrens * everything except dp_config_rwlock and os_obj_lock 75789Sahrens * protects structure of dnode (eg. nlevels) 76789Sahrens * db_blkptr can change when syncing out change to nlevels 77789Sahrens * dn_maxblkid 78789Sahrens * dn_nlevels 79789Sahrens * dn_*blksz* 80789Sahrens * phys nlevels, maxblkid, physical blkptr_t's (?) 81789Sahrens * held from: 82789Sahrens * callers of dbuf_read_impl, dbuf_hold[_impl], dbuf_prefetch 83789Sahrens * dmu_object_info_from_dnode: dn_dirty_mtx (dn_datablksz) 84789Sahrens * dmu_tx_count_free: 85789Sahrens * dbuf_read_impl: db_mtx, dmu_zfetch() 86789Sahrens * dmu_zfetch: zf_rwlock/r, zst_lock, dbuf_prefetch() 87789Sahrens * dbuf_new_size: db_mtx 88789Sahrens * dbuf_dirty: db_mtx 89789Sahrens * dbuf_findbp: (callers, phys? - the real need) 90789Sahrens * dbuf_create: dn_dbufs_mtx, hash_mutexes, db_mtx (phys?) 91789Sahrens * dbuf_prefetch: dn_dirty_mtx, hash_mutexes, db_mtx, dn_dbufs_mtx 92789Sahrens * dbuf_hold_impl: hash_mutexes, db_mtx, dn_dbufs_mtx, dbuf_findbp() 93789Sahrens * dnode_sync/w (increase_indirection): db_mtx (phys) 94789Sahrens * dnode_set_blksz/w: dn_dbufs_mtx (dn_*blksz*) 95789Sahrens * dnode_new_blkid/w: (dn_maxblkid) 96789Sahrens * dnode_free_range/w: dn_dirty_mtx (dn_maxblkid) 97789Sahrens * dnode_next_offset: (phys) 98789Sahrens * 99789Sahrens * dn_dbufs_mtx 100789Sahrens * must be held before: 101789Sahrens * db_mtx, hash_mutexes 102789Sahrens * protects: 103789Sahrens * dn_dbufs 104789Sahrens * dn_evicted 105789Sahrens * held from: 106789Sahrens * dmu_evict_user: db_mtx (dn_dbufs) 107789Sahrens * dbuf_free_range: db_mtx (dn_dbufs) 108789Sahrens * dbuf_remove_ref: db_mtx, callees: 109789Sahrens * dbuf_hash_remove: hash_mutexes, db_mtx 110789Sahrens * dbuf_create: hash_mutexes, db_mtx (dn_dbufs) 111789Sahrens * dnode_set_blksz: (dn_dbufs) 112789Sahrens * 113789Sahrens * hash_mutexes (global) 114789Sahrens * must be held before: 115789Sahrens * db_mtx 116789Sahrens * protects dbuf_hash_table (global) and db_hash_next 117789Sahrens * held from: 118789Sahrens * dbuf_find: db_mtx 119789Sahrens * dbuf_hash_insert: db_mtx 120789Sahrens * dbuf_hash_remove: db_mtx 121789Sahrens * 122789Sahrens * db_mtx (meta-leaf) 123789Sahrens * must be held before: 124789Sahrens * dn_mtx, dn_dirty_mtx, dd_lock (leaf mutexes) 125789Sahrens * protects: 126789Sahrens * db_state 127789Sahrens * db_holds 128789Sahrens * db_buf 129789Sahrens * db_changed 130789Sahrens * db_data_pending 131789Sahrens * db_dirtied 132789Sahrens * db_link 133789Sahrens * db_dirty_node (??) 134789Sahrens * db_dirtycnt 135789Sahrens * db_d.* 136789Sahrens * db.* 137789Sahrens * held from: 138789Sahrens * dbuf_dirty: dn_mtx, dn_dirty_mtx 139789Sahrens * dbuf_dirty->dsl_dir_willuse_space: dd_lock 140789Sahrens * dbuf_dirty->dbuf_new_block->dsl_dataset_block_freeable: dd_lock 141789Sahrens * dbuf_undirty: dn_dirty_mtx (db_d) 142789Sahrens * dbuf_write_done: dn_dirty_mtx (db_state) 143789Sahrens * dbuf_* 144789Sahrens * dmu_buf_update_user: none (db_d) 145789Sahrens * dmu_evict_user: none (db_d) (maybe can eliminate) 146789Sahrens * dbuf_find: none (db_holds) 147789Sahrens * dbuf_hash_insert: none (db_holds) 148789Sahrens * dmu_buf_read_array_impl: none (db_state, db_changed) 149789Sahrens * dmu_sync: none (db_dirty_node, db_d) 150789Sahrens * dnode_reallocate: none (db) 151789Sahrens * 152789Sahrens * dn_mtx (leaf) 153789Sahrens * protects: 154789Sahrens * dn_dirty_dbufs 155789Sahrens * dn_ranges 156789Sahrens * phys accounting 157789Sahrens * dn_allocated_txg 158789Sahrens * dn_free_txg 159789Sahrens * dn_assigned_txg 160789Sahrens * dd_assigned_tx 161789Sahrens * dn_notxholds 162789Sahrens * dn_dirtyctx 163789Sahrens * dn_dirtyctx_firstset 164789Sahrens * (dn_phys copy fields?) 165789Sahrens * (dn_phys contents?) 166789Sahrens * held from: 167789Sahrens * dnode_* 168789Sahrens * dbuf_dirty: none 169789Sahrens * dbuf_sync: none (phys accounting) 170789Sahrens * dbuf_undirty: none (dn_ranges, dn_dirty_dbufs) 171789Sahrens * dbuf_write_done: none (phys accounting) 172789Sahrens * dmu_object_info_from_dnode: none (accounting) 173789Sahrens * dmu_tx_commit: none 174789Sahrens * dmu_tx_hold_object_impl: none 175789Sahrens * dmu_tx_try_assign: dn_notxholds(cv) 176789Sahrens * dmu_tx_unassign: none 177789Sahrens * 1787525Schris.kirby@sun.com * dd_lock 1797595SMatthew.Ahrens@Sun.COM * must be held before: 1807595SMatthew.Ahrens@Sun.COM * ds_lock 1817595SMatthew.Ahrens@Sun.COM * ancestors' dd_lock 182789Sahrens * protects: 183789Sahrens * dd_prop_cbs 184789Sahrens * dd_sync_* 185789Sahrens * dd_used_bytes 186789Sahrens * dd_tempreserved 187789Sahrens * dd_space_towrite 188789Sahrens * dd_myname 189789Sahrens * dd_phys accounting? 190789Sahrens * held from: 191789Sahrens * dsl_dir_* 192789Sahrens * dsl_prop_changed_notify: none (dd_prop_cbs) 193789Sahrens * dsl_prop_register: none (dd_prop_cbs) 194789Sahrens * dsl_prop_unregister: none (dd_prop_cbs) 195789Sahrens * dsl_dataset_block_freeable: none (dd_sync_*) 196789Sahrens * 197789Sahrens * os_lock (leaf) 198789Sahrens * protects: 199789Sahrens * os_dirty_dnodes 200789Sahrens * os_free_dnodes 201789Sahrens * os_dnodes 202789Sahrens * os_downgraded_dbufs 203789Sahrens * dn_dirtyblksz 204789Sahrens * dn_dirty_link 205789Sahrens * held from: 206789Sahrens * dnode_create: none (os_dnodes) 207789Sahrens * dnode_destroy: none (os_dnodes) 208789Sahrens * dnode_setdirty: none (dn_dirtyblksz, os_*_dnodes) 209789Sahrens * dnode_free: none (dn_dirtyblksz, os_*_dnodes) 210789Sahrens * 2117525Schris.kirby@sun.com * ds_lock 212789Sahrens * protects: 21310298SMatthew.Ahrens@Sun.COM * ds_objset 214789Sahrens * ds_open_refcount 215789Sahrens * ds_snapname 216789Sahrens * ds_phys accounting 21710242Schris.kirby@sun.com * ds_phys userrefs zapobj 2187525Schris.kirby@sun.com * ds_reserved 219789Sahrens * held from: 220789Sahrens * dsl_dataset_* 221789Sahrens * 2223547Smaybee * dr_mtx (leaf) 2233547Smaybee * protects: 2243547Smaybee * dr_children 2253547Smaybee * held from: 2263547Smaybee * dbuf_dirty 2273547Smaybee * dbuf_undirty 2283547Smaybee * dbuf_sync_indirect 2293547Smaybee * dnode_new_blkid 230789Sahrens */ 231789Sahrens 232789Sahrens struct objset; 233789Sahrens struct dmu_pool; 234789Sahrens 235*11539SChunli.Zhang@Sun.COM typedef struct dmu_xuio { 236*11539SChunli.Zhang@Sun.COM int next; 237*11539SChunli.Zhang@Sun.COM int cnt; 238*11539SChunli.Zhang@Sun.COM struct arc_buf **bufs; 239*11539SChunli.Zhang@Sun.COM iovec_t *iovp; 240*11539SChunli.Zhang@Sun.COM } dmu_xuio_t; 241*11539SChunli.Zhang@Sun.COM 242*11539SChunli.Zhang@Sun.COM typedef struct xuio_stats { 243*11539SChunli.Zhang@Sun.COM /* loaned yet not returned arc_buf */ 244*11539SChunli.Zhang@Sun.COM kstat_named_t xuiostat_onloan_rbuf; 245*11539SChunli.Zhang@Sun.COM kstat_named_t xuiostat_onloan_wbuf; 246*11539SChunli.Zhang@Sun.COM /* whether a copy is made when loaning out a read buffer */ 247*11539SChunli.Zhang@Sun.COM kstat_named_t xuiostat_rbuf_copied; 248*11539SChunli.Zhang@Sun.COM kstat_named_t xuiostat_rbuf_nocopy; 249*11539SChunli.Zhang@Sun.COM /* whether a copy is made when assigning a write buffer */ 250*11539SChunli.Zhang@Sun.COM kstat_named_t xuiostat_wbuf_copied; 251*11539SChunli.Zhang@Sun.COM kstat_named_t xuiostat_wbuf_nocopy; 252*11539SChunli.Zhang@Sun.COM } xuio_stats_t; 253*11539SChunli.Zhang@Sun.COM 254*11539SChunli.Zhang@Sun.COM static xuio_stats_t xuio_stats = { 255*11539SChunli.Zhang@Sun.COM { "onloan_read_buf", KSTAT_DATA_UINT64 }, 256*11539SChunli.Zhang@Sun.COM { "onloan_write_buf", KSTAT_DATA_UINT64 }, 257*11539SChunli.Zhang@Sun.COM { "read_buf_copied", KSTAT_DATA_UINT64 }, 258*11539SChunli.Zhang@Sun.COM { "read_buf_nocopy", KSTAT_DATA_UINT64 }, 259*11539SChunli.Zhang@Sun.COM { "write_buf_copied", KSTAT_DATA_UINT64 }, 260*11539SChunli.Zhang@Sun.COM { "write_buf_nocopy", KSTAT_DATA_UINT64 } 261*11539SChunli.Zhang@Sun.COM }; 262*11539SChunli.Zhang@Sun.COM 263*11539SChunli.Zhang@Sun.COM #define XUIOSTAT_INCR(stat, val) \ 264*11539SChunli.Zhang@Sun.COM atomic_add_64(&xuio_stats.stat.value.ui64, (val)) 265*11539SChunli.Zhang@Sun.COM #define XUIOSTAT_BUMP(stat) XUIOSTAT_INCR(stat, 1) 266*11539SChunli.Zhang@Sun.COM 267*11539SChunli.Zhang@Sun.COM 268789Sahrens #ifdef __cplusplus 269789Sahrens } 270789Sahrens #endif 271789Sahrens 272789Sahrens #endif /* _SYS_DMU_IMPL_H */ 273