4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
25 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
26 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
29 #include <sys/zfs_context.h>
32 #include <sys/dmu_send.h>
33 #include <sys/dmu_impl.h>
35 #include <sys/dmu_objset.h>
36 #include <sys/dsl_dataset.h>
37 #include <sys/dsl_dir.h>
38 #include <sys/dmu_tx.h>
41 #include <sys/dmu_zfetch.h>
43 #include <sys/sa_impl.h>
44 #include <sys/zfeature.h>
45 #include <sys/blkptr.h>
46 #include <sys/range_tree.h>
47 #include <sys/trace_dbuf.h>
49 struct dbuf_hold_impl_data
{
50 /* Function arguments */
56 dmu_buf_impl_t
**dh_dbp
;
58 dmu_buf_impl_t
*dh_db
;
59 dmu_buf_impl_t
*dh_parent
;
62 dbuf_dirty_record_t
*dh_dr
;
63 arc_buf_contents_t dh_type
;
67 static void __dbuf_hold_impl_init(struct dbuf_hold_impl_data
*dh
,
68 dnode_t
*dn
, uint8_t level
, uint64_t blkid
, int fail_sparse
,
69 void *tag
, dmu_buf_impl_t
**dbp
, int depth
);
70 static int __dbuf_hold_impl(struct dbuf_hold_impl_data
*dh
);
73 * Number of times that zfs_free_range() took the slow path while doing
74 * a zfs receive. A nonzero value indicates a potential performance problem.
76 uint64_t zfs_free_range_recv_miss
;
78 static void dbuf_destroy(dmu_buf_impl_t
*db
);
79 static boolean_t
dbuf_undirty(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
);
80 static void dbuf_write(dbuf_dirty_record_t
*dr
, arc_buf_t
*data
, dmu_tx_t
*tx
);
83 extern inline void dmu_buf_init_user(dmu_buf_user_t
*dbu
,
84 dmu_buf_evict_func_t
*evict_func
, dmu_buf_t
**clear_on_evict_dbufp
);
88 * Global data structures and functions for the dbuf cache.
90 static kmem_cache_t
*dbuf_cache
;
91 static taskq_t
*dbu_evict_taskq
;
95 dbuf_cons(void *vdb
, void *unused
, int kmflag
)
97 dmu_buf_impl_t
*db
= vdb
;
98 bzero(db
, sizeof (dmu_buf_impl_t
));
100 mutex_init(&db
->db_mtx
, NULL
, MUTEX_DEFAULT
, NULL
);
101 cv_init(&db
->db_changed
, NULL
, CV_DEFAULT
, NULL
);
102 refcount_create(&db
->db_holds
);
109 dbuf_dest(void *vdb
, void *unused
)
111 dmu_buf_impl_t
*db
= vdb
;
112 mutex_destroy(&db
->db_mtx
);
113 cv_destroy(&db
->db_changed
);
114 refcount_destroy(&db
->db_holds
);
118 * dbuf hash table routines
120 static dbuf_hash_table_t dbuf_hash_table
;
122 static uint64_t dbuf_hash_count
;
125 dbuf_hash(void *os
, uint64_t obj
, uint8_t lvl
, uint64_t blkid
)
127 uintptr_t osv
= (uintptr_t)os
;
128 uint64_t crc
= -1ULL;
130 ASSERT(zfs_crc64_table
[128] == ZFS_CRC64_POLY
);
131 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (lvl
)) & 0xFF];
132 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (osv
>> 6)) & 0xFF];
133 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (obj
>> 0)) & 0xFF];
134 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (obj
>> 8)) & 0xFF];
135 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (blkid
>> 0)) & 0xFF];
136 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (blkid
>> 8)) & 0xFF];
138 crc
^= (osv
>>14) ^ (obj
>>16) ^ (blkid
>>16);
143 #define DBUF_HASH(os, obj, level, blkid) dbuf_hash(os, obj, level, blkid);
145 #define DBUF_EQUAL(dbuf, os, obj, level, blkid) \
146 ((dbuf)->db.db_object == (obj) && \
147 (dbuf)->db_objset == (os) && \
148 (dbuf)->db_level == (level) && \
149 (dbuf)->db_blkid == (blkid))
152 dbuf_find(objset_t
*os
, uint64_t obj
, uint8_t level
, uint64_t blkid
)
154 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
159 hv
= DBUF_HASH(os
, obj
, level
, blkid
);
160 idx
= hv
& h
->hash_table_mask
;
162 mutex_enter(DBUF_HASH_MUTEX(h
, idx
));
163 for (db
= h
->hash_table
[idx
]; db
!= NULL
; db
= db
->db_hash_next
) {
164 if (DBUF_EQUAL(db
, os
, obj
, level
, blkid
)) {
165 mutex_enter(&db
->db_mtx
);
166 if (db
->db_state
!= DB_EVICTING
) {
167 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
170 mutex_exit(&db
->db_mtx
);
173 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
177 static dmu_buf_impl_t
*
178 dbuf_find_bonus(objset_t
*os
, uint64_t object
)
181 dmu_buf_impl_t
*db
= NULL
;
183 if (dnode_hold(os
, object
, FTAG
, &dn
) == 0) {
184 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
185 if (dn
->dn_bonus
!= NULL
) {
187 mutex_enter(&db
->db_mtx
);
189 rw_exit(&dn
->dn_struct_rwlock
);
190 dnode_rele(dn
, FTAG
);
196 * Insert an entry into the hash table. If there is already an element
197 * equal to elem in the hash table, then the already existing element
198 * will be returned and the new element will not be inserted.
199 * Otherwise returns NULL.
201 static dmu_buf_impl_t
*
202 dbuf_hash_insert(dmu_buf_impl_t
*db
)
204 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
205 objset_t
*os
= db
->db_objset
;
206 uint64_t obj
= db
->db
.db_object
;
207 int level
= db
->db_level
;
208 uint64_t blkid
, hv
, idx
;
211 blkid
= db
->db_blkid
;
212 hv
= DBUF_HASH(os
, obj
, level
, blkid
);
213 idx
= hv
& h
->hash_table_mask
;
215 mutex_enter(DBUF_HASH_MUTEX(h
, idx
));
216 for (dbf
= h
->hash_table
[idx
]; dbf
!= NULL
; dbf
= dbf
->db_hash_next
) {
217 if (DBUF_EQUAL(dbf
, os
, obj
, level
, blkid
)) {
218 mutex_enter(&dbf
->db_mtx
);
219 if (dbf
->db_state
!= DB_EVICTING
) {
220 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
223 mutex_exit(&dbf
->db_mtx
);
227 mutex_enter(&db
->db_mtx
);
228 db
->db_hash_next
= h
->hash_table
[idx
];
229 h
->hash_table
[idx
] = db
;
230 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
231 atomic_add_64(&dbuf_hash_count
, 1);
237 * Remove an entry from the hash table. It must be in the EVICTING state.
240 dbuf_hash_remove(dmu_buf_impl_t
*db
)
242 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
244 dmu_buf_impl_t
*dbf
, **dbp
;
246 hv
= DBUF_HASH(db
->db_objset
, db
->db
.db_object
,
247 db
->db_level
, db
->db_blkid
);
248 idx
= hv
& h
->hash_table_mask
;
251 * We musn't hold db_mtx to maintain lock ordering:
252 * DBUF_HASH_MUTEX > db_mtx.
254 ASSERT(refcount_is_zero(&db
->db_holds
));
255 ASSERT(db
->db_state
== DB_EVICTING
);
256 ASSERT(!MUTEX_HELD(&db
->db_mtx
));
258 mutex_enter(DBUF_HASH_MUTEX(h
, idx
));
259 dbp
= &h
->hash_table
[idx
];
260 while ((dbf
= *dbp
) != db
) {
261 dbp
= &dbf
->db_hash_next
;
264 *dbp
= db
->db_hash_next
;
265 db
->db_hash_next
= NULL
;
266 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
267 atomic_add_64(&dbuf_hash_count
, -1);
270 static arc_evict_func_t dbuf_do_evict
;
275 } dbvu_verify_type_t
;
278 dbuf_verify_user(dmu_buf_impl_t
*db
, dbvu_verify_type_t verify_type
)
283 if (db
->db_user
== NULL
)
286 /* Only data blocks support the attachment of user data. */
287 ASSERT(db
->db_level
== 0);
289 /* Clients must resolve a dbuf before attaching user data. */
290 ASSERT(db
->db
.db_data
!= NULL
);
291 ASSERT3U(db
->db_state
, ==, DB_CACHED
);
293 holds
= refcount_count(&db
->db_holds
);
294 if (verify_type
== DBVU_EVICTING
) {
296 * Immediate eviction occurs when holds == dirtycnt.
297 * For normal eviction buffers, holds is zero on
298 * eviction, except when dbuf_fix_old_data() calls
299 * dbuf_clear_data(). However, the hold count can grow
300 * during eviction even though db_mtx is held (see
301 * dmu_bonus_hold() for an example), so we can only
302 * test the generic invariant that holds >= dirtycnt.
304 ASSERT3U(holds
, >=, db
->db_dirtycnt
);
306 if (db
->db_user_immediate_evict
== TRUE
)
307 ASSERT3U(holds
, >=, db
->db_dirtycnt
);
309 ASSERT3U(holds
, >, 0);
315 dbuf_evict_user(dmu_buf_impl_t
*db
)
317 dmu_buf_user_t
*dbu
= db
->db_user
;
319 ASSERT(MUTEX_HELD(&db
->db_mtx
));
324 dbuf_verify_user(db
, DBVU_EVICTING
);
328 if (dbu
->dbu_clear_on_evict_dbufp
!= NULL
)
329 *dbu
->dbu_clear_on_evict_dbufp
= NULL
;
333 * Invoke the callback from a taskq to avoid lock order reversals
334 * and limit stack depth.
336 taskq_dispatch_ent(dbu_evict_taskq
, dbu
->dbu_evict_func
, dbu
, 0,
341 dbuf_is_metadata(dmu_buf_impl_t
*db
)
344 * Consider indirect blocks and spill blocks to be meta data.
346 if (db
->db_level
> 0 || db
->db_blkid
== DMU_SPILL_BLKID
) {
349 boolean_t is_metadata
;
352 is_metadata
= DMU_OT_IS_METADATA(DB_DNODE(db
)->dn_type
);
355 return (is_metadata
);
360 dbuf_evict(dmu_buf_impl_t
*db
)
362 ASSERT(MUTEX_HELD(&db
->db_mtx
));
363 ASSERT(db
->db_buf
== NULL
);
364 ASSERT(db
->db_data_pending
== NULL
);
373 uint64_t hsize
= 1ULL << 16;
374 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
378 * The hash table is big enough to fill all of physical memory
379 * with an average block size of zfs_arc_average_blocksize (default 8K).
380 * By default, the table will take up
381 * totalmem * sizeof(void*) / 8K (1MB per GB with 8-byte pointers).
383 while (hsize
* zfs_arc_average_blocksize
< physmem
* PAGESIZE
)
387 h
->hash_table_mask
= hsize
- 1;
388 #if defined(_KERNEL) && defined(HAVE_SPL)
390 * Large allocations which do not require contiguous pages
391 * should be using vmem_alloc() in the linux kernel
393 h
->hash_table
= vmem_zalloc(hsize
* sizeof (void *), KM_SLEEP
);
395 h
->hash_table
= kmem_zalloc(hsize
* sizeof (void *), KM_NOSLEEP
);
397 if (h
->hash_table
== NULL
) {
398 /* XXX - we should really return an error instead of assert */
399 ASSERT(hsize
> (1ULL << 10));
404 dbuf_cache
= kmem_cache_create("dmu_buf_impl_t",
405 sizeof (dmu_buf_impl_t
),
406 0, dbuf_cons
, dbuf_dest
, NULL
, NULL
, NULL
, 0);
408 for (i
= 0; i
< DBUF_MUTEXES
; i
++)
409 mutex_init(&h
->hash_mutexes
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
414 * All entries are queued via taskq_dispatch_ent(), so min/maxalloc
415 * configuration is not required.
417 dbu_evict_taskq
= taskq_create("dbu_evict", 1, defclsyspri
, 0, 0, 0);
423 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
426 dbuf_stats_destroy();
428 for (i
= 0; i
< DBUF_MUTEXES
; i
++)
429 mutex_destroy(&h
->hash_mutexes
[i
]);
430 #if defined(_KERNEL) && defined(HAVE_SPL)
432 * Large allocations which do not require contiguous pages
433 * should be using vmem_free() in the linux kernel
435 vmem_free(h
->hash_table
, (h
->hash_table_mask
+ 1) * sizeof (void *));
437 kmem_free(h
->hash_table
, (h
->hash_table_mask
+ 1) * sizeof (void *));
439 kmem_cache_destroy(dbuf_cache
);
440 taskq_destroy(dbu_evict_taskq
);
449 dbuf_verify(dmu_buf_impl_t
*db
)
452 dbuf_dirty_record_t
*dr
;
454 ASSERT(MUTEX_HELD(&db
->db_mtx
));
456 if (!(zfs_flags
& ZFS_DEBUG_DBUF_VERIFY
))
459 ASSERT(db
->db_objset
!= NULL
);
463 ASSERT(db
->db_parent
== NULL
);
464 ASSERT(db
->db_blkptr
== NULL
);
466 ASSERT3U(db
->db
.db_object
, ==, dn
->dn_object
);
467 ASSERT3P(db
->db_objset
, ==, dn
->dn_objset
);
468 ASSERT3U(db
->db_level
, <, dn
->dn_nlevels
);
469 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
470 db
->db_blkid
== DMU_SPILL_BLKID
||
471 !avl_is_empty(&dn
->dn_dbufs
));
473 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
475 ASSERT3U(db
->db
.db_size
, >=, dn
->dn_bonuslen
);
476 ASSERT3U(db
->db
.db_offset
, ==, DMU_BONUS_BLKID
);
477 } else if (db
->db_blkid
== DMU_SPILL_BLKID
) {
479 ASSERT3U(db
->db
.db_size
, >=, dn
->dn_bonuslen
);
480 ASSERT0(db
->db
.db_offset
);
482 ASSERT3U(db
->db
.db_offset
, ==, db
->db_blkid
* db
->db
.db_size
);
485 for (dr
= db
->db_data_pending
; dr
!= NULL
; dr
= dr
->dr_next
)
486 ASSERT(dr
->dr_dbuf
== db
);
488 for (dr
= db
->db_last_dirty
; dr
!= NULL
; dr
= dr
->dr_next
)
489 ASSERT(dr
->dr_dbuf
== db
);
492 * We can't assert that db_size matches dn_datablksz because it
493 * can be momentarily different when another thread is doing
496 if (db
->db_level
== 0 && db
->db
.db_object
== DMU_META_DNODE_OBJECT
) {
497 dr
= db
->db_data_pending
;
499 * It should only be modified in syncing context, so
500 * make sure we only have one copy of the data.
502 ASSERT(dr
== NULL
|| dr
->dt
.dl
.dr_data
== db
->db_buf
);
505 /* verify db->db_blkptr */
507 if (db
->db_parent
== dn
->dn_dbuf
) {
508 /* db is pointed to by the dnode */
509 /* ASSERT3U(db->db_blkid, <, dn->dn_nblkptr); */
510 if (DMU_OBJECT_IS_SPECIAL(db
->db
.db_object
))
511 ASSERT(db
->db_parent
== NULL
);
513 ASSERT(db
->db_parent
!= NULL
);
514 if (db
->db_blkid
!= DMU_SPILL_BLKID
)
515 ASSERT3P(db
->db_blkptr
, ==,
516 &dn
->dn_phys
->dn_blkptr
[db
->db_blkid
]);
518 /* db is pointed to by an indirect block */
519 ASSERTV(int epb
= db
->db_parent
->db
.db_size
>>
521 ASSERT3U(db
->db_parent
->db_level
, ==, db
->db_level
+1);
522 ASSERT3U(db
->db_parent
->db
.db_object
, ==,
525 * dnode_grow_indblksz() can make this fail if we don't
526 * have the struct_rwlock. XXX indblksz no longer
527 * grows. safe to do this now?
529 if (RW_WRITE_HELD(&dn
->dn_struct_rwlock
)) {
530 ASSERT3P(db
->db_blkptr
, ==,
531 ((blkptr_t
*)db
->db_parent
->db
.db_data
+
532 db
->db_blkid
% epb
));
536 if ((db
->db_blkptr
== NULL
|| BP_IS_HOLE(db
->db_blkptr
)) &&
537 (db
->db_buf
== NULL
|| db
->db_buf
->b_data
) &&
538 db
->db
.db_data
&& db
->db_blkid
!= DMU_BONUS_BLKID
&&
539 db
->db_state
!= DB_FILL
&& !dn
->dn_free_txg
) {
541 * If the blkptr isn't set but they have nonzero data,
542 * it had better be dirty, otherwise we'll lose that
543 * data when we evict this buffer.
545 if (db
->db_dirtycnt
== 0) {
546 ASSERTV(uint64_t *buf
= db
->db
.db_data
);
549 for (i
= 0; i
< db
->db
.db_size
>> 3; i
++) {
559 dbuf_clear_data(dmu_buf_impl_t
*db
)
561 ASSERT(MUTEX_HELD(&db
->db_mtx
));
564 db
->db
.db_data
= NULL
;
565 if (db
->db_state
!= DB_NOFILL
)
566 db
->db_state
= DB_UNCACHED
;
570 dbuf_set_data(dmu_buf_impl_t
*db
, arc_buf_t
*buf
)
572 ASSERT(MUTEX_HELD(&db
->db_mtx
));
576 ASSERT(buf
->b_data
!= NULL
);
577 db
->db
.db_data
= buf
->b_data
;
578 if (!arc_released(buf
))
579 arc_set_callback(buf
, dbuf_do_evict
, db
);
583 * Loan out an arc_buf for read. Return the loaned arc_buf.
586 dbuf_loan_arcbuf(dmu_buf_impl_t
*db
)
590 mutex_enter(&db
->db_mtx
);
591 if (arc_released(db
->db_buf
) || refcount_count(&db
->db_holds
) > 1) {
592 int blksz
= db
->db
.db_size
;
593 spa_t
*spa
= db
->db_objset
->os_spa
;
595 mutex_exit(&db
->db_mtx
);
596 abuf
= arc_loan_buf(spa
, blksz
);
597 bcopy(db
->db
.db_data
, abuf
->b_data
, blksz
);
600 arc_loan_inuse_buf(abuf
, db
);
602 mutex_exit(&db
->db_mtx
);
608 dbuf_whichblock(dnode_t
*dn
, uint64_t offset
)
610 if (dn
->dn_datablkshift
) {
611 return (offset
>> dn
->dn_datablkshift
);
613 ASSERT3U(offset
, <, dn
->dn_datablksz
);
619 dbuf_read_done(zio_t
*zio
, arc_buf_t
*buf
, void *vdb
)
621 dmu_buf_impl_t
*db
= vdb
;
623 mutex_enter(&db
->db_mtx
);
624 ASSERT3U(db
->db_state
, ==, DB_READ
);
626 * All reads are synchronous, so we must have a hold on the dbuf
628 ASSERT(refcount_count(&db
->db_holds
) > 0);
629 ASSERT(db
->db_buf
== NULL
);
630 ASSERT(db
->db
.db_data
== NULL
);
631 if (db
->db_level
== 0 && db
->db_freed_in_flight
) {
632 /* we were freed in flight; disregard any error */
633 arc_release(buf
, db
);
634 bzero(buf
->b_data
, db
->db
.db_size
);
636 db
->db_freed_in_flight
= FALSE
;
637 dbuf_set_data(db
, buf
);
638 db
->db_state
= DB_CACHED
;
639 } else if (zio
== NULL
|| zio
->io_error
== 0) {
640 dbuf_set_data(db
, buf
);
641 db
->db_state
= DB_CACHED
;
643 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
644 ASSERT3P(db
->db_buf
, ==, NULL
);
645 VERIFY(arc_buf_remove_ref(buf
, db
));
646 db
->db_state
= DB_UNCACHED
;
648 cv_broadcast(&db
->db_changed
);
649 dbuf_rele_and_unlock(db
, NULL
);
653 dbuf_read_impl(dmu_buf_impl_t
*db
, zio_t
*zio
, uint32_t *flags
)
657 uint32_t aflags
= ARC_FLAG_NOWAIT
;
662 ASSERT(!refcount_is_zero(&db
->db_holds
));
663 /* We need the struct_rwlock to prevent db_blkptr from changing. */
664 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
665 ASSERT(MUTEX_HELD(&db
->db_mtx
));
666 ASSERT(db
->db_state
== DB_UNCACHED
);
667 ASSERT(db
->db_buf
== NULL
);
669 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
670 int bonuslen
= MIN(dn
->dn_bonuslen
, dn
->dn_phys
->dn_bonuslen
);
672 ASSERT3U(bonuslen
, <=, db
->db
.db_size
);
673 db
->db
.db_data
= zio_buf_alloc(DN_MAX_BONUSLEN
);
674 arc_space_consume(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
675 if (bonuslen
< DN_MAX_BONUSLEN
)
676 bzero(db
->db
.db_data
, DN_MAX_BONUSLEN
);
678 bcopy(DN_BONUS(dn
->dn_phys
), db
->db
.db_data
, bonuslen
);
680 db
->db_state
= DB_CACHED
;
681 mutex_exit(&db
->db_mtx
);
686 * Recheck BP_IS_HOLE() after dnode_block_freed() in case dnode_sync()
687 * processes the delete record and clears the bp while we are waiting
688 * for the dn_mtx (resulting in a "no" from block_freed).
690 if (db
->db_blkptr
== NULL
|| BP_IS_HOLE(db
->db_blkptr
) ||
691 (db
->db_level
== 0 && (dnode_block_freed(dn
, db
->db_blkid
) ||
692 BP_IS_HOLE(db
->db_blkptr
)))) {
693 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
696 dbuf_set_data(db
, arc_buf_alloc(db
->db_objset
->os_spa
,
697 db
->db
.db_size
, db
, type
));
698 bzero(db
->db
.db_data
, db
->db
.db_size
);
699 db
->db_state
= DB_CACHED
;
700 *flags
|= DB_RF_CACHED
;
701 mutex_exit(&db
->db_mtx
);
707 db
->db_state
= DB_READ
;
708 mutex_exit(&db
->db_mtx
);
710 if (DBUF_IS_L2CACHEABLE(db
))
711 aflags
|= ARC_FLAG_L2CACHE
;
712 if (DBUF_IS_L2COMPRESSIBLE(db
))
713 aflags
|= ARC_FLAG_L2COMPRESS
;
715 SET_BOOKMARK(&zb
, db
->db_objset
->os_dsl_dataset
?
716 db
->db_objset
->os_dsl_dataset
->ds_object
: DMU_META_OBJSET
,
717 db
->db
.db_object
, db
->db_level
, db
->db_blkid
);
719 dbuf_add_ref(db
, NULL
);
721 err
= arc_read(zio
, db
->db_objset
->os_spa
, db
->db_blkptr
,
722 dbuf_read_done
, db
, ZIO_PRIORITY_SYNC_READ
,
723 (*flags
& DB_RF_CANFAIL
) ? ZIO_FLAG_CANFAIL
: ZIO_FLAG_MUSTSUCCEED
,
725 if (aflags
& ARC_FLAG_CACHED
)
726 *flags
|= DB_RF_CACHED
;
728 return (SET_ERROR(err
));
732 dbuf_read(dmu_buf_impl_t
*db
, zio_t
*zio
, uint32_t flags
)
735 boolean_t havepzio
= (zio
!= NULL
);
740 * We don't have to hold the mutex to check db_state because it
741 * can't be freed while we have a hold on the buffer.
743 ASSERT(!refcount_is_zero(&db
->db_holds
));
745 if (db
->db_state
== DB_NOFILL
)
746 return (SET_ERROR(EIO
));
750 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
751 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
753 prefetch
= db
->db_level
== 0 && db
->db_blkid
!= DMU_BONUS_BLKID
&&
754 (flags
& DB_RF_NOPREFETCH
) == 0 && dn
!= NULL
&&
755 DBUF_IS_CACHEABLE(db
);
757 mutex_enter(&db
->db_mtx
);
758 if (db
->db_state
== DB_CACHED
) {
759 mutex_exit(&db
->db_mtx
);
761 dmu_zfetch(&dn
->dn_zfetch
, db
->db
.db_offset
,
762 db
->db
.db_size
, TRUE
);
763 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
764 rw_exit(&dn
->dn_struct_rwlock
);
766 } else if (db
->db_state
== DB_UNCACHED
) {
767 spa_t
*spa
= dn
->dn_objset
->os_spa
;
770 zio
= zio_root(spa
, NULL
, NULL
, ZIO_FLAG_CANFAIL
);
772 err
= dbuf_read_impl(db
, zio
, &flags
);
774 /* dbuf_read_impl has dropped db_mtx for us */
776 if (!err
&& prefetch
)
777 dmu_zfetch(&dn
->dn_zfetch
, db
->db
.db_offset
,
778 db
->db
.db_size
, flags
& DB_RF_CACHED
);
780 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
781 rw_exit(&dn
->dn_struct_rwlock
);
784 if (!err
&& !havepzio
)
788 * Another reader came in while the dbuf was in flight
789 * between UNCACHED and CACHED. Either a writer will finish
790 * writing the buffer (sending the dbuf to CACHED) or the
791 * first reader's request will reach the read_done callback
792 * and send the dbuf to CACHED. Otherwise, a failure
793 * occurred and the dbuf went to UNCACHED.
795 mutex_exit(&db
->db_mtx
);
797 dmu_zfetch(&dn
->dn_zfetch
, db
->db
.db_offset
,
798 db
->db
.db_size
, TRUE
);
799 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
800 rw_exit(&dn
->dn_struct_rwlock
);
803 /* Skip the wait per the caller's request. */
804 mutex_enter(&db
->db_mtx
);
805 if ((flags
& DB_RF_NEVERWAIT
) == 0) {
806 while (db
->db_state
== DB_READ
||
807 db
->db_state
== DB_FILL
) {
808 ASSERT(db
->db_state
== DB_READ
||
809 (flags
& DB_RF_HAVESTRUCT
) == 0);
810 DTRACE_PROBE2(blocked__read
, dmu_buf_impl_t
*,
812 cv_wait(&db
->db_changed
, &db
->db_mtx
);
814 if (db
->db_state
== DB_UNCACHED
)
815 err
= SET_ERROR(EIO
);
817 mutex_exit(&db
->db_mtx
);
820 ASSERT(err
|| havepzio
|| db
->db_state
== DB_CACHED
);
825 dbuf_noread(dmu_buf_impl_t
*db
)
827 ASSERT(!refcount_is_zero(&db
->db_holds
));
828 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
829 mutex_enter(&db
->db_mtx
);
830 while (db
->db_state
== DB_READ
|| db
->db_state
== DB_FILL
)
831 cv_wait(&db
->db_changed
, &db
->db_mtx
);
832 if (db
->db_state
== DB_UNCACHED
) {
833 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
834 spa_t
*spa
= db
->db_objset
->os_spa
;
836 ASSERT(db
->db_buf
== NULL
);
837 ASSERT(db
->db
.db_data
== NULL
);
838 dbuf_set_data(db
, arc_buf_alloc(spa
, db
->db
.db_size
, db
, type
));
839 db
->db_state
= DB_FILL
;
840 } else if (db
->db_state
== DB_NOFILL
) {
843 ASSERT3U(db
->db_state
, ==, DB_CACHED
);
845 mutex_exit(&db
->db_mtx
);
849 * This is our just-in-time copy function. It makes a copy of
850 * buffers, that have been modified in a previous transaction
851 * group, before we modify them in the current active group.
853 * This function is used in two places: when we are dirtying a
854 * buffer for the first time in a txg, and when we are freeing
855 * a range in a dnode that includes this buffer.
857 * Note that when we are called from dbuf_free_range() we do
858 * not put a hold on the buffer, we just traverse the active
859 * dbuf list for the dnode.
862 dbuf_fix_old_data(dmu_buf_impl_t
*db
, uint64_t txg
)
864 dbuf_dirty_record_t
*dr
= db
->db_last_dirty
;
866 ASSERT(MUTEX_HELD(&db
->db_mtx
));
867 ASSERT(db
->db
.db_data
!= NULL
);
868 ASSERT(db
->db_level
== 0);
869 ASSERT(db
->db
.db_object
!= DMU_META_DNODE_OBJECT
);
872 (dr
->dt
.dl
.dr_data
!=
873 ((db
->db_blkid
== DMU_BONUS_BLKID
) ? db
->db
.db_data
: db
->db_buf
)))
877 * If the last dirty record for this dbuf has not yet synced
878 * and its referencing the dbuf data, either:
879 * reset the reference to point to a new copy,
880 * or (if there a no active holders)
881 * just null out the current db_data pointer.
883 ASSERT(dr
->dr_txg
>= txg
- 2);
884 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
885 /* Note that the data bufs here are zio_bufs */
886 dr
->dt
.dl
.dr_data
= zio_buf_alloc(DN_MAX_BONUSLEN
);
887 arc_space_consume(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
888 bcopy(db
->db
.db_data
, dr
->dt
.dl
.dr_data
, DN_MAX_BONUSLEN
);
889 } else if (refcount_count(&db
->db_holds
) > db
->db_dirtycnt
) {
890 int size
= db
->db
.db_size
;
891 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
892 spa_t
*spa
= db
->db_objset
->os_spa
;
894 dr
->dt
.dl
.dr_data
= arc_buf_alloc(spa
, size
, db
, type
);
895 bcopy(db
->db
.db_data
, dr
->dt
.dl
.dr_data
->b_data
, size
);
902 dbuf_unoverride(dbuf_dirty_record_t
*dr
)
904 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
905 blkptr_t
*bp
= &dr
->dt
.dl
.dr_overridden_by
;
906 uint64_t txg
= dr
->dr_txg
;
908 ASSERT(MUTEX_HELD(&db
->db_mtx
));
909 ASSERT(dr
->dt
.dl
.dr_override_state
!= DR_IN_DMU_SYNC
);
910 ASSERT(db
->db_level
== 0);
912 if (db
->db_blkid
== DMU_BONUS_BLKID
||
913 dr
->dt
.dl
.dr_override_state
== DR_NOT_OVERRIDDEN
)
916 ASSERT(db
->db_data_pending
!= dr
);
918 /* free this block */
919 if (!BP_IS_HOLE(bp
) && !dr
->dt
.dl
.dr_nopwrite
)
920 zio_free(db
->db_objset
->os_spa
, txg
, bp
);
922 dr
->dt
.dl
.dr_override_state
= DR_NOT_OVERRIDDEN
;
923 dr
->dt
.dl
.dr_nopwrite
= B_FALSE
;
926 * Release the already-written buffer, so we leave it in
927 * a consistent dirty state. Note that all callers are
928 * modifying the buffer, so they will immediately do
929 * another (redundant) arc_release(). Therefore, leave
930 * the buf thawed to save the effort of freezing &
931 * immediately re-thawing it.
933 arc_release(dr
->dt
.dl
.dr_data
, db
);
937 * Evict (if its unreferenced) or clear (if its referenced) any level-0
938 * data blocks in the free range, so that any future readers will find
941 * This is a no-op if the dataset is in the middle of an incremental
942 * receive; see comment below for details.
945 dbuf_free_range(dnode_t
*dn
, uint64_t start_blkid
, uint64_t end_blkid
,
948 dmu_buf_impl_t
*db_search
;
949 dmu_buf_impl_t
*db
, *db_next
;
950 uint64_t txg
= tx
->tx_txg
;
952 boolean_t freespill
=
953 (start_blkid
== DMU_SPILL_BLKID
|| end_blkid
== DMU_SPILL_BLKID
);
955 if (end_blkid
> dn
->dn_maxblkid
&& !freespill
)
956 end_blkid
= dn
->dn_maxblkid
;
957 dprintf_dnode(dn
, "start=%llu end=%llu\n", start_blkid
, end_blkid
);
959 db_search
= kmem_alloc(sizeof (dmu_buf_impl_t
), KM_SLEEP
);
960 db_search
->db_level
= 0;
961 db_search
->db_blkid
= start_blkid
;
962 db_search
->db_state
= DB_SEARCH
;
964 mutex_enter(&dn
->dn_dbufs_mtx
);
965 if (start_blkid
>= dn
->dn_unlisted_l0_blkid
&& !freespill
) {
966 /* There can't be any dbufs in this range; no need to search. */
968 db
= avl_find(&dn
->dn_dbufs
, db_search
, &where
);
969 ASSERT3P(db
, ==, NULL
);
970 db
= avl_nearest(&dn
->dn_dbufs
, where
, AVL_AFTER
);
971 ASSERT(db
== NULL
|| db
->db_level
> 0);
974 } else if (dmu_objset_is_receiving(dn
->dn_objset
)) {
976 * If we are receiving, we expect there to be no dbufs in
977 * the range to be freed, because receive modifies each
978 * block at most once, and in offset order. If this is
979 * not the case, it can lead to performance problems,
980 * so note that we unexpectedly took the slow path.
982 atomic_inc_64(&zfs_free_range_recv_miss
);
985 db
= avl_find(&dn
->dn_dbufs
, db_search
, &where
);
986 ASSERT3P(db
, ==, NULL
);
987 db
= avl_nearest(&dn
->dn_dbufs
, where
, AVL_AFTER
);
989 for (; db
!= NULL
; db
= db_next
) {
990 db_next
= AVL_NEXT(&dn
->dn_dbufs
, db
);
991 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
993 if (db
->db_level
!= 0 || db
->db_blkid
> end_blkid
) {
996 ASSERT3U(db
->db_blkid
, >=, start_blkid
);
998 /* found a level 0 buffer in the range */
999 mutex_enter(&db
->db_mtx
);
1000 if (dbuf_undirty(db
, tx
)) {
1001 /* mutex has been dropped and dbuf destroyed */
1005 if (db
->db_state
== DB_UNCACHED
||
1006 db
->db_state
== DB_NOFILL
||
1007 db
->db_state
== DB_EVICTING
) {
1008 ASSERT(db
->db
.db_data
== NULL
);
1009 mutex_exit(&db
->db_mtx
);
1012 if (db
->db_state
== DB_READ
|| db
->db_state
== DB_FILL
) {
1013 /* will be handled in dbuf_read_done or dbuf_rele */
1014 db
->db_freed_in_flight
= TRUE
;
1015 mutex_exit(&db
->db_mtx
);
1018 if (refcount_count(&db
->db_holds
) == 0) {
1023 /* The dbuf is referenced */
1025 if (db
->db_last_dirty
!= NULL
) {
1026 dbuf_dirty_record_t
*dr
= db
->db_last_dirty
;
1028 if (dr
->dr_txg
== txg
) {
1030 * This buffer is "in-use", re-adjust the file
1031 * size to reflect that this buffer may
1032 * contain new data when we sync.
1034 if (db
->db_blkid
!= DMU_SPILL_BLKID
&&
1035 db
->db_blkid
> dn
->dn_maxblkid
)
1036 dn
->dn_maxblkid
= db
->db_blkid
;
1037 dbuf_unoverride(dr
);
1040 * This dbuf is not dirty in the open context.
1041 * Either uncache it (if its not referenced in
1042 * the open context) or reset its contents to
1045 dbuf_fix_old_data(db
, txg
);
1048 /* clear the contents if its cached */
1049 if (db
->db_state
== DB_CACHED
) {
1050 ASSERT(db
->db
.db_data
!= NULL
);
1051 arc_release(db
->db_buf
, db
);
1052 bzero(db
->db
.db_data
, db
->db
.db_size
);
1053 arc_buf_freeze(db
->db_buf
);
1056 mutex_exit(&db
->db_mtx
);
1060 kmem_free(db_search
, sizeof (dmu_buf_impl_t
));
1061 mutex_exit(&dn
->dn_dbufs_mtx
);
1065 dbuf_block_freeable(dmu_buf_impl_t
*db
)
1067 dsl_dataset_t
*ds
= db
->db_objset
->os_dsl_dataset
;
1068 uint64_t birth_txg
= 0;
1071 * We don't need any locking to protect db_blkptr:
1072 * If it's syncing, then db_last_dirty will be set
1073 * so we'll ignore db_blkptr.
1075 * This logic ensures that only block births for
1076 * filled blocks are considered.
1078 ASSERT(MUTEX_HELD(&db
->db_mtx
));
1079 if (db
->db_last_dirty
&& (db
->db_blkptr
== NULL
||
1080 !BP_IS_HOLE(db
->db_blkptr
))) {
1081 birth_txg
= db
->db_last_dirty
->dr_txg
;
1082 } else if (db
->db_blkptr
!= NULL
&& !BP_IS_HOLE(db
->db_blkptr
)) {
1083 birth_txg
= db
->db_blkptr
->blk_birth
;
1087 * If this block don't exist or is in a snapshot, it can't be freed.
1088 * Don't pass the bp to dsl_dataset_block_freeable() since we
1089 * are holding the db_mtx lock and might deadlock if we are
1090 * prefetching a dedup-ed block.
1093 return (ds
== NULL
||
1094 dsl_dataset_block_freeable(ds
, NULL
, birth_txg
));
1100 dbuf_new_size(dmu_buf_impl_t
*db
, int size
, dmu_tx_t
*tx
)
1102 arc_buf_t
*buf
, *obuf
;
1103 int osize
= db
->db
.db_size
;
1104 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
1107 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1112 /* XXX does *this* func really need the lock? */
1113 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
1116 * This call to dmu_buf_will_dirty() with the dn_struct_rwlock held
1117 * is OK, because there can be no other references to the db
1118 * when we are changing its size, so no concurrent DB_FILL can
1122 * XXX we should be doing a dbuf_read, checking the return
1123 * value and returning that up to our callers
1125 dmu_buf_will_dirty(&db
->db
, tx
);
1127 /* create the data buffer for the new block */
1128 buf
= arc_buf_alloc(dn
->dn_objset
->os_spa
, size
, db
, type
);
1130 /* copy old block data to the new block */
1132 bcopy(obuf
->b_data
, buf
->b_data
, MIN(osize
, size
));
1133 /* zero the remainder */
1135 bzero((uint8_t *)buf
->b_data
+ osize
, size
- osize
);
1137 mutex_enter(&db
->db_mtx
);
1138 dbuf_set_data(db
, buf
);
1139 VERIFY(arc_buf_remove_ref(obuf
, db
));
1140 db
->db
.db_size
= size
;
1142 if (db
->db_level
== 0) {
1143 ASSERT3U(db
->db_last_dirty
->dr_txg
, ==, tx
->tx_txg
);
1144 db
->db_last_dirty
->dt
.dl
.dr_data
= buf
;
1146 mutex_exit(&db
->db_mtx
);
1148 dnode_willuse_space(dn
, size
-osize
, tx
);
1153 dbuf_release_bp(dmu_buf_impl_t
*db
)
1155 ASSERTV(objset_t
*os
= db
->db_objset
);
1157 ASSERT(dsl_pool_sync_context(dmu_objset_pool(os
)));
1158 ASSERT(arc_released(os
->os_phys_buf
) ||
1159 list_link_active(&os
->os_dsl_dataset
->ds_synced_link
));
1160 ASSERT(db
->db_parent
== NULL
|| arc_released(db
->db_parent
->db_buf
));
1162 (void) arc_release(db
->db_buf
, db
);
1165 dbuf_dirty_record_t
*
1166 dbuf_dirty(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
)
1170 dbuf_dirty_record_t
**drp
, *dr
;
1171 int drop_struct_lock
= FALSE
;
1172 boolean_t do_free_accounting
= B_FALSE
;
1173 int txgoff
= tx
->tx_txg
& TXG_MASK
;
1175 ASSERT(tx
->tx_txg
!= 0);
1176 ASSERT(!refcount_is_zero(&db
->db_holds
));
1177 DMU_TX_DIRTY_BUF(tx
, db
);
1182 * Shouldn't dirty a regular buffer in syncing context. Private
1183 * objects may be dirtied in syncing context, but only if they
1184 * were already pre-dirtied in open context.
1186 ASSERT(!dmu_tx_is_syncing(tx
) ||
1187 BP_IS_HOLE(dn
->dn_objset
->os_rootbp
) ||
1188 DMU_OBJECT_IS_SPECIAL(dn
->dn_object
) ||
1189 dn
->dn_objset
->os_dsl_dataset
== NULL
);
1191 * We make this assert for private objects as well, but after we
1192 * check if we're already dirty. They are allowed to re-dirty
1193 * in syncing context.
1195 ASSERT(dn
->dn_object
== DMU_META_DNODE_OBJECT
||
1196 dn
->dn_dirtyctx
== DN_UNDIRTIED
|| dn
->dn_dirtyctx
==
1197 (dmu_tx_is_syncing(tx
) ? DN_DIRTY_SYNC
: DN_DIRTY_OPEN
));
1199 mutex_enter(&db
->db_mtx
);
1201 * XXX make this true for indirects too? The problem is that
1202 * transactions created with dmu_tx_create_assigned() from
1203 * syncing context don't bother holding ahead.
1205 ASSERT(db
->db_level
!= 0 ||
1206 db
->db_state
== DB_CACHED
|| db
->db_state
== DB_FILL
||
1207 db
->db_state
== DB_NOFILL
);
1209 mutex_enter(&dn
->dn_mtx
);
1211 * Don't set dirtyctx to SYNC if we're just modifying this as we
1212 * initialize the objset.
1214 if (dn
->dn_dirtyctx
== DN_UNDIRTIED
&&
1215 !BP_IS_HOLE(dn
->dn_objset
->os_rootbp
)) {
1217 (dmu_tx_is_syncing(tx
) ? DN_DIRTY_SYNC
: DN_DIRTY_OPEN
);
1218 ASSERT(dn
->dn_dirtyctx_firstset
== NULL
);
1219 dn
->dn_dirtyctx_firstset
= kmem_alloc(1, KM_SLEEP
);
1221 mutex_exit(&dn
->dn_mtx
);
1223 if (db
->db_blkid
== DMU_SPILL_BLKID
)
1224 dn
->dn_have_spill
= B_TRUE
;
1227 * If this buffer is already dirty, we're done.
1229 drp
= &db
->db_last_dirty
;
1230 ASSERT(*drp
== NULL
|| (*drp
)->dr_txg
<= tx
->tx_txg
||
1231 db
->db
.db_object
== DMU_META_DNODE_OBJECT
);
1232 while ((dr
= *drp
) != NULL
&& dr
->dr_txg
> tx
->tx_txg
)
1234 if (dr
&& dr
->dr_txg
== tx
->tx_txg
) {
1237 if (db
->db_level
== 0 && db
->db_blkid
!= DMU_BONUS_BLKID
) {
1239 * If this buffer has already been written out,
1240 * we now need to reset its state.
1242 dbuf_unoverride(dr
);
1243 if (db
->db
.db_object
!= DMU_META_DNODE_OBJECT
&&
1244 db
->db_state
!= DB_NOFILL
)
1245 arc_buf_thaw(db
->db_buf
);
1247 mutex_exit(&db
->db_mtx
);
1252 * Only valid if not already dirty.
1254 ASSERT(dn
->dn_object
== 0 ||
1255 dn
->dn_dirtyctx
== DN_UNDIRTIED
|| dn
->dn_dirtyctx
==
1256 (dmu_tx_is_syncing(tx
) ? DN_DIRTY_SYNC
: DN_DIRTY_OPEN
));
1258 ASSERT3U(dn
->dn_nlevels
, >, db
->db_level
);
1259 ASSERT((dn
->dn_phys
->dn_nlevels
== 0 && db
->db_level
== 0) ||
1260 dn
->dn_phys
->dn_nlevels
> db
->db_level
||
1261 dn
->dn_next_nlevels
[txgoff
] > db
->db_level
||
1262 dn
->dn_next_nlevels
[(tx
->tx_txg
-1) & TXG_MASK
] > db
->db_level
||
1263 dn
->dn_next_nlevels
[(tx
->tx_txg
-2) & TXG_MASK
] > db
->db_level
);
1266 * We should only be dirtying in syncing context if it's the
1267 * mos or we're initializing the os or it's a special object.
1268 * However, we are allowed to dirty in syncing context provided
1269 * we already dirtied it in open context. Hence we must make
1270 * this assertion only if we're not already dirty.
1273 ASSERT(!dmu_tx_is_syncing(tx
) || DMU_OBJECT_IS_SPECIAL(dn
->dn_object
) ||
1274 os
->os_dsl_dataset
== NULL
|| BP_IS_HOLE(os
->os_rootbp
));
1275 ASSERT(db
->db
.db_size
!= 0);
1277 dprintf_dbuf(db
, "size=%llx\n", (u_longlong_t
)db
->db
.db_size
);
1279 if (db
->db_blkid
!= DMU_BONUS_BLKID
) {
1281 * Update the accounting.
1282 * Note: we delay "free accounting" until after we drop
1283 * the db_mtx. This keeps us from grabbing other locks
1284 * (and possibly deadlocking) in bp_get_dsize() while
1285 * also holding the db_mtx.
1287 dnode_willuse_space(dn
, db
->db
.db_size
, tx
);
1288 do_free_accounting
= dbuf_block_freeable(db
);
1292 * If this buffer is dirty in an old transaction group we need
1293 * to make a copy of it so that the changes we make in this
1294 * transaction group won't leak out when we sync the older txg.
1296 dr
= kmem_zalloc(sizeof (dbuf_dirty_record_t
), KM_SLEEP
);
1297 list_link_init(&dr
->dr_dirty_node
);
1298 if (db
->db_level
== 0) {
1299 void *data_old
= db
->db_buf
;
1301 if (db
->db_state
!= DB_NOFILL
) {
1302 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
1303 dbuf_fix_old_data(db
, tx
->tx_txg
);
1304 data_old
= db
->db
.db_data
;
1305 } else if (db
->db
.db_object
!= DMU_META_DNODE_OBJECT
) {
1307 * Release the data buffer from the cache so
1308 * that we can modify it without impacting
1309 * possible other users of this cached data
1310 * block. Note that indirect blocks and
1311 * private objects are not released until the
1312 * syncing state (since they are only modified
1315 arc_release(db
->db_buf
, db
);
1316 dbuf_fix_old_data(db
, tx
->tx_txg
);
1317 data_old
= db
->db_buf
;
1319 ASSERT(data_old
!= NULL
);
1321 dr
->dt
.dl
.dr_data
= data_old
;
1323 mutex_init(&dr
->dt
.di
.dr_mtx
, NULL
, MUTEX_DEFAULT
, NULL
);
1324 list_create(&dr
->dt
.di
.dr_children
,
1325 sizeof (dbuf_dirty_record_t
),
1326 offsetof(dbuf_dirty_record_t
, dr_dirty_node
));
1328 if (db
->db_blkid
!= DMU_BONUS_BLKID
&& os
->os_dsl_dataset
!= NULL
)
1329 dr
->dr_accounted
= db
->db
.db_size
;
1331 dr
->dr_txg
= tx
->tx_txg
;
1336 * We could have been freed_in_flight between the dbuf_noread
1337 * and dbuf_dirty. We win, as though the dbuf_noread() had
1338 * happened after the free.
1340 if (db
->db_level
== 0 && db
->db_blkid
!= DMU_BONUS_BLKID
&&
1341 db
->db_blkid
!= DMU_SPILL_BLKID
) {
1342 mutex_enter(&dn
->dn_mtx
);
1343 if (dn
->dn_free_ranges
[txgoff
] != NULL
) {
1344 range_tree_clear(dn
->dn_free_ranges
[txgoff
],
1347 mutex_exit(&dn
->dn_mtx
);
1348 db
->db_freed_in_flight
= FALSE
;
1352 * This buffer is now part of this txg
1354 dbuf_add_ref(db
, (void *)(uintptr_t)tx
->tx_txg
);
1355 db
->db_dirtycnt
+= 1;
1356 ASSERT3U(db
->db_dirtycnt
, <=, 3);
1358 mutex_exit(&db
->db_mtx
);
1360 if (db
->db_blkid
== DMU_BONUS_BLKID
||
1361 db
->db_blkid
== DMU_SPILL_BLKID
) {
1362 mutex_enter(&dn
->dn_mtx
);
1363 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
1364 list_insert_tail(&dn
->dn_dirty_records
[txgoff
], dr
);
1365 mutex_exit(&dn
->dn_mtx
);
1366 dnode_setdirty(dn
, tx
);
1369 } else if (do_free_accounting
) {
1370 blkptr_t
*bp
= db
->db_blkptr
;
1371 int64_t willfree
= (bp
&& !BP_IS_HOLE(bp
)) ?
1372 bp_get_dsize(os
->os_spa
, bp
) : db
->db
.db_size
;
1374 * This is only a guess -- if the dbuf is dirty
1375 * in a previous txg, we don't know how much
1376 * space it will use on disk yet. We should
1377 * really have the struct_rwlock to access
1378 * db_blkptr, but since this is just a guess,
1379 * it's OK if we get an odd answer.
1381 ddt_prefetch(os
->os_spa
, bp
);
1382 dnode_willuse_space(dn
, -willfree
, tx
);
1385 if (!RW_WRITE_HELD(&dn
->dn_struct_rwlock
)) {
1386 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
1387 drop_struct_lock
= TRUE
;
1390 if (db
->db_level
== 0) {
1391 dnode_new_blkid(dn
, db
->db_blkid
, tx
, drop_struct_lock
);
1392 ASSERT(dn
->dn_maxblkid
>= db
->db_blkid
);
1395 if (db
->db_level
+1 < dn
->dn_nlevels
) {
1396 dmu_buf_impl_t
*parent
= db
->db_parent
;
1397 dbuf_dirty_record_t
*di
;
1398 int parent_held
= FALSE
;
1400 if (db
->db_parent
== NULL
|| db
->db_parent
== dn
->dn_dbuf
) {
1401 int epbs
= dn
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
1403 parent
= dbuf_hold_level(dn
, db
->db_level
+1,
1404 db
->db_blkid
>> epbs
, FTAG
);
1405 ASSERT(parent
!= NULL
);
1408 if (drop_struct_lock
)
1409 rw_exit(&dn
->dn_struct_rwlock
);
1410 ASSERT3U(db
->db_level
+1, ==, parent
->db_level
);
1411 di
= dbuf_dirty(parent
, tx
);
1413 dbuf_rele(parent
, FTAG
);
1415 mutex_enter(&db
->db_mtx
);
1417 * Since we've dropped the mutex, it's possible that
1418 * dbuf_undirty() might have changed this out from under us.
1420 if (db
->db_last_dirty
== dr
||
1421 dn
->dn_object
== DMU_META_DNODE_OBJECT
) {
1422 mutex_enter(&di
->dt
.di
.dr_mtx
);
1423 ASSERT3U(di
->dr_txg
, ==, tx
->tx_txg
);
1424 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
1425 list_insert_tail(&di
->dt
.di
.dr_children
, dr
);
1426 mutex_exit(&di
->dt
.di
.dr_mtx
);
1429 mutex_exit(&db
->db_mtx
);
1431 ASSERT(db
->db_level
+1 == dn
->dn_nlevels
);
1432 ASSERT(db
->db_blkid
< dn
->dn_nblkptr
);
1433 ASSERT(db
->db_parent
== NULL
|| db
->db_parent
== dn
->dn_dbuf
);
1434 mutex_enter(&dn
->dn_mtx
);
1435 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
1436 list_insert_tail(&dn
->dn_dirty_records
[txgoff
], dr
);
1437 mutex_exit(&dn
->dn_mtx
);
1438 if (drop_struct_lock
)
1439 rw_exit(&dn
->dn_struct_rwlock
);
1442 dnode_setdirty(dn
, tx
);
1448 * Undirty a buffer in the transaction group referenced by the given
1449 * transaction. Return whether this evicted the dbuf.
1452 dbuf_undirty(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
)
1455 uint64_t txg
= tx
->tx_txg
;
1456 dbuf_dirty_record_t
*dr
, **drp
;
1461 * Due to our use of dn_nlevels below, this can only be called
1462 * in open context, unless we are operating on the MOS.
1463 * From syncing context, dn_nlevels may be different from the
1464 * dn_nlevels used when dbuf was dirtied.
1466 ASSERT(db
->db_objset
==
1467 dmu_objset_pool(db
->db_objset
)->dp_meta_objset
||
1468 txg
!= spa_syncing_txg(dmu_objset_spa(db
->db_objset
)));
1469 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1470 ASSERT0(db
->db_level
);
1471 ASSERT(MUTEX_HELD(&db
->db_mtx
));
1474 * If this buffer is not dirty, we're done.
1476 for (drp
= &db
->db_last_dirty
; (dr
= *drp
) != NULL
; drp
= &dr
->dr_next
)
1477 if (dr
->dr_txg
<= txg
)
1479 if (dr
== NULL
|| dr
->dr_txg
< txg
)
1481 ASSERT(dr
->dr_txg
== txg
);
1482 ASSERT(dr
->dr_dbuf
== db
);
1487 dprintf_dbuf(db
, "size=%llx\n", (u_longlong_t
)db
->db
.db_size
);
1489 ASSERT(db
->db
.db_size
!= 0);
1491 dsl_pool_undirty_space(dmu_objset_pool(dn
->dn_objset
),
1492 dr
->dr_accounted
, txg
);
1497 * Note that there are three places in dbuf_dirty()
1498 * where this dirty record may be put on a list.
1499 * Make sure to do a list_remove corresponding to
1500 * every one of those list_insert calls.
1502 if (dr
->dr_parent
) {
1503 mutex_enter(&dr
->dr_parent
->dt
.di
.dr_mtx
);
1504 list_remove(&dr
->dr_parent
->dt
.di
.dr_children
, dr
);
1505 mutex_exit(&dr
->dr_parent
->dt
.di
.dr_mtx
);
1506 } else if (db
->db_blkid
== DMU_SPILL_BLKID
||
1507 db
->db_level
+ 1 == dn
->dn_nlevels
) {
1508 ASSERT(db
->db_blkptr
== NULL
|| db
->db_parent
== dn
->dn_dbuf
);
1509 mutex_enter(&dn
->dn_mtx
);
1510 list_remove(&dn
->dn_dirty_records
[txg
& TXG_MASK
], dr
);
1511 mutex_exit(&dn
->dn_mtx
);
1515 if (db
->db_state
!= DB_NOFILL
) {
1516 dbuf_unoverride(dr
);
1518 ASSERT(db
->db_buf
!= NULL
);
1519 ASSERT(dr
->dt
.dl
.dr_data
!= NULL
);
1520 if (dr
->dt
.dl
.dr_data
!= db
->db_buf
)
1521 VERIFY(arc_buf_remove_ref(dr
->dt
.dl
.dr_data
, db
));
1524 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
1526 ASSERT(db
->db_dirtycnt
> 0);
1527 db
->db_dirtycnt
-= 1;
1529 if (refcount_remove(&db
->db_holds
, (void *)(uintptr_t)txg
) == 0) {
1530 arc_buf_t
*buf
= db
->db_buf
;
1532 ASSERT(db
->db_state
== DB_NOFILL
|| arc_released(buf
));
1533 dbuf_clear_data(db
);
1534 VERIFY(arc_buf_remove_ref(buf
, db
));
1543 dmu_buf_will_dirty(dmu_buf_t
*db_fake
, dmu_tx_t
*tx
)
1545 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
1546 int rf
= DB_RF_MUST_SUCCEED
| DB_RF_NOPREFETCH
;
1548 ASSERT(tx
->tx_txg
!= 0);
1549 ASSERT(!refcount_is_zero(&db
->db_holds
));
1552 if (RW_WRITE_HELD(&DB_DNODE(db
)->dn_struct_rwlock
))
1553 rf
|= DB_RF_HAVESTRUCT
;
1555 (void) dbuf_read(db
, NULL
, rf
);
1556 (void) dbuf_dirty(db
, tx
);
1560 dmu_buf_will_not_fill(dmu_buf_t
*db_fake
, dmu_tx_t
*tx
)
1562 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
1564 db
->db_state
= DB_NOFILL
;
1566 dmu_buf_will_fill(db_fake
, tx
);
1570 dmu_buf_will_fill(dmu_buf_t
*db_fake
, dmu_tx_t
*tx
)
1572 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
1574 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1575 ASSERT(tx
->tx_txg
!= 0);
1576 ASSERT(db
->db_level
== 0);
1577 ASSERT(!refcount_is_zero(&db
->db_holds
));
1579 ASSERT(db
->db
.db_object
!= DMU_META_DNODE_OBJECT
||
1580 dmu_tx_private_ok(tx
));
1583 (void) dbuf_dirty(db
, tx
);
1586 #pragma weak dmu_buf_fill_done = dbuf_fill_done
1589 dbuf_fill_done(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
)
1591 mutex_enter(&db
->db_mtx
);
1594 if (db
->db_state
== DB_FILL
) {
1595 if (db
->db_level
== 0 && db
->db_freed_in_flight
) {
1596 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1597 /* we were freed while filling */
1598 /* XXX dbuf_undirty? */
1599 bzero(db
->db
.db_data
, db
->db
.db_size
);
1600 db
->db_freed_in_flight
= FALSE
;
1602 db
->db_state
= DB_CACHED
;
1603 cv_broadcast(&db
->db_changed
);
1605 mutex_exit(&db
->db_mtx
);
1609 dmu_buf_write_embedded(dmu_buf_t
*dbuf
, void *data
,
1610 bp_embedded_type_t etype
, enum zio_compress comp
,
1611 int uncompressed_size
, int compressed_size
, int byteorder
,
1614 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)dbuf
;
1615 struct dirty_leaf
*dl
;
1616 dmu_object_type_t type
;
1619 type
= DB_DNODE(db
)->dn_type
;
1622 ASSERT0(db
->db_level
);
1623 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1625 dmu_buf_will_not_fill(dbuf
, tx
);
1627 ASSERT3U(db
->db_last_dirty
->dr_txg
, ==, tx
->tx_txg
);
1628 dl
= &db
->db_last_dirty
->dt
.dl
;
1629 encode_embedded_bp_compressed(&dl
->dr_overridden_by
,
1630 data
, comp
, uncompressed_size
, compressed_size
);
1631 BPE_SET_ETYPE(&dl
->dr_overridden_by
, etype
);
1632 BP_SET_TYPE(&dl
->dr_overridden_by
, type
);
1633 BP_SET_LEVEL(&dl
->dr_overridden_by
, 0);
1634 BP_SET_BYTEORDER(&dl
->dr_overridden_by
, byteorder
);
1636 dl
->dr_override_state
= DR_OVERRIDDEN
;
1637 dl
->dr_overridden_by
.blk_birth
= db
->db_last_dirty
->dr_txg
;
1641 * Directly assign a provided arc buf to a given dbuf if it's not referenced
1642 * by anybody except our caller. Otherwise copy arcbuf's contents to dbuf.
1645 dbuf_assign_arcbuf(dmu_buf_impl_t
*db
, arc_buf_t
*buf
, dmu_tx_t
*tx
)
1647 ASSERT(!refcount_is_zero(&db
->db_holds
));
1648 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1649 ASSERT(db
->db_level
== 0);
1650 ASSERT(DBUF_GET_BUFC_TYPE(db
) == ARC_BUFC_DATA
);
1651 ASSERT(buf
!= NULL
);
1652 ASSERT(arc_buf_size(buf
) == db
->db
.db_size
);
1653 ASSERT(tx
->tx_txg
!= 0);
1655 arc_return_buf(buf
, db
);
1656 ASSERT(arc_released(buf
));
1658 mutex_enter(&db
->db_mtx
);
1660 while (db
->db_state
== DB_READ
|| db
->db_state
== DB_FILL
)
1661 cv_wait(&db
->db_changed
, &db
->db_mtx
);
1663 ASSERT(db
->db_state
== DB_CACHED
|| db
->db_state
== DB_UNCACHED
);
1665 if (db
->db_state
== DB_CACHED
&&
1666 refcount_count(&db
->db_holds
) - 1 > db
->db_dirtycnt
) {
1667 mutex_exit(&db
->db_mtx
);
1668 (void) dbuf_dirty(db
, tx
);
1669 bcopy(buf
->b_data
, db
->db
.db_data
, db
->db
.db_size
);
1670 VERIFY(arc_buf_remove_ref(buf
, db
));
1671 xuio_stat_wbuf_copied();
1675 xuio_stat_wbuf_nocopy();
1676 if (db
->db_state
== DB_CACHED
) {
1677 dbuf_dirty_record_t
*dr
= db
->db_last_dirty
;
1679 ASSERT(db
->db_buf
!= NULL
);
1680 if (dr
!= NULL
&& dr
->dr_txg
== tx
->tx_txg
) {
1681 ASSERT(dr
->dt
.dl
.dr_data
== db
->db_buf
);
1682 if (!arc_released(db
->db_buf
)) {
1683 ASSERT(dr
->dt
.dl
.dr_override_state
==
1685 arc_release(db
->db_buf
, db
);
1687 dr
->dt
.dl
.dr_data
= buf
;
1688 VERIFY(arc_buf_remove_ref(db
->db_buf
, db
));
1689 } else if (dr
== NULL
|| dr
->dt
.dl
.dr_data
!= db
->db_buf
) {
1690 arc_release(db
->db_buf
, db
);
1691 VERIFY(arc_buf_remove_ref(db
->db_buf
, db
));
1695 ASSERT(db
->db_buf
== NULL
);
1696 dbuf_set_data(db
, buf
);
1697 db
->db_state
= DB_FILL
;
1698 mutex_exit(&db
->db_mtx
);
1699 (void) dbuf_dirty(db
, tx
);
1700 dmu_buf_fill_done(&db
->db
, tx
);
1704 * "Clear" the contents of this dbuf. This will mark the dbuf
1705 * EVICTING and clear *most* of its references. Unfortunately,
1706 * when we are not holding the dn_dbufs_mtx, we can't clear the
1707 * entry in the dn_dbufs list. We have to wait until dbuf_destroy()
1708 * in this case. For callers from the DMU we will usually see:
1709 * dbuf_clear()->arc_clear_callback()->dbuf_do_evict()->dbuf_destroy()
1710 * For the arc callback, we will usually see:
1711 * dbuf_do_evict()->dbuf_clear();dbuf_destroy()
1712 * Sometimes, though, we will get a mix of these two:
1713 * DMU: dbuf_clear()->arc_clear_callback()
1714 * ARC: dbuf_do_evict()->dbuf_destroy()
1716 * This routine will dissociate the dbuf from the arc, by calling
1717 * arc_clear_callback(), but will not evict the data from the ARC.
1720 dbuf_clear(dmu_buf_impl_t
*db
)
1723 dmu_buf_impl_t
*parent
= db
->db_parent
;
1724 dmu_buf_impl_t
*dndb
;
1725 boolean_t dbuf_gone
= B_FALSE
;
1727 ASSERT(MUTEX_HELD(&db
->db_mtx
));
1728 ASSERT(refcount_is_zero(&db
->db_holds
));
1730 dbuf_evict_user(db
);
1732 if (db
->db_state
== DB_CACHED
) {
1733 ASSERT(db
->db
.db_data
!= NULL
);
1734 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
1735 zio_buf_free(db
->db
.db_data
, DN_MAX_BONUSLEN
);
1736 arc_space_return(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
1738 db
->db
.db_data
= NULL
;
1739 db
->db_state
= DB_UNCACHED
;
1742 ASSERT(db
->db_state
== DB_UNCACHED
|| db
->db_state
== DB_NOFILL
);
1743 ASSERT(db
->db_data_pending
== NULL
);
1745 db
->db_state
= DB_EVICTING
;
1746 db
->db_blkptr
= NULL
;
1751 if (db
->db_blkid
!= DMU_BONUS_BLKID
&& MUTEX_HELD(&dn
->dn_dbufs_mtx
)) {
1752 avl_remove(&dn
->dn_dbufs
, db
);
1753 atomic_dec_32(&dn
->dn_dbufs_count
);
1757 * Decrementing the dbuf count means that the hold corresponding
1758 * to the removed dbuf is no longer discounted in dnode_move(),
1759 * so the dnode cannot be moved until after we release the hold.
1760 * The membar_producer() ensures visibility of the decremented
1761 * value in dnode_move(), since DB_DNODE_EXIT doesn't actually
1765 db
->db_dnode_handle
= NULL
;
1771 dbuf_gone
= arc_clear_callback(db
->db_buf
);
1774 mutex_exit(&db
->db_mtx
);
1777 * If this dbuf is referenced from an indirect dbuf,
1778 * decrement the ref count on the indirect dbuf.
1780 if (parent
&& parent
!= dndb
)
1781 dbuf_rele(parent
, db
);
1784 __attribute__((always_inline
))
1786 dbuf_findbp(dnode_t
*dn
, int level
, uint64_t blkid
, int fail_sparse
,
1787 dmu_buf_impl_t
**parentp
, blkptr_t
**bpp
, struct dbuf_hold_impl_data
*dh
)
1794 ASSERT(blkid
!= DMU_BONUS_BLKID
);
1796 if (blkid
== DMU_SPILL_BLKID
) {
1797 mutex_enter(&dn
->dn_mtx
);
1798 if (dn
->dn_have_spill
&&
1799 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
))
1800 *bpp
= &dn
->dn_phys
->dn_spill
;
1803 dbuf_add_ref(dn
->dn_dbuf
, NULL
);
1804 *parentp
= dn
->dn_dbuf
;
1805 mutex_exit(&dn
->dn_mtx
);
1809 if (dn
->dn_phys
->dn_nlevels
== 0)
1812 nlevels
= dn
->dn_phys
->dn_nlevels
;
1814 epbs
= dn
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
1816 ASSERT3U(level
* epbs
, <, 64);
1817 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
1818 if (level
>= nlevels
||
1819 (blkid
> (dn
->dn_phys
->dn_maxblkid
>> (level
* epbs
)))) {
1820 /* the buffer has no parent yet */
1821 return (SET_ERROR(ENOENT
));
1822 } else if (level
< nlevels
-1) {
1823 /* this block is referenced from an indirect block */
1826 err
= dbuf_hold_impl(dn
, level
+1, blkid
>> epbs
,
1827 fail_sparse
, NULL
, parentp
);
1829 __dbuf_hold_impl_init(dh
+ 1, dn
, dh
->dh_level
+ 1,
1830 blkid
>> epbs
, fail_sparse
, NULL
,
1831 parentp
, dh
->dh_depth
+ 1);
1832 err
= __dbuf_hold_impl(dh
+ 1);
1836 err
= dbuf_read(*parentp
, NULL
,
1837 (DB_RF_HAVESTRUCT
| DB_RF_NOPREFETCH
| DB_RF_CANFAIL
));
1839 dbuf_rele(*parentp
, NULL
);
1843 *bpp
= ((blkptr_t
*)(*parentp
)->db
.db_data
) +
1844 (blkid
& ((1ULL << epbs
) - 1));
1847 /* the block is referenced from the dnode */
1848 ASSERT3U(level
, ==, nlevels
-1);
1849 ASSERT(dn
->dn_phys
->dn_nblkptr
== 0 ||
1850 blkid
< dn
->dn_phys
->dn_nblkptr
);
1852 dbuf_add_ref(dn
->dn_dbuf
, NULL
);
1853 *parentp
= dn
->dn_dbuf
;
1855 *bpp
= &dn
->dn_phys
->dn_blkptr
[blkid
];
1860 static dmu_buf_impl_t
*
1861 dbuf_create(dnode_t
*dn
, uint8_t level
, uint64_t blkid
,
1862 dmu_buf_impl_t
*parent
, blkptr_t
*blkptr
)
1864 objset_t
*os
= dn
->dn_objset
;
1865 dmu_buf_impl_t
*db
, *odb
;
1867 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
1868 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
1870 db
= kmem_cache_alloc(dbuf_cache
, KM_SLEEP
);
1873 db
->db
.db_object
= dn
->dn_object
;
1874 db
->db_level
= level
;
1875 db
->db_blkid
= blkid
;
1876 db
->db_last_dirty
= NULL
;
1877 db
->db_dirtycnt
= 0;
1878 db
->db_dnode_handle
= dn
->dn_handle
;
1879 db
->db_parent
= parent
;
1880 db
->db_blkptr
= blkptr
;
1883 db
->db_user_immediate_evict
= FALSE
;
1884 db
->db_freed_in_flight
= FALSE
;
1885 db
->db_pending_evict
= FALSE
;
1887 if (blkid
== DMU_BONUS_BLKID
) {
1888 ASSERT3P(parent
, ==, dn
->dn_dbuf
);
1889 db
->db
.db_size
= DN_MAX_BONUSLEN
-
1890 (dn
->dn_nblkptr
-1) * sizeof (blkptr_t
);
1891 ASSERT3U(db
->db
.db_size
, >=, dn
->dn_bonuslen
);
1892 db
->db
.db_offset
= DMU_BONUS_BLKID
;
1893 db
->db_state
= DB_UNCACHED
;
1894 /* the bonus dbuf is not placed in the hash table */
1895 arc_space_consume(sizeof (dmu_buf_impl_t
), ARC_SPACE_OTHER
);
1897 } else if (blkid
== DMU_SPILL_BLKID
) {
1898 db
->db
.db_size
= (blkptr
!= NULL
) ?
1899 BP_GET_LSIZE(blkptr
) : SPA_MINBLOCKSIZE
;
1900 db
->db
.db_offset
= 0;
1903 db
->db_level
? 1 << dn
->dn_indblkshift
: dn
->dn_datablksz
;
1904 db
->db
.db_size
= blocksize
;
1905 db
->db
.db_offset
= db
->db_blkid
* blocksize
;
1909 * Hold the dn_dbufs_mtx while we get the new dbuf
1910 * in the hash table *and* added to the dbufs list.
1911 * This prevents a possible deadlock with someone
1912 * trying to look up this dbuf before its added to the
1915 mutex_enter(&dn
->dn_dbufs_mtx
);
1916 db
->db_state
= DB_EVICTING
;
1917 if ((odb
= dbuf_hash_insert(db
)) != NULL
) {
1918 /* someone else inserted it first */
1919 kmem_cache_free(dbuf_cache
, db
);
1920 mutex_exit(&dn
->dn_dbufs_mtx
);
1923 avl_add(&dn
->dn_dbufs
, db
);
1924 if (db
->db_level
== 0 && db
->db_blkid
>=
1925 dn
->dn_unlisted_l0_blkid
)
1926 dn
->dn_unlisted_l0_blkid
= db
->db_blkid
+ 1;
1927 db
->db_state
= DB_UNCACHED
;
1928 mutex_exit(&dn
->dn_dbufs_mtx
);
1929 arc_space_consume(sizeof (dmu_buf_impl_t
), ARC_SPACE_OTHER
);
1931 if (parent
&& parent
!= dn
->dn_dbuf
)
1932 dbuf_add_ref(parent
, db
);
1934 ASSERT(dn
->dn_object
== DMU_META_DNODE_OBJECT
||
1935 refcount_count(&dn
->dn_holds
) > 0);
1936 (void) refcount_add(&dn
->dn_holds
, db
);
1937 atomic_inc_32(&dn
->dn_dbufs_count
);
1939 dprintf_dbuf(db
, "db=%p\n", db
);
1945 dbuf_do_evict(void *private)
1947 dmu_buf_impl_t
*db
= private;
1949 if (!MUTEX_HELD(&db
->db_mtx
))
1950 mutex_enter(&db
->db_mtx
);
1952 ASSERT(refcount_is_zero(&db
->db_holds
));
1954 if (db
->db_state
!= DB_EVICTING
) {
1955 ASSERT(db
->db_state
== DB_CACHED
);
1960 mutex_exit(&db
->db_mtx
);
1967 dbuf_destroy(dmu_buf_impl_t
*db
)
1969 ASSERT(refcount_is_zero(&db
->db_holds
));
1971 if (db
->db_blkid
!= DMU_BONUS_BLKID
) {
1973 * If this dbuf is still on the dn_dbufs list,
1974 * remove it from that list.
1976 if (db
->db_dnode_handle
!= NULL
) {
1981 mutex_enter(&dn
->dn_dbufs_mtx
);
1982 avl_remove(&dn
->dn_dbufs
, db
);
1983 atomic_dec_32(&dn
->dn_dbufs_count
);
1984 mutex_exit(&dn
->dn_dbufs_mtx
);
1987 * Decrementing the dbuf count means that the hold
1988 * corresponding to the removed dbuf is no longer
1989 * discounted in dnode_move(), so the dnode cannot be
1990 * moved until after we release the hold.
1993 db
->db_dnode_handle
= NULL
;
1995 dbuf_hash_remove(db
);
1997 db
->db_parent
= NULL
;
2000 ASSERT(db
->db
.db_data
== NULL
);
2001 ASSERT(db
->db_hash_next
== NULL
);
2002 ASSERT(db
->db_blkptr
== NULL
);
2003 ASSERT(db
->db_data_pending
== NULL
);
2005 kmem_cache_free(dbuf_cache
, db
);
2006 arc_space_return(sizeof (dmu_buf_impl_t
), ARC_SPACE_OTHER
);
2010 dbuf_prefetch(dnode_t
*dn
, uint64_t blkid
, zio_priority_t prio
)
2012 dmu_buf_impl_t
*db
= NULL
;
2013 blkptr_t
*bp
= NULL
;
2015 ASSERT(blkid
!= DMU_BONUS_BLKID
);
2016 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
2018 if (dnode_block_freed(dn
, blkid
))
2021 /* dbuf_find() returns with db_mtx held */
2022 if ((db
= dbuf_find(dn
->dn_objset
, dn
->dn_object
, 0, blkid
))) {
2024 * This dbuf is already in the cache. We assume that
2025 * it is already CACHED, or else about to be either
2028 mutex_exit(&db
->db_mtx
);
2032 if (dbuf_findbp(dn
, 0, blkid
, TRUE
, &db
, &bp
, NULL
) == 0) {
2033 if (bp
&& !BP_IS_HOLE(bp
) && !BP_IS_EMBEDDED(bp
)) {
2034 dsl_dataset_t
*ds
= dn
->dn_objset
->os_dsl_dataset
;
2035 arc_flags_t aflags
=
2036 ARC_FLAG_NOWAIT
| ARC_FLAG_PREFETCH
;
2037 zbookmark_phys_t zb
;
2039 SET_BOOKMARK(&zb
, ds
? ds
->ds_object
: DMU_META_OBJSET
,
2040 dn
->dn_object
, 0, blkid
);
2042 (void) arc_read(NULL
, dn
->dn_objset
->os_spa
,
2043 bp
, NULL
, NULL
, prio
,
2044 ZIO_FLAG_CANFAIL
| ZIO_FLAG_SPECULATIVE
,
2048 dbuf_rele(db
, NULL
);
2052 #define DBUF_HOLD_IMPL_MAX_DEPTH 20
2055 * Returns with db_holds incremented, and db_mtx not held.
2056 * Note: dn_struct_rwlock must be held.
2059 __dbuf_hold_impl(struct dbuf_hold_impl_data
*dh
)
2061 ASSERT3S(dh
->dh_depth
, <, DBUF_HOLD_IMPL_MAX_DEPTH
);
2062 dh
->dh_parent
= NULL
;
2064 ASSERT(dh
->dh_blkid
!= DMU_BONUS_BLKID
);
2065 ASSERT(RW_LOCK_HELD(&dh
->dh_dn
->dn_struct_rwlock
));
2066 ASSERT3U(dh
->dh_dn
->dn_nlevels
, >, dh
->dh_level
);
2068 *(dh
->dh_dbp
) = NULL
;
2070 /* dbuf_find() returns with db_mtx held */
2071 dh
->dh_db
= dbuf_find(dh
->dh_dn
->dn_objset
, dh
->dh_dn
->dn_object
,
2072 dh
->dh_level
, dh
->dh_blkid
);
2074 if (dh
->dh_db
== NULL
) {
2077 ASSERT3P(dh
->dh_parent
, ==, NULL
);
2078 dh
->dh_err
= dbuf_findbp(dh
->dh_dn
, dh
->dh_level
, dh
->dh_blkid
,
2079 dh
->dh_fail_sparse
, &dh
->dh_parent
,
2081 if (dh
->dh_fail_sparse
) {
2082 if (dh
->dh_err
== 0 &&
2083 dh
->dh_bp
&& BP_IS_HOLE(dh
->dh_bp
))
2084 dh
->dh_err
= SET_ERROR(ENOENT
);
2087 dbuf_rele(dh
->dh_parent
, NULL
);
2088 return (dh
->dh_err
);
2091 if (dh
->dh_err
&& dh
->dh_err
!= ENOENT
)
2092 return (dh
->dh_err
);
2093 dh
->dh_db
= dbuf_create(dh
->dh_dn
, dh
->dh_level
, dh
->dh_blkid
,
2094 dh
->dh_parent
, dh
->dh_bp
);
2097 if (dh
->dh_db
->db_buf
&& refcount_is_zero(&dh
->dh_db
->db_holds
)) {
2098 arc_buf_add_ref(dh
->dh_db
->db_buf
, dh
->dh_db
);
2099 if (dh
->dh_db
->db_buf
->b_data
== NULL
) {
2100 dbuf_clear(dh
->dh_db
);
2101 if (dh
->dh_parent
) {
2102 dbuf_rele(dh
->dh_parent
, NULL
);
2103 dh
->dh_parent
= NULL
;
2107 ASSERT3P(dh
->dh_db
->db
.db_data
, ==, dh
->dh_db
->db_buf
->b_data
);
2110 ASSERT(dh
->dh_db
->db_buf
== NULL
|| arc_referenced(dh
->dh_db
->db_buf
));
2113 * If this buffer is currently syncing out, and we are are
2114 * still referencing it from db_data, we need to make a copy
2115 * of it in case we decide we want to dirty it again in this txg.
2117 if (dh
->dh_db
->db_level
== 0 &&
2118 dh
->dh_db
->db_blkid
!= DMU_BONUS_BLKID
&&
2119 dh
->dh_dn
->dn_object
!= DMU_META_DNODE_OBJECT
&&
2120 dh
->dh_db
->db_state
== DB_CACHED
&& dh
->dh_db
->db_data_pending
) {
2121 dh
->dh_dr
= dh
->dh_db
->db_data_pending
;
2123 if (dh
->dh_dr
->dt
.dl
.dr_data
== dh
->dh_db
->db_buf
) {
2124 dh
->dh_type
= DBUF_GET_BUFC_TYPE(dh
->dh_db
);
2126 dbuf_set_data(dh
->dh_db
,
2127 arc_buf_alloc(dh
->dh_dn
->dn_objset
->os_spa
,
2128 dh
->dh_db
->db
.db_size
, dh
->dh_db
, dh
->dh_type
));
2129 bcopy(dh
->dh_dr
->dt
.dl
.dr_data
->b_data
,
2130 dh
->dh_db
->db
.db_data
, dh
->dh_db
->db
.db_size
);
2134 (void) refcount_add(&dh
->dh_db
->db_holds
, dh
->dh_tag
);
2135 DBUF_VERIFY(dh
->dh_db
);
2136 mutex_exit(&dh
->dh_db
->db_mtx
);
2138 /* NOTE: we can't rele the parent until after we drop the db_mtx */
2140 dbuf_rele(dh
->dh_parent
, NULL
);
2142 ASSERT3P(DB_DNODE(dh
->dh_db
), ==, dh
->dh_dn
);
2143 ASSERT3U(dh
->dh_db
->db_blkid
, ==, dh
->dh_blkid
);
2144 ASSERT3U(dh
->dh_db
->db_level
, ==, dh
->dh_level
);
2145 *(dh
->dh_dbp
) = dh
->dh_db
;
2151 * The following code preserves the recursive function dbuf_hold_impl()
2152 * but moves the local variables AND function arguments to the heap to
2153 * minimize the stack frame size. Enough space is initially allocated
2154 * on the stack for 20 levels of recursion.
2157 dbuf_hold_impl(dnode_t
*dn
, uint8_t level
, uint64_t blkid
, int fail_sparse
,
2158 void *tag
, dmu_buf_impl_t
**dbp
)
2160 struct dbuf_hold_impl_data
*dh
;
2163 dh
= kmem_zalloc(sizeof (struct dbuf_hold_impl_data
) *
2164 DBUF_HOLD_IMPL_MAX_DEPTH
, KM_SLEEP
);
2165 __dbuf_hold_impl_init(dh
, dn
, level
, blkid
, fail_sparse
, tag
, dbp
, 0);
2167 error
= __dbuf_hold_impl(dh
);
2169 kmem_free(dh
, sizeof (struct dbuf_hold_impl_data
) *
2170 DBUF_HOLD_IMPL_MAX_DEPTH
);
2176 __dbuf_hold_impl_init(struct dbuf_hold_impl_data
*dh
,
2177 dnode_t
*dn
, uint8_t level
, uint64_t blkid
, int fail_sparse
,
2178 void *tag
, dmu_buf_impl_t
**dbp
, int depth
)
2181 dh
->dh_level
= level
;
2182 dh
->dh_blkid
= blkid
;
2183 dh
->dh_fail_sparse
= fail_sparse
;
2186 dh
->dh_depth
= depth
;
2190 dbuf_hold(dnode_t
*dn
, uint64_t blkid
, void *tag
)
2193 int err
= dbuf_hold_impl(dn
, 0, blkid
, FALSE
, tag
, &db
);
2194 return (err
? NULL
: db
);
2198 dbuf_hold_level(dnode_t
*dn
, int level
, uint64_t blkid
, void *tag
)
2201 int err
= dbuf_hold_impl(dn
, level
, blkid
, FALSE
, tag
, &db
);
2202 return (err
? NULL
: db
);
2206 dbuf_create_bonus(dnode_t
*dn
)
2208 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
2210 ASSERT(dn
->dn_bonus
== NULL
);
2211 dn
->dn_bonus
= dbuf_create(dn
, 0, DMU_BONUS_BLKID
, dn
->dn_dbuf
, NULL
);
2215 dbuf_spill_set_blksz(dmu_buf_t
*db_fake
, uint64_t blksz
, dmu_tx_t
*tx
)
2217 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2220 if (db
->db_blkid
!= DMU_SPILL_BLKID
)
2221 return (SET_ERROR(ENOTSUP
));
2223 blksz
= SPA_MINBLOCKSIZE
;
2224 ASSERT3U(blksz
, <=, spa_maxblocksize(dmu_objset_spa(db
->db_objset
)));
2225 blksz
= P2ROUNDUP(blksz
, SPA_MINBLOCKSIZE
);
2229 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
2230 dbuf_new_size(db
, blksz
, tx
);
2231 rw_exit(&dn
->dn_struct_rwlock
);
2238 dbuf_rm_spill(dnode_t
*dn
, dmu_tx_t
*tx
)
2240 dbuf_free_range(dn
, DMU_SPILL_BLKID
, DMU_SPILL_BLKID
, tx
);
2243 #pragma weak dmu_buf_add_ref = dbuf_add_ref
2245 dbuf_add_ref(dmu_buf_impl_t
*db
, void *tag
)
2247 VERIFY(refcount_add(&db
->db_holds
, tag
) > 1);
2250 #pragma weak dmu_buf_try_add_ref = dbuf_try_add_ref
2252 dbuf_try_add_ref(dmu_buf_t
*db_fake
, objset_t
*os
, uint64_t obj
, uint64_t blkid
,
2255 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2256 dmu_buf_impl_t
*found_db
;
2257 boolean_t result
= B_FALSE
;
2259 if (blkid
== DMU_BONUS_BLKID
)
2260 found_db
= dbuf_find_bonus(os
, obj
);
2262 found_db
= dbuf_find(os
, obj
, 0, blkid
);
2264 if (found_db
!= NULL
) {
2265 if (db
== found_db
&& dbuf_refcount(db
) > db
->db_dirtycnt
) {
2266 (void) refcount_add(&db
->db_holds
, tag
);
2269 mutex_exit(&found_db
->db_mtx
);
2275 * If you call dbuf_rele() you had better not be referencing the dnode handle
2276 * unless you have some other direct or indirect hold on the dnode. (An indirect
2277 * hold is a hold on one of the dnode's dbufs, including the bonus buffer.)
2278 * Without that, the dbuf_rele() could lead to a dnode_rele() followed by the
2279 * dnode's parent dbuf evicting its dnode handles.
2282 dbuf_rele(dmu_buf_impl_t
*db
, void *tag
)
2284 mutex_enter(&db
->db_mtx
);
2285 dbuf_rele_and_unlock(db
, tag
);
2289 dmu_buf_rele(dmu_buf_t
*db
, void *tag
)
2291 dbuf_rele((dmu_buf_impl_t
*)db
, tag
);
2295 * dbuf_rele() for an already-locked dbuf. This is necessary to allow
2296 * db_dirtycnt and db_holds to be updated atomically.
2299 dbuf_rele_and_unlock(dmu_buf_impl_t
*db
, void *tag
)
2303 ASSERT(MUTEX_HELD(&db
->db_mtx
));
2307 * Remove the reference to the dbuf before removing its hold on the
2308 * dnode so we can guarantee in dnode_move() that a referenced bonus
2309 * buffer has a corresponding dnode hold.
2311 holds
= refcount_remove(&db
->db_holds
, tag
);
2315 * We can't freeze indirects if there is a possibility that they
2316 * may be modified in the current syncing context.
2318 if (db
->db_buf
&& holds
== (db
->db_level
== 0 ? db
->db_dirtycnt
: 0))
2319 arc_buf_freeze(db
->db_buf
);
2321 if (holds
== db
->db_dirtycnt
&&
2322 db
->db_level
== 0 && db
->db_user_immediate_evict
)
2323 dbuf_evict_user(db
);
2326 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
2328 boolean_t evict_dbuf
= db
->db_pending_evict
;
2331 * If the dnode moves here, we cannot cross this
2332 * barrier until the move completes.
2337 atomic_dec_32(&dn
->dn_dbufs_count
);
2340 * Decrementing the dbuf count means that the bonus
2341 * buffer's dnode hold is no longer discounted in
2342 * dnode_move(). The dnode cannot move until after
2343 * the dnode_rele() below.
2348 * Do not reference db after its lock is dropped.
2349 * Another thread may evict it.
2351 mutex_exit(&db
->db_mtx
);
2354 dnode_evict_bonus(dn
);
2357 } else if (db
->db_buf
== NULL
) {
2359 * This is a special case: we never associated this
2360 * dbuf with any data allocated from the ARC.
2362 ASSERT(db
->db_state
== DB_UNCACHED
||
2363 db
->db_state
== DB_NOFILL
);
2365 } else if (arc_released(db
->db_buf
)) {
2366 arc_buf_t
*buf
= db
->db_buf
;
2368 * This dbuf has anonymous data associated with it.
2370 dbuf_clear_data(db
);
2371 VERIFY(arc_buf_remove_ref(buf
, db
));
2374 VERIFY(!arc_buf_remove_ref(db
->db_buf
, db
));
2377 * A dbuf will be eligible for eviction if either the
2378 * 'primarycache' property is set or a duplicate
2379 * copy of this buffer is already cached in the arc.
2381 * In the case of the 'primarycache' a buffer
2382 * is considered for eviction if it matches the
2383 * criteria set in the property.
2385 * To decide if our buffer is considered a
2386 * duplicate, we must call into the arc to determine
2387 * if multiple buffers are referencing the same
2388 * block on-disk. If so, then we simply evict
2391 if (!DBUF_IS_CACHEABLE(db
)) {
2392 if (db
->db_blkptr
!= NULL
&&
2393 !BP_IS_HOLE(db
->db_blkptr
) &&
2394 !BP_IS_EMBEDDED(db
->db_blkptr
)) {
2396 dmu_objset_spa(db
->db_objset
);
2397 blkptr_t bp
= *db
->db_blkptr
;
2399 arc_freed(spa
, &bp
);
2403 } else if (db
->db_pending_evict
||
2404 arc_buf_eviction_needed(db
->db_buf
)) {
2407 mutex_exit(&db
->db_mtx
);
2411 mutex_exit(&db
->db_mtx
);
2415 #pragma weak dmu_buf_refcount = dbuf_refcount
2417 dbuf_refcount(dmu_buf_impl_t
*db
)
2419 return (refcount_count(&db
->db_holds
));
2423 dmu_buf_replace_user(dmu_buf_t
*db_fake
, dmu_buf_user_t
*old_user
,
2424 dmu_buf_user_t
*new_user
)
2426 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2428 mutex_enter(&db
->db_mtx
);
2429 dbuf_verify_user(db
, DBVU_NOT_EVICTING
);
2430 if (db
->db_user
== old_user
)
2431 db
->db_user
= new_user
;
2433 old_user
= db
->db_user
;
2434 dbuf_verify_user(db
, DBVU_NOT_EVICTING
);
2435 mutex_exit(&db
->db_mtx
);
2441 dmu_buf_set_user(dmu_buf_t
*db_fake
, dmu_buf_user_t
*user
)
2443 return (dmu_buf_replace_user(db_fake
, NULL
, user
));
2447 dmu_buf_set_user_ie(dmu_buf_t
*db_fake
, dmu_buf_user_t
*user
)
2449 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2451 db
->db_user_immediate_evict
= TRUE
;
2452 return (dmu_buf_set_user(db_fake
, user
));
2456 dmu_buf_remove_user(dmu_buf_t
*db_fake
, dmu_buf_user_t
*user
)
2458 return (dmu_buf_replace_user(db_fake
, user
, NULL
));
2462 dmu_buf_get_user(dmu_buf_t
*db_fake
)
2464 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2466 dbuf_verify_user(db
, DBVU_NOT_EVICTING
);
2467 return (db
->db_user
);
2471 dmu_buf_user_evict_wait()
2473 taskq_wait(dbu_evict_taskq
);
2477 dmu_buf_freeable(dmu_buf_t
*dbuf
)
2479 boolean_t res
= B_FALSE
;
2480 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)dbuf
;
2483 res
= dsl_dataset_block_freeable(db
->db_objset
->os_dsl_dataset
,
2484 db
->db_blkptr
, db
->db_blkptr
->blk_birth
);
2490 dmu_buf_get_blkptr(dmu_buf_t
*db
)
2492 dmu_buf_impl_t
*dbi
= (dmu_buf_impl_t
*)db
;
2493 return (dbi
->db_blkptr
);
2497 dbuf_check_blkptr(dnode_t
*dn
, dmu_buf_impl_t
*db
)
2499 /* ASSERT(dmu_tx_is_syncing(tx) */
2500 ASSERT(MUTEX_HELD(&db
->db_mtx
));
2502 if (db
->db_blkptr
!= NULL
)
2505 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2506 db
->db_blkptr
= &dn
->dn_phys
->dn_spill
;
2507 BP_ZERO(db
->db_blkptr
);
2510 if (db
->db_level
== dn
->dn_phys
->dn_nlevels
-1) {
2512 * This buffer was allocated at a time when there was
2513 * no available blkptrs from the dnode, or it was
2514 * inappropriate to hook it in (i.e., nlevels mis-match).
2516 ASSERT(db
->db_blkid
< dn
->dn_phys
->dn_nblkptr
);
2517 ASSERT(db
->db_parent
== NULL
);
2518 db
->db_parent
= dn
->dn_dbuf
;
2519 db
->db_blkptr
= &dn
->dn_phys
->dn_blkptr
[db
->db_blkid
];
2522 dmu_buf_impl_t
*parent
= db
->db_parent
;
2523 int epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
2525 ASSERT(dn
->dn_phys
->dn_nlevels
> 1);
2526 if (parent
== NULL
) {
2527 mutex_exit(&db
->db_mtx
);
2528 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
2529 (void) dbuf_hold_impl(dn
, db
->db_level
+1,
2530 db
->db_blkid
>> epbs
, FALSE
, db
, &parent
);
2531 rw_exit(&dn
->dn_struct_rwlock
);
2532 mutex_enter(&db
->db_mtx
);
2533 db
->db_parent
= parent
;
2535 db
->db_blkptr
= (blkptr_t
*)parent
->db
.db_data
+
2536 (db
->db_blkid
& ((1ULL << epbs
) - 1));
2542 * dbuf_sync_indirect() is called recursively from dbuf_sync_list() so it
2543 * is critical the we not allow the compiler to inline this function in to
2544 * dbuf_sync_list() thereby drastically bloating the stack usage.
2546 noinline
static void
2547 dbuf_sync_indirect(dbuf_dirty_record_t
*dr
, dmu_tx_t
*tx
)
2549 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
2553 ASSERT(dmu_tx_is_syncing(tx
));
2555 dprintf_dbuf_bp(db
, db
->db_blkptr
, "blkptr=%p", db
->db_blkptr
);
2557 mutex_enter(&db
->db_mtx
);
2559 ASSERT(db
->db_level
> 0);
2562 /* Read the block if it hasn't been read yet. */
2563 if (db
->db_buf
== NULL
) {
2564 mutex_exit(&db
->db_mtx
);
2565 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
);
2566 mutex_enter(&db
->db_mtx
);
2568 ASSERT3U(db
->db_state
, ==, DB_CACHED
);
2569 ASSERT(db
->db_buf
!= NULL
);
2573 /* Indirect block size must match what the dnode thinks it is. */
2574 ASSERT3U(db
->db
.db_size
, ==, 1<<dn
->dn_phys
->dn_indblkshift
);
2575 dbuf_check_blkptr(dn
, db
);
2578 /* Provide the pending dirty record to child dbufs */
2579 db
->db_data_pending
= dr
;
2581 mutex_exit(&db
->db_mtx
);
2582 dbuf_write(dr
, db
->db_buf
, tx
);
2585 mutex_enter(&dr
->dt
.di
.dr_mtx
);
2586 dbuf_sync_list(&dr
->dt
.di
.dr_children
, db
->db_level
- 1, tx
);
2587 ASSERT(list_head(&dr
->dt
.di
.dr_children
) == NULL
);
2588 mutex_exit(&dr
->dt
.di
.dr_mtx
);
2593 * dbuf_sync_leaf() is called recursively from dbuf_sync_list() so it is
2594 * critical the we not allow the compiler to inline this function in to
2595 * dbuf_sync_list() thereby drastically bloating the stack usage.
2597 noinline
static void
2598 dbuf_sync_leaf(dbuf_dirty_record_t
*dr
, dmu_tx_t
*tx
)
2600 arc_buf_t
**datap
= &dr
->dt
.dl
.dr_data
;
2601 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
2604 uint64_t txg
= tx
->tx_txg
;
2606 ASSERT(dmu_tx_is_syncing(tx
));
2608 dprintf_dbuf_bp(db
, db
->db_blkptr
, "blkptr=%p", db
->db_blkptr
);
2610 mutex_enter(&db
->db_mtx
);
2612 * To be synced, we must be dirtied. But we
2613 * might have been freed after the dirty.
2615 if (db
->db_state
== DB_UNCACHED
) {
2616 /* This buffer has been freed since it was dirtied */
2617 ASSERT(db
->db
.db_data
== NULL
);
2618 } else if (db
->db_state
== DB_FILL
) {
2619 /* This buffer was freed and is now being re-filled */
2620 ASSERT(db
->db
.db_data
!= dr
->dt
.dl
.dr_data
);
2622 ASSERT(db
->db_state
== DB_CACHED
|| db
->db_state
== DB_NOFILL
);
2629 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2630 mutex_enter(&dn
->dn_mtx
);
2631 if (!(dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
)) {
2633 * In the previous transaction group, the bonus buffer
2634 * was entirely used to store the attributes for the
2635 * dnode which overrode the dn_spill field. However,
2636 * when adding more attributes to the file a spill
2637 * block was required to hold the extra attributes.
2639 * Make sure to clear the garbage left in the dn_spill
2640 * field from the previous attributes in the bonus
2641 * buffer. Otherwise, after writing out the spill
2642 * block to the new allocated dva, it will free
2643 * the old block pointed to by the invalid dn_spill.
2645 db
->db_blkptr
= NULL
;
2647 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_SPILL_BLKPTR
;
2648 mutex_exit(&dn
->dn_mtx
);
2652 * If this is a bonus buffer, simply copy the bonus data into the
2653 * dnode. It will be written out when the dnode is synced (and it
2654 * will be synced, since it must have been dirty for dbuf_sync to
2657 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
2658 dbuf_dirty_record_t
**drp
;
2660 ASSERT(*datap
!= NULL
);
2661 ASSERT0(db
->db_level
);
2662 ASSERT3U(dn
->dn_phys
->dn_bonuslen
, <=, DN_MAX_BONUSLEN
);
2663 bcopy(*datap
, DN_BONUS(dn
->dn_phys
), dn
->dn_phys
->dn_bonuslen
);
2666 if (*datap
!= db
->db
.db_data
) {
2667 zio_buf_free(*datap
, DN_MAX_BONUSLEN
);
2668 arc_space_return(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
2670 db
->db_data_pending
= NULL
;
2671 drp
= &db
->db_last_dirty
;
2673 drp
= &(*drp
)->dr_next
;
2674 ASSERT(dr
->dr_next
== NULL
);
2675 ASSERT(dr
->dr_dbuf
== db
);
2677 if (dr
->dr_dbuf
->db_level
!= 0) {
2678 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
2679 list_destroy(&dr
->dt
.di
.dr_children
);
2681 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
2682 ASSERT(db
->db_dirtycnt
> 0);
2683 db
->db_dirtycnt
-= 1;
2684 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
2691 * This function may have dropped the db_mtx lock allowing a dmu_sync
2692 * operation to sneak in. As a result, we need to ensure that we
2693 * don't check the dr_override_state until we have returned from
2694 * dbuf_check_blkptr.
2696 dbuf_check_blkptr(dn
, db
);
2699 * If this buffer is in the middle of an immediate write,
2700 * wait for the synchronous IO to complete.
2702 while (dr
->dt
.dl
.dr_override_state
== DR_IN_DMU_SYNC
) {
2703 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
2704 cv_wait(&db
->db_changed
, &db
->db_mtx
);
2705 ASSERT(dr
->dt
.dl
.dr_override_state
!= DR_NOT_OVERRIDDEN
);
2708 if (db
->db_state
!= DB_NOFILL
&&
2709 dn
->dn_object
!= DMU_META_DNODE_OBJECT
&&
2710 refcount_count(&db
->db_holds
) > 1 &&
2711 dr
->dt
.dl
.dr_override_state
!= DR_OVERRIDDEN
&&
2712 *datap
== db
->db_buf
) {
2714 * If this buffer is currently "in use" (i.e., there
2715 * are active holds and db_data still references it),
2716 * then make a copy before we start the write so that
2717 * any modifications from the open txg will not leak
2720 * NOTE: this copy does not need to be made for
2721 * objects only modified in the syncing context (e.g.
2722 * DNONE_DNODE blocks).
2724 int blksz
= arc_buf_size(*datap
);
2725 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
2726 *datap
= arc_buf_alloc(os
->os_spa
, blksz
, db
, type
);
2727 bcopy(db
->db
.db_data
, (*datap
)->b_data
, blksz
);
2729 db
->db_data_pending
= dr
;
2731 mutex_exit(&db
->db_mtx
);
2733 dbuf_write(dr
, *datap
, tx
);
2735 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
2736 if (dn
->dn_object
== DMU_META_DNODE_OBJECT
) {
2737 list_insert_tail(&dn
->dn_dirty_records
[txg
&TXG_MASK
], dr
);
2741 * Although zio_nowait() does not "wait for an IO", it does
2742 * initiate the IO. If this is an empty write it seems plausible
2743 * that the IO could actually be completed before the nowait
2744 * returns. We need to DB_DNODE_EXIT() first in case
2745 * zio_nowait() invalidates the dbuf.
2748 zio_nowait(dr
->dr_zio
);
2753 dbuf_sync_list(list_t
*list
, int level
, dmu_tx_t
*tx
)
2755 dbuf_dirty_record_t
*dr
;
2757 while ((dr
= list_head(list
))) {
2758 if (dr
->dr_zio
!= NULL
) {
2760 * If we find an already initialized zio then we
2761 * are processing the meta-dnode, and we have finished.
2762 * The dbufs for all dnodes are put back on the list
2763 * during processing, so that we can zio_wait()
2764 * these IOs after initiating all child IOs.
2766 ASSERT3U(dr
->dr_dbuf
->db
.db_object
, ==,
2767 DMU_META_DNODE_OBJECT
);
2770 if (dr
->dr_dbuf
->db_blkid
!= DMU_BONUS_BLKID
&&
2771 dr
->dr_dbuf
->db_blkid
!= DMU_SPILL_BLKID
) {
2772 VERIFY3U(dr
->dr_dbuf
->db_level
, ==, level
);
2774 list_remove(list
, dr
);
2775 if (dr
->dr_dbuf
->db_level
> 0)
2776 dbuf_sync_indirect(dr
, tx
);
2778 dbuf_sync_leaf(dr
, tx
);
2784 dbuf_write_ready(zio_t
*zio
, arc_buf_t
*buf
, void *vdb
)
2786 dmu_buf_impl_t
*db
= vdb
;
2788 blkptr_t
*bp
= zio
->io_bp
;
2789 blkptr_t
*bp_orig
= &zio
->io_bp_orig
;
2790 spa_t
*spa
= zio
->io_spa
;
2795 ASSERT3P(db
->db_blkptr
, ==, bp
);
2799 delta
= bp_get_dsize_sync(spa
, bp
) - bp_get_dsize_sync(spa
, bp_orig
);
2800 dnode_diduse_space(dn
, delta
- zio
->io_prev_space_delta
);
2801 zio
->io_prev_space_delta
= delta
;
2803 if (bp
->blk_birth
!= 0) {
2804 ASSERT((db
->db_blkid
!= DMU_SPILL_BLKID
&&
2805 BP_GET_TYPE(bp
) == dn
->dn_type
) ||
2806 (db
->db_blkid
== DMU_SPILL_BLKID
&&
2807 BP_GET_TYPE(bp
) == dn
->dn_bonustype
) ||
2808 BP_IS_EMBEDDED(bp
));
2809 ASSERT(BP_GET_LEVEL(bp
) == db
->db_level
);
2812 mutex_enter(&db
->db_mtx
);
2815 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2816 ASSERT(dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
);
2817 ASSERT(!(BP_IS_HOLE(db
->db_blkptr
)) &&
2818 db
->db_blkptr
== &dn
->dn_phys
->dn_spill
);
2822 if (db
->db_level
== 0) {
2823 mutex_enter(&dn
->dn_mtx
);
2824 if (db
->db_blkid
> dn
->dn_phys
->dn_maxblkid
&&
2825 db
->db_blkid
!= DMU_SPILL_BLKID
)
2826 dn
->dn_phys
->dn_maxblkid
= db
->db_blkid
;
2827 mutex_exit(&dn
->dn_mtx
);
2829 if (dn
->dn_type
== DMU_OT_DNODE
) {
2830 dnode_phys_t
*dnp
= db
->db
.db_data
;
2831 for (i
= db
->db
.db_size
>> DNODE_SHIFT
; i
> 0;
2833 if (dnp
->dn_type
!= DMU_OT_NONE
)
2837 if (BP_IS_HOLE(bp
)) {
2844 blkptr_t
*ibp
= db
->db
.db_data
;
2845 ASSERT3U(db
->db
.db_size
, ==, 1<<dn
->dn_phys
->dn_indblkshift
);
2846 for (i
= db
->db
.db_size
>> SPA_BLKPTRSHIFT
; i
> 0; i
--, ibp
++) {
2847 if (BP_IS_HOLE(ibp
))
2849 fill
+= BP_GET_FILL(ibp
);
2854 if (!BP_IS_EMBEDDED(bp
))
2855 bp
->blk_fill
= fill
;
2857 mutex_exit(&db
->db_mtx
);
2861 * The SPA will call this callback several times for each zio - once
2862 * for every physical child i/o (zio->io_phys_children times). This
2863 * allows the DMU to monitor the progress of each logical i/o. For example,
2864 * there may be 2 copies of an indirect block, or many fragments of a RAID-Z
2865 * block. There may be a long delay before all copies/fragments are completed,
2866 * so this callback allows us to retire dirty space gradually, as the physical
2871 dbuf_write_physdone(zio_t
*zio
, arc_buf_t
*buf
, void *arg
)
2873 dmu_buf_impl_t
*db
= arg
;
2874 objset_t
*os
= db
->db_objset
;
2875 dsl_pool_t
*dp
= dmu_objset_pool(os
);
2876 dbuf_dirty_record_t
*dr
;
2879 dr
= db
->db_data_pending
;
2880 ASSERT3U(dr
->dr_txg
, ==, zio
->io_txg
);
2883 * The callback will be called io_phys_children times. Retire one
2884 * portion of our dirty space each time we are called. Any rounding
2885 * error will be cleaned up by dsl_pool_sync()'s call to
2886 * dsl_pool_undirty_space().
2888 delta
= dr
->dr_accounted
/ zio
->io_phys_children
;
2889 dsl_pool_undirty_space(dp
, delta
, zio
->io_txg
);
2894 dbuf_write_done(zio_t
*zio
, arc_buf_t
*buf
, void *vdb
)
2896 dmu_buf_impl_t
*db
= vdb
;
2897 blkptr_t
*bp_orig
= &zio
->io_bp_orig
;
2898 blkptr_t
*bp
= db
->db_blkptr
;
2899 objset_t
*os
= db
->db_objset
;
2900 dmu_tx_t
*tx
= os
->os_synctx
;
2901 dbuf_dirty_record_t
**drp
, *dr
;
2903 ASSERT0(zio
->io_error
);
2904 ASSERT(db
->db_blkptr
== bp
);
2907 * For nopwrites and rewrites we ensure that the bp matches our
2908 * original and bypass all the accounting.
2910 if (zio
->io_flags
& (ZIO_FLAG_IO_REWRITE
| ZIO_FLAG_NOPWRITE
)) {
2911 ASSERT(BP_EQUAL(bp
, bp_orig
));
2913 dsl_dataset_t
*ds
= os
->os_dsl_dataset
;
2914 (void) dsl_dataset_block_kill(ds
, bp_orig
, tx
, B_TRUE
);
2915 dsl_dataset_block_born(ds
, bp
, tx
);
2918 mutex_enter(&db
->db_mtx
);
2922 drp
= &db
->db_last_dirty
;
2923 while ((dr
= *drp
) != db
->db_data_pending
)
2925 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
2926 ASSERT(dr
->dr_dbuf
== db
);
2927 ASSERT(dr
->dr_next
== NULL
);
2931 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2936 ASSERT(dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
);
2937 ASSERT(!(BP_IS_HOLE(db
->db_blkptr
)) &&
2938 db
->db_blkptr
== &dn
->dn_phys
->dn_spill
);
2943 if (db
->db_level
== 0) {
2944 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
2945 ASSERT(dr
->dt
.dl
.dr_override_state
== DR_NOT_OVERRIDDEN
);
2946 if (db
->db_state
!= DB_NOFILL
) {
2947 if (dr
->dt
.dl
.dr_data
!= db
->db_buf
)
2948 VERIFY(arc_buf_remove_ref(dr
->dt
.dl
.dr_data
,
2950 else if (!arc_released(db
->db_buf
))
2951 arc_set_callback(db
->db_buf
, dbuf_do_evict
, db
);
2958 ASSERT(list_head(&dr
->dt
.di
.dr_children
) == NULL
);
2959 ASSERT3U(db
->db
.db_size
, ==, 1 << dn
->dn_phys
->dn_indblkshift
);
2960 if (!BP_IS_HOLE(db
->db_blkptr
)) {
2961 ASSERTV(int epbs
= dn
->dn_phys
->dn_indblkshift
-
2963 ASSERT3U(db
->db_blkid
, <=,
2964 dn
->dn_phys
->dn_maxblkid
>> (db
->db_level
* epbs
));
2965 ASSERT3U(BP_GET_LSIZE(db
->db_blkptr
), ==,
2967 if (!arc_released(db
->db_buf
))
2968 arc_set_callback(db
->db_buf
, dbuf_do_evict
, db
);
2971 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
2972 list_destroy(&dr
->dt
.di
.dr_children
);
2974 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
2976 cv_broadcast(&db
->db_changed
);
2977 ASSERT(db
->db_dirtycnt
> 0);
2978 db
->db_dirtycnt
-= 1;
2979 db
->db_data_pending
= NULL
;
2980 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)tx
->tx_txg
);
2984 dbuf_write_nofill_ready(zio_t
*zio
)
2986 dbuf_write_ready(zio
, NULL
, zio
->io_private
);
2990 dbuf_write_nofill_done(zio_t
*zio
)
2992 dbuf_write_done(zio
, NULL
, zio
->io_private
);
2996 dbuf_write_override_ready(zio_t
*zio
)
2998 dbuf_dirty_record_t
*dr
= zio
->io_private
;
2999 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
3001 dbuf_write_ready(zio
, NULL
, db
);
3005 dbuf_write_override_done(zio_t
*zio
)
3007 dbuf_dirty_record_t
*dr
= zio
->io_private
;
3008 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
3009 blkptr_t
*obp
= &dr
->dt
.dl
.dr_overridden_by
;
3011 mutex_enter(&db
->db_mtx
);
3012 if (!BP_EQUAL(zio
->io_bp
, obp
)) {
3013 if (!BP_IS_HOLE(obp
))
3014 dsl_free(spa_get_dsl(zio
->io_spa
), zio
->io_txg
, obp
);
3015 arc_release(dr
->dt
.dl
.dr_data
, db
);
3017 mutex_exit(&db
->db_mtx
);
3019 dbuf_write_done(zio
, NULL
, db
);
3022 /* Issue I/O to commit a dirty buffer to disk. */
3024 dbuf_write(dbuf_dirty_record_t
*dr
, arc_buf_t
*data
, dmu_tx_t
*tx
)
3026 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
3029 dmu_buf_impl_t
*parent
= db
->db_parent
;
3030 uint64_t txg
= tx
->tx_txg
;
3031 zbookmark_phys_t zb
;
3040 if (db
->db_state
!= DB_NOFILL
) {
3041 if (db
->db_level
> 0 || dn
->dn_type
== DMU_OT_DNODE
) {
3043 * Private object buffers are released here rather
3044 * than in dbuf_dirty() since they are only modified
3045 * in the syncing context and we don't want the
3046 * overhead of making multiple copies of the data.
3048 if (BP_IS_HOLE(db
->db_blkptr
)) {
3051 dbuf_release_bp(db
);
3056 if (parent
!= dn
->dn_dbuf
) {
3057 /* Our parent is an indirect block. */
3058 /* We have a dirty parent that has been scheduled for write. */
3059 ASSERT(parent
&& parent
->db_data_pending
);
3060 /* Our parent's buffer is one level closer to the dnode. */
3061 ASSERT(db
->db_level
== parent
->db_level
-1);
3063 * We're about to modify our parent's db_data by modifying
3064 * our block pointer, so the parent must be released.
3066 ASSERT(arc_released(parent
->db_buf
));
3067 zio
= parent
->db_data_pending
->dr_zio
;
3069 /* Our parent is the dnode itself. */
3070 ASSERT((db
->db_level
== dn
->dn_phys
->dn_nlevels
-1 &&
3071 db
->db_blkid
!= DMU_SPILL_BLKID
) ||
3072 (db
->db_blkid
== DMU_SPILL_BLKID
&& db
->db_level
== 0));
3073 if (db
->db_blkid
!= DMU_SPILL_BLKID
)
3074 ASSERT3P(db
->db_blkptr
, ==,
3075 &dn
->dn_phys
->dn_blkptr
[db
->db_blkid
]);
3079 ASSERT(db
->db_level
== 0 || data
== db
->db_buf
);
3080 ASSERT3U(db
->db_blkptr
->blk_birth
, <=, txg
);
3083 SET_BOOKMARK(&zb
, os
->os_dsl_dataset
?
3084 os
->os_dsl_dataset
->ds_object
: DMU_META_OBJSET
,
3085 db
->db
.db_object
, db
->db_level
, db
->db_blkid
);
3087 if (db
->db_blkid
== DMU_SPILL_BLKID
)
3089 wp_flag
|= (db
->db_state
== DB_NOFILL
) ? WP_NOFILL
: 0;
3091 dmu_write_policy(os
, dn
, db
->db_level
, wp_flag
, &zp
);
3094 if (db
->db_level
== 0 &&
3095 dr
->dt
.dl
.dr_override_state
== DR_OVERRIDDEN
) {
3097 * The BP for this block has been provided by open context
3098 * (by dmu_sync() or dmu_buf_write_embedded()).
3100 void *contents
= (data
!= NULL
) ? data
->b_data
: NULL
;
3102 dr
->dr_zio
= zio_write(zio
, os
->os_spa
, txg
,
3103 db
->db_blkptr
, contents
, db
->db
.db_size
, &zp
,
3104 dbuf_write_override_ready
, NULL
, dbuf_write_override_done
,
3105 dr
, ZIO_PRIORITY_ASYNC_WRITE
, ZIO_FLAG_MUSTSUCCEED
, &zb
);
3106 mutex_enter(&db
->db_mtx
);
3107 dr
->dt
.dl
.dr_override_state
= DR_NOT_OVERRIDDEN
;
3108 zio_write_override(dr
->dr_zio
, &dr
->dt
.dl
.dr_overridden_by
,
3109 dr
->dt
.dl
.dr_copies
, dr
->dt
.dl
.dr_nopwrite
);
3110 mutex_exit(&db
->db_mtx
);
3111 } else if (db
->db_state
== DB_NOFILL
) {
3112 ASSERT(zp
.zp_checksum
== ZIO_CHECKSUM_OFF
);
3113 dr
->dr_zio
= zio_write(zio
, os
->os_spa
, txg
,
3114 db
->db_blkptr
, NULL
, db
->db
.db_size
, &zp
,
3115 dbuf_write_nofill_ready
, NULL
, dbuf_write_nofill_done
, db
,
3116 ZIO_PRIORITY_ASYNC_WRITE
,
3117 ZIO_FLAG_MUSTSUCCEED
| ZIO_FLAG_NODATA
, &zb
);
3119 ASSERT(arc_released(data
));
3120 dr
->dr_zio
= arc_write(zio
, os
->os_spa
, txg
,
3121 db
->db_blkptr
, data
, DBUF_IS_L2CACHEABLE(db
),
3122 DBUF_IS_L2COMPRESSIBLE(db
), &zp
, dbuf_write_ready
,
3123 dbuf_write_physdone
, dbuf_write_done
, db
,
3124 ZIO_PRIORITY_ASYNC_WRITE
, ZIO_FLAG_MUSTSUCCEED
, &zb
);
3128 #if defined(_KERNEL) && defined(HAVE_SPL)
3129 EXPORT_SYMBOL(dbuf_find
);
3130 EXPORT_SYMBOL(dbuf_is_metadata
);
3131 EXPORT_SYMBOL(dbuf_evict
);
3132 EXPORT_SYMBOL(dbuf_loan_arcbuf
);
3133 EXPORT_SYMBOL(dbuf_whichblock
);
3134 EXPORT_SYMBOL(dbuf_read
);
3135 EXPORT_SYMBOL(dbuf_unoverride
);
3136 EXPORT_SYMBOL(dbuf_free_range
);
3137 EXPORT_SYMBOL(dbuf_new_size
);
3138 EXPORT_SYMBOL(dbuf_release_bp
);
3139 EXPORT_SYMBOL(dbuf_dirty
);
3140 EXPORT_SYMBOL(dmu_buf_will_dirty
);
3141 EXPORT_SYMBOL(dmu_buf_will_not_fill
);
3142 EXPORT_SYMBOL(dmu_buf_will_fill
);
3143 EXPORT_SYMBOL(dmu_buf_fill_done
);
3144 EXPORT_SYMBOL(dmu_buf_rele
);
3145 EXPORT_SYMBOL(dbuf_assign_arcbuf
);
3146 EXPORT_SYMBOL(dbuf_clear
);
3147 EXPORT_SYMBOL(dbuf_prefetch
);
3148 EXPORT_SYMBOL(dbuf_hold_impl
);
3149 EXPORT_SYMBOL(dbuf_hold
);
3150 EXPORT_SYMBOL(dbuf_hold_level
);
3151 EXPORT_SYMBOL(dbuf_create_bonus
);
3152 EXPORT_SYMBOL(dbuf_spill_set_blksz
);
3153 EXPORT_SYMBOL(dbuf_rm_spill
);
3154 EXPORT_SYMBOL(dbuf_add_ref
);
3155 EXPORT_SYMBOL(dbuf_rele
);
3156 EXPORT_SYMBOL(dbuf_rele_and_unlock
);
3157 EXPORT_SYMBOL(dbuf_refcount
);
3158 EXPORT_SYMBOL(dbuf_sync_list
);
3159 EXPORT_SYMBOL(dmu_buf_set_user
);
3160 EXPORT_SYMBOL(dmu_buf_set_user_ie
);
3161 EXPORT_SYMBOL(dmu_buf_get_user
);
3162 EXPORT_SYMBOL(dmu_buf_freeable
);
3163 EXPORT_SYMBOL(dmu_buf_get_blkptr
);