fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
f65e61c04bc28ffd6bda04619c84330b420450b5ahrens * Common Development and Distribution License (the "License").
f65e61c04bc28ffd6bda04619c84330b420450b5ahrens * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3f2366c2bb65e49f1b5900001844588089a7d7c4Gordon Ross * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
ae9727953cac4bd427aafd9f27458e401590bcb5Matthew Ahrens * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
aad02571bc59671aa3103bb070ae365f531b0b62Saso Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
810e43b2eb0e320833671a403fdda51917e8b036Bill Pijewski * Copyright (c) 2013, Joyent, Inc. All rights reserved.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensstatic boolean_t dbuf_undirty(dmu_buf_impl_t *db, dmu_tx_t *tx);
088f389458728c464569a5506b58070254fa4f7dahrensstatic void dbuf_write(dbuf_dirty_record_t *dr, arc_buf_t *data, dmu_tx_t *tx);
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbsextern inline void dmu_buf_init_user(dmu_buf_user_t *dbu,
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs#endif /* ! __lint */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Global data structures and functions for the dbuf cache.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * LRU cache of dbufs. The dbuf cache maintains a list of dbufs that
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * are not currently held but have been recently released. These dbufs
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * are not eligible for arc eviction until they are aged out of the cache.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Dbufs are added to the dbuf cache once the last hold is released. If a
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * dbuf is later accessed and still exists in the dbuf cache, then it will
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * be removed from the cache and later re-added to the head of the cache.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Dbufs that are aged out of the cache will be immediately destroyed and
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * become eligible for arc eviction.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilsonuint64_t dbuf_cache_max_bytes = 100 * 1024 * 1024;
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson/* Cap the size of the dbuf cache to log2 fraction of arc size. */
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The dbuf cache uses a three-stage eviction policy:
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * - A low water marker designates when the dbuf eviction thread
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * should stop evicting from the dbuf cache.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * - When we reach the maximum size (aka mid water mark), we
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * signal the eviction thread to run.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * - The high water mark indicates when the eviction thread
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * is unable to keep up with the incoming load and eviction must
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * happen in the context of the calling thread.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The dbuf cache:
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * low water mid water hi water
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * +----------------------------------------+----------+----------+
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * +----------------------------------------+----------+----------+
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * stop signal evict
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * evicting eviction directly
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The high and low water marks indicate the operating range for the eviction
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * thread. The low water mark is, by default, 90% of the total size of the
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * cache and the high water mark is at 110% (both of these percentages can be
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * changed by setting dbuf_cache_lowater_pct and dbuf_cache_hiwater_pct,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * respectively). The eviction thread will try to ensure that the cache remains
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * within this range by waking up every second and checking if the cache is
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * above the low water mark. The thread can also be woken up by callers adding
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * elements into the cache if the cache is larger than the mid water (i.e max
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * cache size). Once the eviction thread is woken up and eviction is required,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * it will continue evicting buffers until it's able to reduce the cache size
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * to the low water mark. If the cache size continues to grow and hits the high
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * water mark, then callers adding elments to the cache will begin to evict
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * directly from the cache until the cache is no longer above the high water
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The percentage above and below the maximum cache size.
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ASSERT(!multilist_link_active(&db->db_cache_link));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dbuf hash table routines
fa9e4066f08beec538e775443c5be79dd423fcabahrensdbuf_hash(void *os, uint64_t obj, uint8_t lvl, uint64_t blkid)
fa9e4066f08beec538e775443c5be79dd423fcabahrens crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (lvl)) & 0xFF];
fa9e4066f08beec538e775443c5be79dd423fcabahrens crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (osv >> 6)) & 0xFF];
fa9e4066f08beec538e775443c5be79dd423fcabahrens crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 0)) & 0xFF];
fa9e4066f08beec538e775443c5be79dd423fcabahrens crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (obj >> 8)) & 0xFF];
fa9e4066f08beec538e775443c5be79dd423fcabahrens crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (blkid >> 0)) & 0xFF];
fa9e4066f08beec538e775443c5be79dd423fcabahrens crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ (blkid >> 8)) & 0xFF];
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbsdbuf_find(objset_t *os, uint64_t obj, uint8_t level, uint64_t blkid)
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson uint64_t hv = dbuf_hash(os, obj, level, blkid);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (db = h->hash_table[idx]; db != NULL; db = db->db_hash_next) {
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbsdbuf_find_bonus(objset_t *os, uint64_t object)
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbs if (dnode_hold(os, object, FTAG, &dn) == 0) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Insert an entry into the hash table. If there is already an element
fa9e4066f08beec538e775443c5be79dd423fcabahrens * equal to elem in the hash table, then the already existing element
fa9e4066f08beec538e775443c5be79dd423fcabahrens * will be returned and the new element will not be inserted.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Otherwise returns NULL.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson uint64_t hv = dbuf_hash(os, obj, level, blkid);
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (dbf = h->hash_table[idx]; dbf != NULL; dbf = dbf->db_hash_next) {
bbfa8ea8bb4168c969ba27d632dfe0aeec3fc0daMatthew Ahrens * Remove an entry from the hash table. It must be in the EVICTING state.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson uint64_t hv = dbuf_hash(db->db_objset, db->db.db_object,
bbfa8ea8bb4168c969ba27d632dfe0aeec3fc0daMatthew Ahrens * We musn't hold db_mtx to maintain lock ordering:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * DBUF_HASH_MUTEX > db_mtx.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbstypedef enum {
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbsdbuf_verify_user(dmu_buf_impl_t *db, dbvu_verify_type_t verify_type)
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs /* Only data blocks support the attachment of user data. */
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs /* Clients must resolve a dbuf before attaching user data. */
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * Immediate eviction occurs when holds == dirtycnt.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * For normal eviction buffers, holds is zero on
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * eviction, except when dbuf_fix_old_data() calls
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * dbuf_clear_data(). However, the hold count can grow
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * during eviction even though db_mtx is held (see
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * dmu_bonus_hold() for an example), so we can only
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * test the generic invariant that holds >= dirtycnt.
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * There are two eviction callbacks - one that we call synchronously
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * and one that we invoke via a taskq. The async one is useful for
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * avoiding lock order reversals and limiting stack depth.
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * Note that if we have a sync callback but no async callback,
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * it's likely that the sync callback will free the structure
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * containing the dbu. In that case we need to take care to not
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek * dereference dbu after calling the sync evict func.
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek boolean_t has_async = (dbu->dbu_evict_func_async != NULL);
40510e8eba18690b9a9843b26393725eeb0f1dacJosef 'Jeff' Sipek taskq_dispatch_ent(dbu_evict_taskq, dbu->dbu_evict_func_async,
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden is_metadata = DMU_OT_IS_METADATA(DB_DNODE(db)->dn_type);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * This function *must* return indices evenly distributed between all
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * sublists of the multilist. This is needed due to how the dbuf eviction
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * code is laid out; dbuf_evict_thread() assumes dbufs are evenly
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * distributed between all sublists and uses this assumption when
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * deciding which sublist to evict from and how much to evict from it.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilsondbuf_cache_multilist_index_func(multilist_t *ml, void *obj)
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The assumption here, is the hash value for a given
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * dmu_buf_impl_t will remain constant throughout it's lifetime
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * (i.e. it's objset, object, level and blkid fields don't change).
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Thus, we don't need to store the dbuf's sublist index
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * on insertion, as this index can be recalculated on removal.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Also, the low order bits of the hash value are thought to be
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * distributed evenly. Otherwise, in the case that the multilist
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * has a power of two number of sublists, each sublists' usage
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * would not be evenly distributed.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson return (dbuf_hash(db->db_objset, db->db.db_object,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson (dbuf_cache_max_bytes * dbuf_cache_hiwater_pct) / 100;
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dbuf_cache_max_bytes + dbuf_cache_hiwater_bytes);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson (dbuf_cache_max_bytes * dbuf_cache_lowater_pct) / 100;
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dbuf_cache_max_bytes - dbuf_cache_lowater_bytes);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Evict the oldest eligible dbuf from the dbuf cache.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson int idx = multilist_get_random_index(&dbuf_cache);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson multilist_sublist_t *mls = multilist_sublist_lock(&dbuf_cache, idx);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Set the thread's tsd to indicate that it's processing evictions.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Once a thread stops evicting from the dbuf cache it will
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * reset its tsd to NULL.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ASSERT3P(tsd_get(zfs_dbuf_evict_key), ==, NULL);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson (void) tsd_set(zfs_dbuf_evict_key, (void *)B_TRUE);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dmu_buf_impl_t *db = multilist_sublist_tail(mls);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson while (db != NULL && mutex_tryenter(&db->db_mtx) == 0) {
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson DTRACE_PROBE2(dbuf__evict__one, dmu_buf_impl_t *, db,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The dbuf evict thread is responsible for aging out dbufs from the
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * cache. Once the cache has reached it's maximum size, dbufs are removed
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * and destroyed. The eviction thread will continue running until the size
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * of the dbuf cache is at or below the maximum size. Once the dbuf is aged
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * out of the cache it is destroyed and becomes eligible for arc eviction.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson CALLB_CPR_INIT(&cpr, &dbuf_evict_lock, callb_generic_cpr, FTAG);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson while (!dbuf_cache_above_lowater() && !dbuf_evict_thread_exit) {
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson &dbuf_evict_lock, SEC2NSEC(1), MSEC2NSEC(1), 0);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Keep evicting as long as we're above the low water mark
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * for the cache. We do this without holding the locks to
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * minimize lock contention.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson while (dbuf_cache_above_lowater() && !dbuf_evict_thread_exit) {
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson CALLB_CPR_EXIT(&cpr); /* drops dbuf_evict_lock */
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Wake up the dbuf eviction thread if the dbuf cache is at its max size.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * If the dbuf cache is at its high water mark, then evict a dbuf from the
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * dbuf cache using the callers context.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * We use thread specific data to track when a thread has
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * started processing evictions. This allows us to avoid deeply
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * nested stacks that would have a call flow similar to this:
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * dbuf_rele()-->dbuf_rele_and_unlock()-->dbuf_evict_notify()
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * +-----dbuf_destroy()<--dbuf_evict_one()<--------+
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The dbuf_eviction_thread will always have its tsd set until
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * that thread exits. All other threads will only set their tsd
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * if they are participating in the eviction process. This only
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * happens if the eviction thread is unable to process evictions
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * fast enough. To keep the dbuf cache size in check, other threads
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * can evict from the dbuf cache directly. Those threads will set
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * their tsd values so that we ensure that they only evict one dbuf
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * from the dbuf cache.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson if (refcount_count(&dbuf_cache_size) > dbuf_cache_max_bytes) {
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson if (refcount_count(&dbuf_cache_size) > dbuf_cache_max_bytes) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The hash table is big enough to fill all of physical memory
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * with an average 4K block size. The table will take up
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * totalmem*sizeof(void*)/4K (i.e. 2MB/GB with 8-byte pointers).
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock h->hash_table = kmem_zalloc(hsize * sizeof (void *), KM_NOSLEEP);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock /* XXX - we should really return an error instead of assert */
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dbuf_kmem_cache = kmem_cache_create("dmu_buf_impl_t",
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < DBUF_MUTEXES; i++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens mutex_init(&h->hash_mutexes[i], NULL, MUTEX_DEFAULT, NULL);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Setup the parameters for the dbuf cache. We cap the size of the
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * dbuf cache to 1/32nd (default) of the size of the ARC.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dbuf_cache_max_bytes = MIN(dbuf_cache_max_bytes,
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * All entries are queued via taskq_dispatch_ent(), so min/maxalloc
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs * configuration is not required.
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs dbu_evict_taskq = taskq_create("dbu_evict", 1, minclsyspri, 0, 0, 0);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson multilist_create(&dbuf_cache, sizeof (dmu_buf_impl_t),
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson mutex_init(&dbuf_evict_lock, NULL, MUTEX_DEFAULT, NULL);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson cv_init(&dbuf_evict_cv, NULL, CV_DEFAULT, NULL);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dbuf_cache_evict_thread = thread_create(NULL, 0, dbuf_evict_thread,
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i = 0; i < DBUF_MUTEXES; i++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(h->hash_table, (h->hash_table_mask + 1) * sizeof (void *));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Other stuff.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum ASSERT3U(db->db.db_offset, ==, DMU_BONUS_BLKID);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum } else if (db->db_blkid == DMU_SPILL_BLKID) {
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum ASSERT3U(db->db.db_size, >=, dn->dn_bonuslen);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT3U(db->db.db_offset, ==, db->db_blkid * db->db.db_size);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick for (dr = db->db_data_pending; dr != NULL; dr = dr->dr_next)
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick for (dr = db->db_last_dirty; dr != NULL; dr = dr->dr_next)
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * We can't assert that db_size matches dn_datablksz because it
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * can be momentarily different when another thread is doing
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * dnode_set_blksz().
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens if (db->db_level == 0 && db->db.db_object == DMU_META_DNODE_OBJECT) {
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * It should only be modified in syncing context, so
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens * make sure we only have one copy of the data.
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens ASSERT(dr == NULL || dr->dt.dl.dr_data == db->db_buf);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* verify db->db_blkptr */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* db is pointed to by the dnode */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* ASSERT3U(db->db_blkid, <, dn->dn_nblkptr); */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* db is pointed to by an indirect block */
fa9e4066f08beec538e775443c5be79dd423fcabahrens int epb = db->db_parent->db.db_size >> SPA_BLKPTRSHIFT;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT3U(db->db_parent->db_level, ==, db->db_level+1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dnode_grow_indblksz() can make this fail if we don't
fa9e4066f08beec538e775443c5be79dd423fcabahrens * have the struct_rwlock. XXX indblksz no longer
fa9e4066f08beec538e775443c5be79dd423fcabahrens * grows. safe to do this now?
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((db->db_blkptr == NULL || BP_IS_HOLE(db->db_blkptr)) &&
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum db->db.db_data && db->db_blkid != DMU_BONUS_BLKID &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If the blkptr isn't set but they have nonzero data,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * it had better be dirty, otherwise we'll lose that
fa9e4066f08beec538e775443c5be79dd423fcabahrens * data when we evict this buffer.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * There is an exception to this rule for indirect blocks; in
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * this case, if the indirect block is a hole, we fill in a few
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * fields on each of the child blocks (importantly, birth time)
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * to prevent hole birth times from being lost when you
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * partially fill in a hole.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie ASSERT3U(1 << DB_DNODE(db)->dn_indblkshift, ==,
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * We want to verify that all the blkptrs in the
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * indirect block are holes, but we may have
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * automatically set up a few fields for them.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * We iterate through each blkptr and verify
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * they only have those fields set.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie for (int i = 0;
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States * Loan out an arc_buf for read. Return the loaned arc_buf.
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United Statesarc_buf_t *
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United Statesdbuf_loan_arcbuf(dmu_buf_impl_t *db)
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States arc_buf_t *abuf;
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States mutex_enter(&db->db_mtx);
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States if (arc_released(db->db_buf) || refcount_count(&db->db_holds) > 1) {
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States int blksz = db->db.db_size;
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States mutex_exit(&db->db_mtx);
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States bcopy(db->db.db_data, abuf->b_data, blksz);
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States } else {
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States abuf = db->db_buf;
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States arc_loan_inuse_buf(abuf, db);
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States mutex_exit(&db->db_mtx);
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States return (abuf);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Calculate which level n block references the data at the level 0 offset
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedbuf_whichblock(dnode_t *dn, int64_t level, uint64_t offset)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dn->dn_datablkshift != 0 && dn->dn_indblkshift != 0) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * The level n blkid is equal to the level 0 blkid divided by
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * the number of level 0s in a level n block.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * The level 0 blkid is offset >> datablkshift =
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * offset / 2^datablkshift.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * The number of level 0s in a level n is the number of block
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * pointers in an indirect block, raised to the power of level.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * This is 2^(indblkshift - SPA_BLKPTRSHIFT)^level =
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * 2^(level*(indblkshift - SPA_BLKPTRSHIFT)).
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Thus, the level n blkid is: offset /
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * ((2^datablkshift)*(2^(level*(indblkshift - SPA_BLKPTRSHIFT)))
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * = offset / 2^(datablkshift + level *
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * (indblkshift - SPA_BLKPTRSHIFT))
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * = offset >> (datablkshift + level *
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * (indblkshift - SPA_BLKPTRSHIFT))
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie return (offset >> (dn->dn_datablkshift + level *
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * All reads are synchronous, so we must have a hold on the dbuf
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* we were freed in flight; disregard any error */
cf6106c8a0d6598b045811f9650d66e07eb332afMatthew Ahrensdbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* We need the struct_rwlock to prevent db_blkptr from changing. */
cf04dda189f8e7f1d3245be8e387757e07c78e66Mark Maybee int bonuslen = MIN(dn->dn_bonuslen, dn->dn_phys->dn_bonuslen);
5a98e54b3632348add05cdbf50bbf52e1b839c10Brendan Gregg - Sun Microsystems arc_space_consume(DN_MAX_BONUSLEN, ARC_SPACE_OTHER);
cf04dda189f8e7f1d3245be8e387757e07c78e66Mark Maybee bcopy(DN_BONUS(dn->dn_phys), db->db.db_data, bonuslen);
1c8564a7573482b45fcc6f9bc0c2de70f92c193cMark Maybee * Recheck BP_IS_HOLE() after dnode_block_freed() in case dnode_sync()
1c8564a7573482b45fcc6f9bc0c2de70f92c193cMark Maybee * processes the delete record and clears the bp while we are waiting
1c8564a7573482b45fcc6f9bc0c2de70f92c193cMark Maybee * for the dn_mtx (resulting in a "no" from block_freed).
088f389458728c464569a5506b58070254fa4f7dahrens if (db->db_blkptr == NULL || BP_IS_HOLE(db->db_blkptr) ||
1c8564a7573482b45fcc6f9bc0c2de70f92c193cMark Maybee (db->db_level == 0 && (dnode_block_freed(dn, db->db_blkid) ||
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dbuf_set_data(db, arc_alloc_buf(db->db_objset->os_spa, db, type,
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie if (db->db_blkptr != NULL && db->db_level > 0 &&
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie for (int i = 0; i < ((1 <<
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie DB_DNODE(db)->dn_indblkshift) / sizeof (blkptr_t));
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie BP_SET_BIRTH(bp, db->db_blkptr->blk_birth, 0);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick SET_BOOKMARK(&zb, db->db_objset->os_dsl_dataset ?
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick db->db_objset->os_dsl_dataset->ds_object : DMU_META_OBJSET,
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman (void) arc_read(zio, db->db_objset->os_spa, db->db_blkptr,
cf6106c8a0d6598b045811f9650d66e07eb332afMatthew Ahrens (flags & DB_RF_CANFAIL) ? ZIO_FLAG_CANFAIL : ZIO_FLAG_MUSTSUCCEED,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * This is our just-in-time copy function. It makes a copy of buffers that
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * have been modified in a previous transaction group before we access them in
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * the current active group.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * This function is used in three places: when we are dirtying a buffer for the
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * first time in a txg, when we are freeing a range in a dnode that includes
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * this buffer, and when we are accessing a buffer which was received compressed
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * and later referenced in a WRITE_BYREF record.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * Note that when we are called from dbuf_free_range() we do not put a hold on
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * the buffer, we just traverse the active dbuf list for the dnode.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmeldbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel ASSERT(db->db.db_object != DMU_META_DNODE_OBJECT);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel ((db->db_blkid == DMU_BONUS_BLKID) ? db->db.db_data : db->db_buf)))
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * If the last dirty record for this dbuf has not yet synced
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * and its referencing the dbuf data, either:
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * reset the reference to point to a new copy,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * or (if there a no active holders)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * just null out the current db_data pointer.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel /* Note that the data bufs here are zio_bufs */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dr->dt.dl.dr_data = zio_buf_alloc(DN_MAX_BONUSLEN);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel arc_space_consume(DN_MAX_BONUSLEN, ARC_SPACE_OTHER);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel bcopy(db->db.db_data, dr->dt.dl.dr_data, DN_MAX_BONUSLEN);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel } else if (refcount_count(&db->db_holds) > db->db_dirtycnt) {
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dr->dt.dl.dr_data = arc_alloc_buf(spa, db, type, size);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dr->dt.dl.dr_data = arc_alloc_compressed_buf(spa, db,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel bcopy(db->db.db_data, dr->dt.dl.dr_data->b_data, size);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockdbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We don't have to hold the mutex to check db_state because it
fa9e4066f08beec538e775443c5be79dd423fcabahrens * can't be freed while we have a hold on the buffer.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum prefetch = db->db_level == 0 && db->db_blkid != DMU_BONUS_BLKID &&
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson (flags & DB_RF_NOPREFETCH) == 0 && dn != NULL &&
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * If the arc buf is compressed, we need to decompress it to
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * read the data. This could happen during the "zfs receive" of
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel * a stream which is compressed and deduplicated.
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel arc_get_compression(db->db_buf) != ZIO_COMPRESS_OFF) {
cb92f4130ce5b2c4ae1fa5fa6c776f4d4dc28ad9Alexander Motin dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson zio = zio_root(spa, NULL, NULL, ZIO_FLAG_CANFAIL);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock /* dbuf_read_impl has dropped db_mtx for us */
cb92f4130ce5b2c4ae1fa5fa6c776f4d4dc28ad9Alexander Motin dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * Another reader came in while the dbuf was in flight
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * between UNCACHED and CACHED. Either a writer will finish
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * writing the buffer (sending the dbuf to CACHED) or the
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * first reader's request will reach the read_done callback
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * and send the dbuf to CACHED. Otherwise, a failure
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * occurred and the dbuf went to UNCACHED.
cb92f4130ce5b2c4ae1fa5fa6c776f4d4dc28ad9Alexander Motin dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Skip the wait per the caller's request. */
f6164ad638e7346c4ae4ba393760a897cf6eb744Adam H. Leventhal DTRACE_PROBE2(blocked__read, dmu_buf_impl_t *,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ASSERT(err || havepzio || db->db_state == DB_CACHED);
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (db->db_state == DB_READ || db->db_state == DB_FILL)
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dbuf_set_data(db, arc_alloc_buf(spa, db, type, db->db.db_size));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee ASSERT(dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /* free this block */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * Release the already-written buffer, so we leave it in
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * a consistent dirty state. Note that all callers are
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * modifying the buffer, so they will immediately do
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * another (redundant) arc_release(). Therefore, leave
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * the buf thawed to save the effort of freezing &
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * immediately re-thawing it.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * Evict (if its unreferenced) or clear (if its referenced) any level-0
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee * data blocks in the free range, so that any future readers will find
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman * empty blocks.
0f6d88aded0d165f5954688a9b13bac76c38da84Alex Reecedbuf_free_range(dnode_t *dn, uint64_t start_blkid, uint64_t end_blkid,
653af1b809998570c7e89fe7a0d3f90992bf0216Stephen Blinick !(start_blkid == DMU_SPILL_BLKID || end_blkid == DMU_SPILL_BLKID))
0f6d88aded0d165f5954688a9b13bac76c38da84Alex Reece dprintf_dnode(dn, "start=%llu end=%llu\n", start_blkid, end_blkid);
0f6d88aded0d165f5954688a9b13bac76c38da84Alex Reece db = avl_find(&dn->dn_dbufs, &db_search, &where);
0f6d88aded0d165f5954688a9b13bac76c38da84Alex Reece db = avl_nearest(&dn->dn_dbufs, where, AVL_AFTER);
0f6d88aded0d165f5954688a9b13bac76c38da84Alex Reece if (db->db_level != 0 || db->db_blkid > end_blkid) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* found a level 0 buffer in the range */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* mutex has been dropped and dbuf destroyed */
c543ec060d1359f6c8a9507242521f344a2ac3efahrens if (db->db_state == DB_READ || db->db_state == DB_FILL) {
c543ec060d1359f6c8a9507242521f344a2ac3efahrens /* will be handled in dbuf_read_done or dbuf_rele */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /* The dbuf is referenced */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * This buffer is "in-use", re-adjust the file
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * size to reflect that this buffer may
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * contain new data when we sync.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * This dbuf is not dirty in the open context.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * Either uncache it (if its not referenced in
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * the open context) or reset its contents to
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /* clear the contents if its cached */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We don't need any locking to protect db_blkptr:
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * If it's syncing, then db_last_dirty will be set
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * so we'll ignore db_blkptr.
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman * This logic ensures that only block births for
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman * filled blocks are considered.
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman if (db->db_last_dirty && (db->db_blkptr == NULL ||
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman } else if (db->db_blkptr != NULL && !BP_IS_HOLE(db->db_blkptr)) {
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman * If this block don't exist or is in a snapshot, it can't be freed.
837b568b3a2559f8c9b9403f95104271a85d129eGeorge Wilson * Don't pass the bp to dsl_dataset_block_freeable() since we
837b568b3a2559f8c9b9403f95104271a85d129eGeorge Wilson * are holding the db_mtx lock and might deadlock if we are
837b568b3a2559f8c9b9403f95104271a85d129eGeorge Wilson * prefetching a dedup-ed block.
837b568b3a2559f8c9b9403f95104271a85d129eGeorge Wilson dsl_dataset_block_freeable(ds, NULL, birth_txg));
fa9e4066f08beec538e775443c5be79dd423fcabahrensdbuf_new_size(dmu_buf_impl_t *db, int size, dmu_tx_t *tx)
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXX does *this* func really need the lock? */
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman * This call to dmu_buf_will_dirty() with the dn_struct_rwlock held
fa9e4066f08beec538e775443c5be79dd423fcabahrens * is OK, because there can be no other references to the db
fa9e4066f08beec538e775443c5be79dd423fcabahrens * when we are changing its size, so no concurrent DB_FILL can
fa9e4066f08beec538e775443c5be79dd423fcabahrens * be happening.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * XXX we should be doing a dbuf_read, checking the return
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * value and returning that up to our callers
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the data buffer for the new block */
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel buf = arc_alloc_buf(dn->dn_objset->os_spa, db, type, size);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* copy old block data to the new block */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* zero the remainder */
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling ASSERT(dsl_pool_sync_context(dmu_objset_pool(os)));
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling list_link_active(&os->os_dsl_dataset->ds_synced_link));
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling ASSERT(db->db_parent == NULL || arc_released(db->db_parent->db_buf));
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * We already have a dirty record for this TXG, and we are being
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * dirtied again.
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens if (db->db_level == 0 && db->db_blkid != DMU_BONUS_BLKID) {
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * If this buffer has already been written out,
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * we now need to reset its state.
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens if (db->db.db_object != DMU_META_DNODE_OBJECT &&
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens /* Already released on initial dirty, so just thaw. */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Shouldn't dirty a regular buffer in syncing context. Private
fa9e4066f08beec538e775443c5be79dd423fcabahrens * objects may be dirtied in syncing context, but only if they
fa9e4066f08beec538e775443c5be79dd423fcabahrens * were already pre-dirtied in open context.
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&dn->dn_objset->os_dsl_dataset->ds_bp_rwlock,
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_exit(&dn->dn_objset->os_dsl_dataset->ds_bp_rwlock, FTAG);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We make this assert for private objects as well, but after we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * check if we're already dirty. They are allowed to re-dirty
fa9e4066f08beec538e775443c5be79dd423fcabahrens * in syncing context.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dn->dn_dirtyctx == DN_UNDIRTIED || dn->dn_dirtyctx ==
fa9e4066f08beec538e775443c5be79dd423fcabahrens (dmu_tx_is_syncing(tx) ? DN_DIRTY_SYNC : DN_DIRTY_OPEN));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * XXX make this true for indirects too? The problem is that
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * transactions created with dmu_tx_create_assigned() from
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * syncing context don't bother holding ahead.
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley db->db_state == DB_CACHED || db->db_state == DB_FILL ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Don't set dirtyctx to SYNC if we're just modifying this as we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * initialize the objset.
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&dn->dn_objset->os_dsl_dataset->ds_bp_rwlock,
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie dn->dn_dirtyctx_firstset = kmem_alloc(1, KM_SLEEP);
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_exit(&dn->dn_objset->os_dsl_dataset->ds_bp_rwlock,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this buffer is already dirty, we're done.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee ASSERT(*drp == NULL || (*drp)->dr_txg <= tx->tx_txg ||
7e2186e374a893aab8d2301cc2b65032f7b0d51dbonwick while ((dr = *drp) != NULL && dr->dr_txg > tx->tx_txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Only valid if not already dirty.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens dn->dn_dirtyctx == DN_UNDIRTIED || dn->dn_dirtyctx ==
fa9e4066f08beec538e775443c5be79dd423fcabahrens (dmu_tx_is_syncing(tx) ? DN_DIRTY_SYNC : DN_DIRTY_OPEN));
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT((dn->dn_phys->dn_nlevels == 0 && db->db_level == 0) ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens dn->dn_next_nlevels[(tx->tx_txg-1) & TXG_MASK] > db->db_level ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens dn->dn_next_nlevels[(tx->tx_txg-2) & TXG_MASK] > db->db_level);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We should only be dirtying in syncing context if it's the
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * mos or we're initializing the os or it's a special object.
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * However, we are allowed to dirty in syncing context provided
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * we already dirtied it in open context. Hence we must make
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens * this assertion only if we're not already dirty.
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&os->os_dsl_dataset->ds_bp_rwlock, RW_READER, FTAG);
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens ASSERT(!dmu_tx_is_syncing(tx) || DMU_OBJECT_IS_SPECIAL(dn->dn_object) ||
148434217c040ea38dc844384f6ba68d9b325906Matthew Ahrens os->os_dsl_dataset == NULL || BP_IS_HOLE(os->os_rootbp));
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_exit(&os->os_dsl_dataset->ds_bp_rwlock, FTAG);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf_dbuf(db, "size=%llx\n", (u_longlong_t)db->db.db_size);
1934e92fc930c49429ad71a8ca97340f33227e78maybee * Update the accounting.
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * Note: we delay "free accounting" until after we drop
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * the db_mtx. This keeps us from grabbing other locks
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * (and possibly deadlocking) in bp_get_dsize() while
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * also holding the db_mtx.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * If this buffer is dirty in an old transaction group we need
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * to make a copy of it so that the changes we make in this
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * transaction group won't leak out when we sync the older txg.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dr = kmem_zalloc(sizeof (dbuf_dirty_record_t), KM_SLEEP);
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley } else if (db->db.db_object != DMU_META_DNODE_OBJECT) {
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley * Release the data buffer from the cache so
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley * that we can modify it without impacting
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley * possible other users of this cached data
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley * block. Note that indirect blocks and
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley * private objects are not released until the
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley * syncing state (since they are only modified
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee mutex_init(&dr->dt.di.dr_mtx, NULL, MUTEX_DEFAULT, NULL);
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens if (db->db_blkid != DMU_BONUS_BLKID && os->os_dsl_dataset != NULL)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * We could have been freed_in_flight between the dbuf_noread
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and dbuf_dirty. We win, as though the dbuf_noread() had
fa9e4066f08beec538e775443c5be79dd423fcabahrens * happened after the free.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (db->db_level == 0 && db->db_blkid != DMU_BONUS_BLKID &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This buffer is now part of this txg
926549256b71acd595f69b236779ff6b78fa08efMatthew Ahrens * The dn_struct_rwlock prevents db_blkptr from changing
926549256b71acd595f69b236779ff6b78fa08efMatthew Ahrens * due to a write from syncing context completing
926549256b71acd595f69b236779ff6b78fa08efMatthew Ahrens * while we are running, so we want to acquire it before
926549256b71acd595f69b236779ff6b78fa08efMatthew Ahrens * looking at db_blkptr.
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * This is only a guess -- if the dbuf is dirty
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * in a previous txg, we don't know how much
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * space it will use on disk yet. We should
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * really have the struct_rwlock to access
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * db_blkptr, but since this is just a guess,
d3469faae6c34118ddaebbde0e49b8b4c7bc420cMark Maybee * it's OK if we get an odd answer.
8346f03fb3b709a113891e0aec5f1f8d45f8e758Jonathan W Adams dnode_new_blkid(dn, db->db_blkid, tx, drop_struct_lock);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (db->db_parent == NULL || db->db_parent == dn->dn_dbuf) {
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * Since we've dropped the mutex, it's possible that
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * dbuf_undirty() might have changed this out from under us.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson ASSERT(db->db_parent == NULL || db->db_parent == dn->dn_dbuf);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * Undirty a buffer in the transaction group referenced by the given
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * transaction. Return whether this evicted the dbuf.
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens * Due to our use of dn_nlevels below, this can only be called
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens * in open context, unless we are operating on the MOS.
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens * From syncing context, dn_nlevels may be different from the
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens * dn_nlevels used when dbuf was dirtied.
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens dmu_objset_pool(db->db_objset)->dp_meta_objset ||
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens txg != spa_syncing_txg(dmu_objset_spa(db->db_objset)));
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If this buffer is not dirty, we're done.
17f17c2df4ca603e787c5fc03b7af83519edfd2cbonwick for (drp = &db->db_last_dirty; (dr = *drp) != NULL; drp = &dr->dr_next)
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf_dbuf(db, "size=%llx\n", (u_longlong_t)db->db.db_size);
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens dsl_pool_undirty_space(dmu_objset_pool(dn->dn_objset),
3f2366c2bb65e49f1b5900001844588089a7d7c4Gordon Ross * Note that there are three places in dbuf_dirty()
3f2366c2bb65e49f1b5900001844588089a7d7c4Gordon Ross * where this dirty record may be put on a list.
3f2366c2bb65e49f1b5900001844588089a7d7c4Gordon Ross * Make sure to do a list_remove corresponding to
3f2366c2bb65e49f1b5900001844588089a7d7c4Gordon Ross * every one of those list_insert calls.
cdb0ab79ea1af7b8fc339a04d4bf7426dc77ec4emaybee ASSERT(db->db_blkptr == NULL || db->db_parent == dn->dn_dbuf);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee list_remove(&dn->dn_dirty_records[txg & TXG_MASK], dr);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee if (refcount_remove(&db->db_holds, (void *)(uintptr_t)txg) == 0) {
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ASSERT(db->db_state == DB_NOFILL || arc_released(db->db_buf));
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossmandmu_buf_will_dirty(dmu_buf_t *db_fake, dmu_tx_t *tx)
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * Quick check for dirtyness. For already dirty blocks, this
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * reduces runtime of this function by >90%, and overall performance
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * by 50% for some workloads (e.g. file deletion with indirect blocks
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens dr != NULL && dr->dr_txg >= tx->tx_txg; dr = dr->dr_next) {
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * It's possible that it is already dirty but not cached,
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * because there are some calls to dbuf_dirty() that don't
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens * go through dmu_buf_will_dirty().
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens if (dr->dr_txg == tx->tx_txg && db->db_state == DB_CACHED) {
0f2e7d03b8f588387cb8dd8dd500cbe5ff4484e0Matthew Ahrens /* This dbuf is already dirty and cached. */
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson if (RW_WRITE_HELD(&DB_DNODE(db)->dn_struct_rwlock))
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haleydmu_buf_will_not_fill(dmu_buf_t *db_fake, dmu_tx_t *tx)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ASSERT(db->db.db_object != DMU_META_DNODE_OBJECT ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* we were freed while filling */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* XXX dbuf_undirty? */
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrensdmu_buf_write_embedded(dmu_buf_t *dbuf, void *data,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens bp_embedded_type_t etype, enum zio_compress comp,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens int uncompressed_size, int compressed_size, int byteorder,
ca0cc3918a1789fa839194af2a9245f801a06b1aMatthew Ahrens ASSERT(spa_feature_is_active(dmu_objset_spa(db->db_objset),
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens ASSERT3U(db->db_last_dirty->dr_txg, ==, tx->tx_txg);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens encode_embedded_bp_compressed(&dl->dr_overridden_by,
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens data, comp, uncompressed_size, compressed_size);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens BP_SET_BYTEORDER(&dl->dr_overridden_by, byteorder);
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens dl->dr_overridden_by.blk_birth = db->db_last_dirty->dr_txg;
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy * Directly assign a provided arc buf to a given dbuf if it's not referenced
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy * by anybody except our caller. Otherwise copy arcbuf's contents to dbuf.
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiydbuf_assign_arcbuf(dmu_buf_impl_t *db, arc_buf_t *buf, dmu_tx_t *tx)
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy ASSERT(!refcount_is_zero(&db->db_holds));
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel ASSERT3U(dbuf_is_metadata(db), ==, arc_is_metadata(buf));
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy while (db->db_state == DB_READ || db->db_state == DB_FILL)
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy ASSERT(db->db_state == DB_CACHED || db->db_state == DB_UNCACHED);
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy refcount_count(&db->db_holds) - 1 > db->db_dirtycnt) {
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy bcopy(buf->b_data, db->db.db_data, db->db.db_size);
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States xuio_stat_wbuf_copied();
c242f9a02a2ef021449275ae0a1d2581ee77231dchunli zhang - Sun Microsystems - Irvine United States xuio_stat_wbuf_nocopy();
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy dbuf_dirty_record_t *dr = db->db_last_dirty;
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy if (dr != NULL && dr->dr_txg == tx->tx_txg) {
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy ASSERT(dr->dt.dl.dr_data == db->db_buf);
2fdbea25c2ba89186b8a6b7c6840ebc9f4dff245Aleksandr Guzovskiy } else if (dr == NULL || dr->dt.dl.dr_data != db->db_buf) {
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson zio_buf_free(db->db.db_data, DN_MAX_BONUSLEN);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson arc_space_return(DN_MAX_BONUSLEN, ARC_SPACE_OTHER);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson if (multilist_link_active(&db->db_cache_link)) {
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley ASSERT(db->db_state == DB_UNCACHED || db->db_state == DB_NOFILL);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * Now that db_state is DB_EVICTING, nobody else can find this via
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * the hash table. We can now drop db_mtx, which allows us to
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * acquire the dn_dbufs_mtx.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson boolean_t needlock = !MUTEX_HELD(&dn->dn_dbufs_mtx);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Decrementing the dbuf count means that the hold corresponding
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * to the removed dbuf is no longer discounted in dnode_move(),
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * so the dnode cannot be moved until after we release the hold.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * The membar_producer() ensures visibility of the decremented
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * value in dnode_move(), since DB_DNODE_EXIT doesn't actually
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * release any lock.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ASSERT(!multilist_link_active(&db->db_cache_link));
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson arc_space_return(sizeof (dmu_buf_impl_t), ARC_SPACE_OTHER);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * If this dbuf is referenced from an indirect dbuf,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * decrement the ref count on the indirect dbuf.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Note: While bpp will always be updated if the function returns success,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * parentp will not be updated if the dnode does not have dn_dbuf filled in;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * this happens when the dnode is the meta-dnode, or a userused or groupused
fa9e4066f08beec538e775443c5be79dd423fcabahrensdbuf_findbp(dnode_t *dn, int level, uint64_t blkid, int fail_sparse,
06e0070d70ba2ee95f5aa2645423eb2cf1546788Mark Shellenbaum (dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR))
fa9e4066f08beec538e775443c5be79dd423fcabahrens (blkid > (dn->dn_phys->dn_maxblkid >> (level * epbs)))) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* the buffer has no parent yet */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* this block is referenced from an indirect block */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie blkid >> epbs, fail_sparse, FALSE, NULL, parentp);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock (DB_RF_HAVESTRUCT | DB_RF_NOPREFETCH | DB_RF_CANFAIL));
c543ec060d1359f6c8a9507242521f344a2ac3efahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* the block is referenced from the dnode */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrensdbuf_create(dnode_t *dn, uint8_t level, uint64_t blkid,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson db = kmem_cache_alloc(dbuf_kmem_cache, KM_SLEEP);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock /* the bonus dbuf is not placed in the hash table */
5a98e54b3632348add05cdbf50bbf52e1b839c10Brendan Gregg - Sun Microsystems arc_space_consume(sizeof (dmu_buf_impl_t), ARC_SPACE_OTHER);
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens db->db_level ? 1 << dn->dn_indblkshift : dn->dn_datablksz;
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Hold the dn_dbufs_mtx while we get the new dbuf
fa9e4066f08beec538e775443c5be79dd423fcabahrens * in the hash table *and* added to the dbufs list.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This prevents a possible deadlock with someone
fa9e4066f08beec538e775443c5be79dd423fcabahrens * trying to look up this dbuf before its added to the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * dn_dbufs list.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* someone else inserted it first */
5a98e54b3632348add05cdbf50bbf52e1b839c10Brendan Gregg - Sun Microsystems arc_space_consume(sizeof (dmu_buf_impl_t), ARC_SPACE_OTHER);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie spa_t *dpa_spa; /* The spa to issue the prefetch in. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie zbookmark_phys_t dpa_zb; /* The target block to prefetch. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie int dpa_epbs; /* Entries (blkptr_t's) Per Block Shift. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie int dpa_curlevel; /* The current level that we're reading */
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dnode_t *dpa_dnode; /* The dnode associated with the prefetch */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie zio_priority_t dpa_prio; /* The priority I/Os should be issued at. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie zio_t *dpa_zio; /* The parent zio_t for all prefetches. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie arc_flags_t dpa_aflags; /* Flags to pass to the final prefetch. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Actually issue the prefetch read for the block given.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedbuf_issue_final_prefetch(dbuf_prefetch_arg_t *dpa, blkptr_t *bp)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dpa->dpa_aflags | ARC_FLAG_NOWAIT | ARC_FLAG_PREFETCH;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3U(dpa->dpa_curlevel, ==, BP_GET_LEVEL(bp));
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3U(dpa->dpa_curlevel, ==, dpa->dpa_zb.zb_level);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (void) arc_read(dpa->dpa_zio, dpa->dpa_spa, bp, NULL, NULL,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dpa->dpa_prio, ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Called when an indirect block above our prefetch target is read in. This
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * will either read in the next indirect block down the tree or issue the actual
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * prefetch if the next block down is our target.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedbuf_prefetch_indirect_done(zio_t *zio, arc_buf_t *abuf, void *private)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3S(dpa->dpa_zb.zb_level, <, dpa->dpa_curlevel);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * The dpa_dnode is only valid if we are called with a NULL
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * zio. This indicates that the arc_read() returned without
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * first calling zio_read() to issue a physical read. Once
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * a physical read is made the dpa_dnode must be invalidated
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * as the locks guarding it may have been dropped. If the
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * dpa_dnode is still valid, then we want to add it to the dbuf
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * cache. To do so, we must hold the dbuf associated with the block
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * we just prefetched, read its contents so that we associate it
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson * with an arc_buf_t, and then release it.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3S(BP_GET_LEVEL(zio->io_bp), ==, dpa->dpa_curlevel);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ASSERT3U(BP_GET_PSIZE(zio->io_bp), ==, zio->io_size);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson ASSERT3U(BP_GET_LSIZE(zio->io_bp), ==, zio->io_size);
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson dmu_buf_impl_t *db = dbuf_hold_level(dpa->dpa_dnode,
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson DB_RF_MUST_SUCCEED | DB_RF_NOPREFETCH | DB_RF_HAVESTRUCT);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie (dpa->dpa_epbs * (dpa->dpa_curlevel - dpa->dpa_zb.zb_level));
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (BP_IS_HOLE(bp) || (zio != NULL && zio->io_error != 0)) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie } else if (dpa->dpa_curlevel == dpa->dpa_zb.zb_level) {
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3U(nextblkid, ==, dpa->dpa_zb.zb_blkid);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3U(dpa->dpa_curlevel, ==, BP_GET_LEVEL(bp));
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dpa->dpa_zb.zb_object, dpa->dpa_curlevel, nextblkid);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie bp, dbuf_prefetch_indirect_done, dpa, dpa->dpa_prio,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Issue prefetch reads for the given block on the given level. If the indirect
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * blocks above that block are not in memory, we will read them in
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * asynchronously. As a result, this call never blocks waiting for a read to
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedbuf_prefetch(dnode_t *dn, int64_t level, uint64_t blkid, zio_priority_t prio,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * This dnode hasn't been written to disk yet, so there's nothing to
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (level >= nlevels || dn->dn_phys->dn_nblkptr == 0)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dn->dn_phys->dn_maxblkid < blkid << (epbs * level))
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dmu_buf_impl_t *db = dbuf_find(dn->dn_objset, dn->dn_object,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * This dbuf already exists. It is either CACHED, or
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * (we assume) about to be read or filled.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Find the closest ancestor (indirect block) of the target block
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * that is present in the cache. In this indirect block, we will
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * find the bp that is at curlevel, curblkid.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (dbuf_hold_impl(dn, parent_level, parent_blkid,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie /* No cached indirect blocks found. */
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie ASSERT3U(curblkid, <, dn->dn_phys->dn_nblkptr);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie zio_t *pio = zio_root(dmu_objset_spa(dn->dn_objset), NULL, NULL,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dbuf_prefetch_arg_t *dpa = kmem_zalloc(sizeof (*dpa), KM_SLEEP);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie dsl_dataset_t *ds = dn->dn_objset->os_dsl_dataset;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie SET_BOOKMARK(&dpa->dpa_zb, ds != NULL ? ds->ds_object : DMU_META_OBJSET,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * If we have the indirect just above us, no need to do the asynchronous
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * prefetch chain; we'll just run the last step ourselves. If we're at
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * a higher level, though, we want to issue the prefetches for all the
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * indirect blocks asynchronously, so we can go on with whatever we were
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie SET_BOOKMARK(&zb, ds != NULL ? ds->ds_object : DMU_META_OBJSET,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * We use pio here instead of dpa_zio since it's possible that
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * dpa may have already been freed.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns with db_holds incremented, and db_mtx not held.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Note: dn_struct_rwlock must be held.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagneliedbuf_hold_impl(dnode_t *dn, uint8_t level, uint64_t blkid,
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie boolean_t fail_sparse, boolean_t fail_uncached,
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* dbuf_find() returns with db_mtx held */
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbs db = dbuf_find(dn->dn_objset, dn->dn_object, level, blkid);
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = dbuf_findbp(dn, level, blkid, fail_sparse, &parent, &bp);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (fail_uncached && db->db_state != DB_CACHED) {
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ASSERT(db->db_buf == NULL || arc_referenced(db->db_buf));
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * If this buffer is currently syncing out, and we are are
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * still referencing it from db_data, we need to make a copy
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * of it in case we decide we want to dirty it again in this txg.
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (db->db_level == 0 && db->db_blkid != DMU_BONUS_BLKID &&
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson if (multilist_link_active(&db->db_cache_link)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* NOTE: we can't rele the parent until after we drop the db_mtx */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrensdbuf_hold_level(dnode_t *dn, int level, uint64_t blkid, void *tag)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie int err = dbuf_hold_impl(dn, level, blkid, FALSE, FALSE, tag, &db);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum dn->dn_bonus = dbuf_create(dn, 0, DMU_BONUS_BLKID, dn->dn_dbuf, NULL);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaumdbuf_spill_set_blksz(dmu_buf_t *db_fake, uint64_t blksz, dmu_tx_t *tx)
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
b515258426fed6c7311fd3f1dea697cfbd4085c6Matthew Ahrens ASSERT3U(blksz, <=, spa_maxblocksize(dmu_objset_spa(db->db_objset)));
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum dbuf_free_range(dn, DMU_SPILL_BLKID, DMU_SPILL_BLKID, tx);
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbs#pragma weak dmu_buf_try_add_ref = dbuf_try_add_ref
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbsdbuf_try_add_ref(dmu_buf_t *db_fake, objset_t *os, uint64_t obj, uint64_t blkid,
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbs dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
e57a022b8f718889ffa92adbde47a8f08abcdb25Justin T. Gibbs if (db == found_db && dbuf_refcount(db) > db->db_dirtycnt) {
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * If you call dbuf_rele() you had better not be referencing the dnode handle
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * unless you have some other direct or indirect hold on the dnode. (An indirect
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * hold is a hold on one of the dnode's dbufs, including the bonus buffer.)
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Without that, the dbuf_rele() could lead to a dnode_rele() followed by the
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * dnode's parent dbuf evicting its dnode handles.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * dbuf_rele() for an already-locked dbuf. This is necessary to allow
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * db_dirtycnt and db_holds to be updated atomically.
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickdbuf_rele_and_unlock(dmu_buf_impl_t *db, void *tag)
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Remove the reference to the dbuf before removing its hold on the
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * dnode so we can guarantee in dnode_move() that a referenced bonus
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * buffer has a corresponding dnode hold.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * We can't freeze indirects if there is a possibility that they
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * may be modified in the current syncing context.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson holds == (db->db_level == 0 ? db->db_dirtycnt : 0)) {
d2058105c61ec61df3a2dd3f839fed8c3fe7bfd6Justin T. Gibbs db->db_level == 0 && db->db_user_immediate_evict)
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (holds == 0) {
d2058105c61ec61df3a2dd3f839fed8c3fe7bfd6Justin T. Gibbs boolean_t evict_dbuf = db->db_pending_evict;
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * If the dnode moves here, we cannot cross this
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * barrier until the move completes.
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * Decrementing the dbuf count means that the bonus
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * buffer's dnode hold is no longer discounted in
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * dnode_move(). The dnode cannot move until after
d2058105c61ec61df3a2dd3f839fed8c3fe7bfd6Justin T. Gibbs * the dnode_rele() below.
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * Do not reference db after its lock is dropped.
cd485b49201b16c079663125308af274b6299e96Justin T. Gibbs * Another thread may evict it.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * This is a special case: we never associated this
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * dbuf with any data allocated from the ARC.
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * This dbuf has anonymous data associated with it.
dcbf3bd6a1f1360fc1afcee9e22c6dcff7844bf2George Wilson } else if (!multilist_link_active(&db->db_cache_link)) {
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbsdmu_buf_replace_user(dmu_buf_t *db_fake, dmu_buf_user_t *old_user,
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake;
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbsdmu_buf_set_user(dmu_buf_t *db_fake, dmu_buf_user_t *user)
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs return (dmu_buf_replace_user(db_fake, NULL, user));
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbsdmu_buf_set_user_ie(dmu_buf_t *db_fake, dmu_buf_user_t *user)
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbsdmu_buf_remove_user(dmu_buf_t *db_fake, dmu_buf_user_t *user)
bc9014e6a81272073b9854d9f65dd59e18d18c35Justin Gibbs return (dmu_buf_replace_user(db_fake, user, NULL));
3d6926289465757c3da780cea696825b0d730283Sanjeev Bagewadi dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbuf;
3d6926289465757c3da780cea696825b0d730283Sanjeev Bagewadi res = dsl_dataset_block_freeable(db->db_objset->os_dsl_dataset,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee /* ASSERT(dmu_tx_is_syncing(tx) */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * This buffer was allocated at a time when there was
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * no available blkptrs from the dnode, or it was
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * inappropriate to hook it in (i.e., nlevels mis-match).
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee db->db_blkptr = &dn->dn_phys->dn_blkptr[db->db_blkid];
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee int epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie parent = dbuf_hold_level(dn, db->db_level + 1,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeedbuf_sync_indirect(dbuf_dirty_record_t *dr, dmu_tx_t *tx)
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee dprintf_dbuf_bp(db, db->db_blkptr, "blkptr=%p", db->db_blkptr);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Read the block if it hasn't been read yet. */
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Indirect block size must match what the dnode thinks it is. */
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson ASSERT3U(db->db.db_size, ==, 1<<dn->dn_phys->dn_indblkshift);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Provide the pending dirty record to child dbufs */
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens dbuf_sync_list(&dr->dt.di.dr_children, db->db_level - 1, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf_dbuf_bp(db, db->db_blkptr, "blkptr=%p", db->db_blkptr);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * To be synced, we must be dirtied. But we
fa9e4066f08beec538e775443c5be79dd423fcabahrens * might have been freed after the dirty.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* This buffer has been freed since it was dirtied */
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* This buffer was freed and is now being re-filled */
82c9918f28a2d8d9e93769e16f7fa7bee347e80fTim Haley ASSERT(db->db_state == DB_CACHED || db->db_state == DB_NOFILL);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum dn->dn_phys->dn_flags |= DNODE_FLAG_SPILL_BLKPTR;
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * If this is a bonus buffer, simply copy the bonus data into the
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * dnode. It will be written out when the dnode is synced (and it
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * will be synced, since it must have been dirty for dbuf_sync to
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * be called).
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ASSERT3U(dn->dn_phys->dn_bonuslen, <=, DN_MAX_BONUSLEN);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock bcopy(*datap, DN_BONUS(dn->dn_phys), dn->dn_phys->dn_bonuslen);
5a98e54b3632348add05cdbf50bbf52e1b839c10Brendan Gregg - Sun Microsystems arc_space_return(DN_MAX_BONUSLEN, ARC_SPACE_OTHER);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick dbuf_rele_and_unlock(db, (void *)(uintptr_t)txg);
f82bfe17f53efa8e4aca04a764d0352539201fb5gw * This function may have dropped the db_mtx lock allowing a dmu_sync
f82bfe17f53efa8e4aca04a764d0352539201fb5gw * operation to sneak in. As a result, we need to ensure that we
f82bfe17f53efa8e4aca04a764d0352539201fb5gw * don't check the dr_override_state until we have returned from
f82bfe17f53efa8e4aca04a764d0352539201fb5gw * dbuf_check_blkptr.
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * If this buffer is in the middle of an immediate write,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * wait for the synchronous IO to complete.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee while (dr->dt.dl.dr_override_state == DR_IN_DMU_SYNC) {
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee ASSERT(dr->dt.dl.dr_override_state != DR_NOT_OVERRIDDEN);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick dr->dt.dl.dr_override_state != DR_OVERRIDDEN &&
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * If this buffer is currently "in use" (i.e., there
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * are active holds and db_data still references it),
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * then make a copy before we start the write so that
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * any modifications from the open txg will not leak
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * into this write.
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * NOTE: this copy does not need to be made for
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * objects only modified in the syncing context (e.g.
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens * DNONE_DNODE blocks).
ab69d62f363ee70f4e4cded1092a68cc0c63136fMatthew Ahrens arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel enum zio_compress compress_type = arc_get_compression(*datap);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel *datap = arc_alloc_buf(os->os_spa, db, type, psize);
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel *datap = arc_alloc_compressed_buf(os->os_spa, db,
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee list_insert_tail(&dn->dn_dirty_records[txg&TXG_MASK], dr);
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Although zio_nowait() does not "wait for an IO", it does
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * initiate the IO. If this is an empty write it seems plausible
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * that the IO could actually be completed before the nowait
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * returns. We need to DB_DNODE_EXIT() first in case
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * zio_nowait() invalidates the dbuf.
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrensdbuf_sync_list(list_t *list, int level, dmu_tx_t *tx)
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * If we find an already initialized zio then we
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * are processing the meta-dnode, and we have finished.
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * The dbufs for all dnodes are put back on the list
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * during processing, so that we can zio_wait()
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee * these IOs after initiating all child IOs.
46e1baa6cf6d5432f5fd231bb588df8f9570c858Matthew Ahrens if (dr->dr_dbuf->db_blkid != DMU_BONUS_BLKID &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens/* ARGSUSED */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeedbuf_write_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
11ceac77ea8034bf2fe9bdd6d314f5d1e5ceeba3Alex Reece ASSERT3P(&db->db_data_pending->dr_bp_copy, ==, bp);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick delta = bp_get_dsize_sync(spa, bp) - bp_get_dsize_sync(spa, bp_orig);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick dnode_diduse_space(dn, delta - zio->io_prev_space_delta);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum ASSERT(dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum if (db->db_blkid > dn->dn_phys->dn_maxblkid &&
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT3U(db->db.db_size, ==, 1<<dn->dn_phys->dn_indblkshift);
e14bb3258d05c1b1077e2db7cf77088924e56919Jeff Bonwick for (i = db->db.db_size >> SPA_BLKPTRSHIFT; i > 0; i--, ibp++) {
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie/* ARGSUSED */
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * This function gets called just prior to running through the compression
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * stage of the zio pipeline. If we're an indirect block comprised of only
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * holes, then we want this indirect to be compressed away to a hole. In
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * order to do that we must zero out any information about the holes that
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * this indirect points to prior to before we try to compress it.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagneliedbuf_write_children_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie /* Determine if all our children are holes */
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie for (i = 0, bp = db->db.db_data; i < 1 << epbs; i++, bp++) {
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * If all the children are holes, then zero them all out so that
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * we may get compressed away.
1a01181fdc809f40c64d5c6881ae3e4521a9d9c7George Wilson * We only found holes. Grab the rwlock to prevent
1a01181fdc809f40c64d5c6881ae3e4521a9d9c7George Wilson * anybody from reading the blocks we're about to
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * The SPA will call this callback several times for each zio - once
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * for every physical child i/o (zio->io_phys_children times). This
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * allows the DMU to monitor the progress of each logical i/o. For example,
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * there may be 2 copies of an indirect block, or many fragments of a RAID-Z
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * block. There may be a long delay before all copies/fragments are completed,
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * so this callback allows us to retire dirty space gradually, as the physical
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens/* ARGSUSED */
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensdbuf_write_physdone(zio_t *zio, arc_buf_t *buf, void *arg)
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * The callback will be called io_phys_children times. Retire one
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * portion of our dirty space each time we are called. Any rounding
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * error will be cleaned up by dsl_pool_sync()'s call to
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * dsl_pool_undirty_space().
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens delta = dr->dr_accounted / zio->io_phys_children;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens dsl_pool_undirty_space(dp, delta, zio->io_txg);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee/* ARGSUSED */
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybeedbuf_write_done(zio_t *zio, arc_buf_t *buf, void *vdb)
80901aea8e78a2c20751f61f01bebd1d5b5c2ba5George Wilson * For nopwrites and rewrites we ensure that the bp matches our
80901aea8e78a2c20751f61f01bebd1d5b5c2ba5George Wilson * original and bypass all the accounting.
80901aea8e78a2c20751f61f01bebd1d5b5c2ba5George Wilson if (zio->io_flags & (ZIO_FLAG_IO_REWRITE | ZIO_FLAG_NOPWRITE)) {
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick (void) dsl_dataset_block_kill(ds, bp_orig, tx, B_TRUE);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum ASSERT(dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR);
c717a56157ae0e6fca6a1e3689ae1edc385716a3maybee ASSERT(dr->dt.dl.dr_override_state == DR_NOT_OVERRIDDEN);
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman ASSERT3U(db->db.db_size, ==, 1 << dn->dn_phys->dn_indblkshift);
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman dn->dn_phys->dn_maxblkid >> (db->db_level * epbs));
43466aae47bfcd2ad9bf501faec8e75c08095e4fMax Grossman dbuf_rele_and_unlock(db, (void *)(uintptr_t)tx->tx_txg);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick dsl_free(spa_get_dsl(zio->io_spa), zio->io_txg, obp);
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews/* Issue I/O to commit a dirty buffer to disk. */
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickdbuf_write(dbuf_dirty_record_t *dr, arc_buf_t *data, dmu_tx_t *tx)
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick if (db->db_level > 0 || dn->dn_type == DMU_OT_DNODE) {
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * Private object buffers are released here rather
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * than in dbuf_dirty() since they are only modified
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * in the syncing context and we don't want the
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick * overhead of making multiple copies of the data.
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Our parent is an indirect block. */
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* We have a dirty parent that has been scheduled for write. */
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Our parent's buffer is one level closer to the dnode. */
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * We're about to modify our parent's db_data by modifying
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews * our block pointer, so the parent must be released.
3e30c24aeefdee1631958ecf17f18da671781956Will Andrews /* Our parent is the dnode itself. */
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum ASSERT((db->db_level == dn->dn_phys->dn_nlevels-1 &&
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum (db->db_blkid == DMU_SPILL_BLKID && db->db_level == 0));
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick ASSERT(db->db_level == 0 || data == db->db_buf);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick os->os_dsl_dataset->ds_object : DMU_META_OBJSET,
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum wp_flag |= (db->db_state == DB_NOFILL) ? WP_NOFILL : 0;
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel (data != NULL && arc_get_compression(data) != ZIO_COMPRESS_OFF) ?
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel arc_get_compression(data) : ZIO_COMPRESS_INHERIT, &zp);
11ceac77ea8034bf2fe9bdd6d314f5d1e5ceeba3Alex Reece * We copy the blkptr now (rather than when we instantiate the dirty
11ceac77ea8034bf2fe9bdd6d314f5d1e5ceeba3Alex Reece * record), because its value can change between open context and
11ceac77ea8034bf2fe9bdd6d314f5d1e5ceeba3Alex Reece * syncing context. We do not need to hold dn_struct_rwlock to read
11ceac77ea8034bf2fe9bdd6d314f5d1e5ceeba3Alex Reece * db_blkptr because we are in syncing context.
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens dr->dt.dl.dr_override_state == DR_OVERRIDDEN) {
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * The BP for this block has been provided by open context
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens * (by dmu_sync() or dmu_buf_write_embedded()).
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens void *contents = (data != NULL) ? data->b_data : NULL;
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel dr->dr_zio = zio_write(zio, os->os_spa, txg, &dr->dr_bp_copy,
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens dr, ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick dr->dt.dl.dr_override_state = DR_NOT_OVERRIDDEN;
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwick zio_write_override(dr->dr_zio, &dr->dt.dl.dr_overridden_by,
5602294fda888d923d57a78bafdaf48ae6223deaDan Kimmel &dr->dr_bp_copy, NULL, db->db.db_size, db->db.db_size, &zp,
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * For indirect blocks, we want to setup the children
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * ready callback so that we can properly handle an indirect
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie * block that only contains holes.
8df0bcf0df7622a075cc6e52f659d2fcfdd08cdcPaul Dagnelie children_ready_cb = dbuf_write_children_ready;