dbuf.c revision ae9727953cac4bd427aafd9f27458e401590bcb5
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2012, 2016 by Delphix. All rights reserved.
* Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
* Copyright (c) 2014 Integros [integros.com]
*/
#include <sys/zfs_context.h>
#include <sys/dmu_send.h>
#include <sys/dmu_impl.h>
#include <sys/dmu_objset.h>
#include <sys/dsl_dataset.h>
#include <sys/dmu_zfetch.h>
#include <sys/zfeature.h>
#include <sys/range_tree.h>
/*
* Number of times that zfs_free_range() took the slow path while doing
* a zfs receive. A nonzero value indicates a potential performance problem.
*/
#ifndef __lint
#endif /* ! __lint */
/*
* Global data structures and functions for the dbuf cache.
*/
static kmem_cache_t *dbuf_kmem_cache;
static taskq_t *dbu_evict_taskq;
static kthread_t *dbuf_cache_evict_thread;
static kmutex_t dbuf_evict_lock;
static kcondvar_t dbuf_evict_cv;
static boolean_t dbuf_evict_thread_exit;
/*
* LRU cache of dbufs. The dbuf cache maintains a list of dbufs that
* are not currently held but have been recently released. These dbufs
* are not eligible for arc eviction until they are aged out of the cache.
* Dbufs are added to the dbuf cache once the last hold is released. If a
* dbuf is later accessed and still exists in the dbuf cache, then it will
* be removed from the cache and later re-added to the head of the cache.
* Dbufs that are aged out of the cache will be immediately destroyed and
* become eligible for arc eviction.
*/
static multilist_t dbuf_cache;
static refcount_t dbuf_cache_size;
/* Cap the size of the dbuf cache to log2 fraction of arc size. */
int dbuf_cache_max_shift = 5;
/*
* The dbuf cache uses a three-stage eviction policy:
* - A low water marker designates when the dbuf eviction thread
* should stop evicting from the dbuf cache.
* - When we reach the maximum size (aka mid water mark), we
* signal the eviction thread to run.
* - The high water mark indicates when the eviction thread
* is unable to keep up with the incoming load and eviction must
* happen in the context of the calling thread.
*
* The dbuf cache:
* (max size)
* low water mid water hi water
* +----------------------------------------+----------+----------+
* | | | |
* | | | |
* | | | |
* | | | |
* +----------------------------------------+----------+----------+
* stop signal evict
* evicting eviction directly
* thread
*
* The high and low water marks indicate the operating range for the eviction
* thread. The low water mark is, by default, 90% of the total size of the
* cache and the high water mark is at 110% (both of these percentages can be
* changed by setting dbuf_cache_lowater_pct and dbuf_cache_hiwater_pct,
* respectively). The eviction thread will try to ensure that the cache remains
* within this range by waking up every second and checking if the cache is
* above the low water mark. The thread can also be woken up by callers adding
* elements into the cache if the cache is larger than the mid water (i.e max
* cache size). Once the eviction thread is woken up and eviction is required,
* it will continue evicting buffers until it's able to reduce the cache size
* to the low water mark. If the cache size continues to grow and hits the high
* water mark, then callers adding elments to the cache will begin to evict
* directly from the cache until the cache is no longer above the high water
* mark.
*/
/*
* The percentage above and below the maximum cache size.
*/
/* ARGSUSED */
static int
{
return (0);
}
/* ARGSUSED */
static void
{
}
/*
* dbuf hash table routines
*/
static dbuf_hash_table_t dbuf_hash_table;
static uint64_t dbuf_hash_count;
static uint64_t
{
return (crc);
}
{
dbuf_hash_table_t *h = &dbuf_hash_table;
return (db);
}
}
}
return (NULL);
}
static dmu_buf_impl_t *
{
}
}
return (db);
}
/*
* Insert an entry into the hash table. If there is already an element
* equal to elem in the hash table, then the already existing element
* will be returned and the new element will not be inserted.
* Otherwise returns NULL.
*/
static dmu_buf_impl_t *
{
dbuf_hash_table_t *h = &dbuf_hash_table;
return (dbf);
}
}
}
return (NULL);
}
/*
* Remove an entry from the hash table. It must be in the EVICTING state.
*/
static void
{
dbuf_hash_table_t *h = &dbuf_hash_table;
/*
* We musn't hold db_mtx to maintain lock ordering:
* DBUF_HASH_MUTEX > db_mtx.
*/
}
}
typedef enum {
static void
{
#ifdef ZFS_DEBUG
return;
/* Only data blocks support the attachment of user data. */
/* Clients must resolve a dbuf before attaching user data. */
if (verify_type == DBVU_EVICTING) {
/*
* Immediate eviction occurs when holds == dirtycnt.
* For normal eviction buffers, holds is zero on
* eviction, except when dbuf_fix_old_data() calls
* dbuf_clear_data(). However, the hold count can grow
* during eviction even though db_mtx is held (see
* dmu_bonus_hold() for an example), so we can only
* test the generic invariant that holds >= dirtycnt.
*/
} else {
else
}
#endif
}
static void
{
return;
#ifdef ZFS_DEBUG
#endif
/*
* Invoke the callback from a taskq to avoid lock order reversals
* and limit stack depth.
*/
}
{
return (B_TRUE);
} else {
return (is_metadata);
}
}
/*
* This function *must* return indices evenly distributed between all
* sublists of the multilist. This is needed due to how the dbuf eviction
* code is laid out; dbuf_evict_thread() assumes dbufs are evenly
* distributed between all sublists and uses this assumption when
* deciding which sublist to evict from and how much to evict from it.
*/
unsigned int
{
/*
* The assumption here, is the hash value for a given
* dmu_buf_impl_t will remain constant throughout it's lifetime
* (i.e. it's objset, object, level and blkid fields don't change).
* Thus, we don't need to store the dbuf's sublist index
* on insertion, as this index can be recalculated on removal.
*
* Also, the low order bits of the hash value are thought to be
* distributed evenly. Otherwise, in the case that the multilist
* has a power of two number of sublists, each sublists' usage
* would not be evenly distributed.
*/
}
static inline boolean_t
dbuf_cache_above_hiwater(void)
{
return (refcount_count(&dbuf_cache_size) >
}
static inline boolean_t
dbuf_cache_above_lowater(void)
{
return (refcount_count(&dbuf_cache_size) >
}
/*
* Evict the oldest eligible dbuf from the dbuf cache.
*/
static void
dbuf_evict_one(void)
{
/*
* Set the thread's tsd to indicate that it's processing evictions.
* Once a thread stops evicting from the dbuf cache it will
* reset its tsd to NULL.
*/
}
multilist_sublist_t *, mls);
(void) refcount_remove_many(&dbuf_cache_size,
} else {
}
}
/*
* The dbuf evict thread is responsible for aging out dbufs from the
* cache. Once the cache has reached it's maximum size, dbufs are removed
* and destroyed. The eviction thread will continue running until the size
* of the dbuf cache is at or below the maximum size. Once the dbuf is aged
* out of the cache it is destroyed and becomes eligible for arc eviction.
*/
static void
dbuf_evict_thread(void)
{
while (!dbuf_evict_thread_exit) {
while (!dbuf_cache_above_lowater() && !dbuf_evict_thread_exit) {
(void) cv_timedwait_hires(&dbuf_evict_cv,
}
/*
* Keep evicting as long as we're above the low water mark
* for the cache. We do this without holding the locks to
* minimize lock contention.
*/
while (dbuf_cache_above_lowater() && !dbuf_evict_thread_exit) {
}
}
thread_exit();
}
/*
* Wake up the dbuf eviction thread if the dbuf cache is at its max size.
* If the dbuf cache is at its high water mark, then evict a dbuf from the
* dbuf cache using the callers context.
*/
static void
dbuf_evict_notify(void)
{
/*
* We use thread specific data to track when a thread has
* started processing evictions. This allows us to avoid deeply
* nested stacks that would have a call flow similar to this:
*
* dbuf_rele()-->dbuf_rele_and_unlock()-->dbuf_evict_notify()
* ^ |
* | |
* +-----dbuf_destroy()<--dbuf_evict_one()<--------+
*
* The dbuf_eviction_thread will always have its tsd set until
* that thread exits. All other threads will only set their tsd
* if they are participating in the eviction process. This only
* happens if the eviction thread is unable to process evictions
* fast enough. To keep the dbuf cache size in check, other threads
* can evict from the dbuf cache directly. Those threads will set
* their tsd values so that we ensure that they only evict one dbuf
* from the dbuf cache.
*/
return;
}
if (evict_now) {
}
}
}
void
dbuf_init(void)
{
dbuf_hash_table_t *h = &dbuf_hash_table;
int i;
/*
* The hash table is big enough to fill all of physical memory
* with an average 4K block size. The table will take up
*/
hsize <<= 1;
if (h->hash_table == NULL) {
/* XXX - we should really return an error instead of assert */
hsize >>= 1;
goto retry;
}
sizeof (dmu_buf_impl_t),
for (i = 0; i < DBUF_MUTEXES; i++)
/*
* Setup the parameters for the dbuf cache. We cap the size of the
* dbuf cache to 1/32nd (default) of the size of the ARC.
*/
/*
* configuration is not required.
*/
}
void
dbuf_fini(void)
{
dbuf_hash_table_t *h = &dbuf_hash_table;
int i;
for (i = 0; i < DBUF_MUTEXES; i++)
mutex_destroy(&h->hash_mutexes[i]);
while (dbuf_evict_thread_exit) {
}
}
/*
* Other stuff.
*/
#ifdef ZFS_DEBUG
static void
{
if (!(zfs_flags & ZFS_DEBUG_DBUF_VERIFY))
return;
} else {
}
} else {
}
/*
* We can't assert that db_size matches dn_datablksz because it
* can be momentarily different when another thread is doing
* dnode_set_blksz().
*/
/*
* It should only be modified in syncing context, so
* make sure we only have one copy of the data.
*/
}
/* verify db->db_blkptr */
/* db is pointed to by the dnode */
/* ASSERT3U(db->db_blkid, <, dn->dn_nblkptr); */
else
} else {
/* db is pointed to by an indirect block */
/*
* dnode_grow_indblksz() can make this fail if we don't
* have the struct_rwlock. XXX indblksz no longer
* grows. safe to do this now?
*/
}
}
}
/*
* If the blkptr isn't set but they have nonzero data,
* it had better be dirty, otherwise we'll lose that
* data when we evict this buffer.
*
* There is an exception to this rule for indirect blocks; in
* this case, if the indirect block is a hole, we fill in a few
* fields on each of the child blocks (importantly, birth time)
* to prevent hole birth times from being lost when you
* partially fill in a hole.
*/
if (db->db_dirtycnt == 0) {
int i;
}
} else {
/*
* We want to verify that all the blkptrs in the
* indirect block are holes, but we may have
* automatically set up a few fields for them.
* We iterate through each blkptr and verify
* they only have those fields set.
*/
for (int i = 0;
i++) {
}
}
}
}
}
#endif
static void
{
}
static void
{
}
/*
* Loan out an arc_buf for read. Return the loaned arc_buf.
*/
{
} else {
}
return (abuf);
}
/*
* Calculate which level n block references the data at the level 0 offset
* provided.
*/
{
/*
* The level n blkid is equal to the level 0 blkid divided by
* the number of level 0s in a level n block.
*
* The level 0 blkid is offset >> datablkshift =
* offset / 2^datablkshift.
*
* The number of level 0s in a level n is the number of block
* pointers in an indirect block, raised to the power of level.
* This is 2^(indblkshift - SPA_BLKPTRSHIFT)^level =
* 2^(level*(indblkshift - SPA_BLKPTRSHIFT)).
*
* Thus, the level n blkid is: offset /
* ((2^datablkshift)*(2^(level*(indblkshift - SPA_BLKPTRSHIFT)))
* = offset / 2^(datablkshift + level *
* (indblkshift - SPA_BLKPTRSHIFT))
* = offset >> (datablkshift + level *
* (indblkshift - SPA_BLKPTRSHIFT))
*/
} else {
return (0);
}
}
static void
{
/*
* All reads are synchronous, so we must have a hold on the dbuf
*/
/* we were freed in flight; disregard any error */
} else {
}
}
static void
{
/* We need the struct_rwlock to prevent db_blkptr from changing. */
if (bonuslen < DN_MAX_BONUSLEN)
if (bonuslen)
return;
}
/*
* Recheck BP_IS_HOLE() after dnode_block_freed() in case dnode_sync()
* processes the delete record and clears the bp while we are waiting
* for the dn_mtx (resulting in a "no" from block_freed).
*/
for (int i = 0; i < ((1 <<
i++) {
dn->dn_datablksz :
}
}
return;
}
if (DBUF_IS_L2CACHEABLE(db))
}
int
{
int err = 0;
/*
* We don't have to hold the mutex to check db_state because it
* can't be freed while we have a hold on the buffer.
*/
if ((flags & DB_RF_HAVESTRUCT) == 0)
if (prefetch)
if ((flags & DB_RF_HAVESTRUCT) == 0)
/* dbuf_read_impl has dropped db_mtx for us */
if (prefetch)
if ((flags & DB_RF_HAVESTRUCT) == 0)
if (!havepzio)
} else {
/*
* Another reader came in while the dbuf was in flight
* between UNCACHED and CACHED. Either a writer will finish
* writing the buffer (sending the dbuf to CACHED) or the
* first reader's request will reach the read_done callback
* and send the dbuf to CACHED. Otherwise, a failure
* occurred and the dbuf went to UNCACHED.
*/
if (prefetch)
if ((flags & DB_RF_HAVESTRUCT) == 0)
/* Skip the wait per the caller's request. */
if ((flags & DB_RF_NEVERWAIT) == 0) {
(flags & DB_RF_HAVESTRUCT) == 0);
}
}
}
return (err);
}
static void
{
} else {
}
}
/*
* This is our just-in-time copy function. It makes a copy of
* buffers, that have been modified in a previous transaction
* group, before we modify them in the current active group.
*
* This function is used in two places: when we are dirtying a
* buffer for the first time in a txg, and when we are freeing
* a range in a dnode that includes this buffer.
*
* Note that when we are called from dbuf_free_range() we do
* not put a hold on the buffer, we just traverse the active
* dbuf list for the dnode.
*/
static void
{
return;
/*
* If the last dirty record for this dbuf has not yet synced
* and its referencing the dbuf data, either:
* reset the reference to point to a new copy,
* or (if there a no active holders)
* just null out the current db_data pointer.
*/
/* Note that the data bufs here are zio_bufs */
} else {
}
}
void
{
return;
/* free this block */
/*
* Release the already-written buffer, so we leave it in
* a consistent dirty state. Note that all callers are
* modifying the buffer, so they will immediately do
* another (redundant) arc_release(). Therefore, leave
* the buf thawed to save the effort of freezing &
* immediately re-thawing it.
*/
}
/*
* Evict (if its unreferenced) or clear (if its referenced) any level-0
* data blocks in the free range, so that any future readers will find
* empty blocks.
*
* This is a no-op if the dataset is in the middle of an incremental
* receive; see comment below for details.
*/
void
{
/* There can't be any dbufs in this range; no need to search. */
#ifdef DEBUG
#endif
return;
/*
* If we are receiving, we expect there to be no dbufs in
* the range to be freed, because receive modifies each
* block at most once, and in offset order. If this is
* not the case, it can lead to performance problems,
* so note that we unexpectedly took the slow path.
*/
}
break;
}
/* found a level 0 buffer in the range */
/* mutex has been dropped and dbuf destroyed */
continue;
}
continue;
}
/* will be handled in dbuf_read_done or dbuf_rele */
continue;
}
continue;
}
/* The dbuf is referenced */
/*
* This buffer is "in-use", re-adjust the file
* size to reflect that this buffer may
* contain new data when we sync.
*/
} else {
/*
* This dbuf is not dirty in the open context.
* Either uncache it (if its not referenced in
* the open context) or reset its contents to
* empty.
*/
}
}
/* clear the contents if its cached */
}
}
}
static int
{
/*
* We don't need any locking to protect db_blkptr:
* If it's syncing, then db_last_dirty will be set
* so we'll ignore db_blkptr.
*
* This logic ensures that only block births for
* filled blocks are considered.
*/
}
/*
* If this block don't exist or is in a snapshot, it can't be freed.
* Don't pass the bp to dsl_dataset_block_freeable() since we
* are holding the db_mtx lock and might deadlock if we are
* prefetching a dedup-ed block.
*/
if (birth_txg != 0)
else
return (B_FALSE);
}
void
{
/* XXX does *this* func really need the lock? */
/*
* This call to dmu_buf_will_dirty() with the dn_struct_rwlock held
* is OK, because there can be no other references to the db
* when we are changing its size, so no concurrent DB_FILL can
* be happening.
*/
/*
* XXX we should be doing a dbuf_read, checking the return
* value and returning that up to our callers
*/
/* create the data buffer for the new block */
/* copy old block data to the new block */
/* zero the remainder */
}
}
void
{
}
/*
* We already have a dirty record for this TXG, and we are being
* dirtied again.
*/
static void
{
/*
* If this buffer has already been written out,
* we now need to reset its state.
*/
/* Already released on initial dirty, so just thaw. */
}
}
}
{
int drop_struct_lock = FALSE;
/*
* Shouldn't dirty a regular buffer in syncing context. Private
* objects may be dirtied in syncing context, but only if they
* were already pre-dirtied in open context.
*/
/*
* We make this assert for private objects as well, but after we
* check if we're already dirty. They are allowed to re-dirty
* in syncing context.
*/
/*
* XXX make this true for indirects too? The problem is that
* transactions created with dmu_tx_create_assigned() from
* syncing context don't bother holding ahead.
*/
/*
* Don't set dirtyctx to SYNC if we're just modifying this as we
* initialize the objset.
*/
dn->dn_dirtyctx =
}
/*
* If this buffer is already dirty, we're done.
*/
return (dr);
}
/*
* Only valid if not already dirty.
*/
/*
* We should only be dirtying in syncing context if it's the
* mos or we're initializing the os or it's a special object.
* However, we are allowed to dirty in syncing context provided
* we already dirtied it in open context. Hence we must make
* this assertion only if we're not already dirty.
*/
/*
* Update the accounting.
* Note: we delay "free accounting" until after we drop
* the db_mtx. This keeps us from grabbing other locks
* (and possibly deadlocking) in bp_get_dsize() while
* also holding the db_mtx.
*/
}
/*
* If this buffer is dirty in an old transaction group we need
* to make a copy of it so that the changes we make in this
* transaction group won't leak out when we sync the older txg.
*/
/*
* Release the data buffer from the cache so
* that we can modify it without impacting
* possible other users of this cached data
* block. Note that indirect blocks and
* private objects are not released until the
* syncing state (since they are only modified
* then).
*/
}
}
} else {
sizeof (dbuf_dirty_record_t),
}
/*
* We could have been freed_in_flight between the dbuf_noread
* and dbuf_dirty. We win, as though the dbuf_noread() had
* happened after the free.
*/
}
}
/*
* This buffer is now part of this txg
*/
return (dr);
}
/*
* The dn_struct_rwlock prevents db_blkptr from changing
* due to a write from syncing context completing
* while we are running, so we want to acquire it before
* looking at db_blkptr.
*/
}
if (do_free_accounting) {
/*
* This is only a guess -- if the dbuf is dirty
* in a previous txg, we don't know how much
* space it will use on disk yet. We should
* really have the struct_rwlock to access
* db_blkptr, but since this is just a guess,
* it's OK if we get an odd answer.
*/
}
}
int parent_held = FALSE;
parent_held = TRUE;
}
if (drop_struct_lock)
if (parent_held)
/*
* Since we've dropped the mutex, it's possible that
* dbuf_undirty() might have changed this out from under us.
*/
}
} else {
if (drop_struct_lock)
}
return (dr);
}
/*
* Undirty a buffer in the transaction group referenced by the given
* transaction. Return whether this evicted the dbuf.
*/
static boolean_t
{
/*
* Due to our use of dn_nlevels below, this can only be called
* in open context, unless we are operating on the MOS.
* From syncing context, dn_nlevels may be different from the
* dn_nlevels used when dbuf was dirtied.
*/
/*
* If this buffer is not dirty, we're done.
*/
break;
return (B_FALSE);
/*
* Note that there are three places in dbuf_dirty()
* where this dirty record may be put on a list.
* Make sure to do a list_remove corresponding to
* every one of those list_insert calls.
*/
}
}
return (B_TRUE);
}
return (B_FALSE);
}
void
{
/*
* Quick check for dirtyness. For already dirty blocks, this
* reduces runtime of this function by >90%, and overall performance
* by 50% for some workloads (e.g. file deletion with indirect blocks
* cached).
*/
/*
* It's possible that it is already dirty but not cached,
* because there are some calls to dbuf_dirty() that don't
* go through dmu_buf_will_dirty().
*/
/* This dbuf is already dirty and cached. */
return;
}
}
rf |= DB_RF_HAVESTRUCT;
}
void
{
}
void
{
}
/* ARGSUSED */
void
{
/* we were freed while filling */
/* XXX dbuf_undirty? */
}
}
}
void
{
struct dirty_leaf *dl;
if (etype == BP_EMBEDDED_TYPE_DATA) {
}
}
/*
* Directly assign a provided arc buf to a given dbuf if it's not referenced
* by anybody except our caller. Otherwise copy arcbuf's contents to dbuf.
*/
void
{
return;
}
}
}
}
}
void
{
}
}
(void) refcount_remove_many(&dbuf_cache_size,
}
/*
* Now that db_state is DB_EVICTING, nobody else can find this via
* the hash table. We can now drop db_mtx, which allows us to
* acquire the dn_dbufs_mtx.
*/
if (needlock)
if (needlock)
/*
* Decrementing the dbuf count means that the hold corresponding
* to the removed dbuf is no longer discounted in dnode_move(),
* so the dnode cannot be moved until after we release the hold.
* The membar_producer() ensures visibility of the decremented
* value in dnode_move(), since DB_DNODE_EXIT doesn't actually
* release any lock.
*/
} else {
}
/*
* If this dbuf is referenced from an indirect dbuf,
* decrement the ref count on the indirect dbuf.
*/
}
/*
* Note: While bpp will always be updated if the function returns success,
* parentp will not be updated if the dnode does not have dn_dbuf filled in;
* this happens when the dnode is the meta-dnode, or a userused or groupused
* object.
*/
static int
{
if (blkid == DMU_SPILL_BLKID) {
if (dn->dn_have_spill &&
else
return (0);
}
nlevels = 1;
else
/* the buffer has no parent yet */
/* this block is referenced from an indirect block */
if (err)
return (err);
if (err) {
return (err);
}
return (0);
} else {
/* the block is referenced from the dnode */
}
return (0);
}
}
static dmu_buf_impl_t *
{
db->db_dirtycnt = 0;
if (blkid == DMU_BONUS_BLKID) {
/* the bonus dbuf is not placed in the hash table */
return (db);
} else if (blkid == DMU_SPILL_BLKID) {
} else {
int blocksize =
}
/*
* Hold the dn_dbufs_mtx while we get the new dbuf
* in the hash table *and* added to the dbufs list.
* This prevents a possible deadlock with someone
* trying to look up this dbuf before its added to the
* dn_dbufs list.
*/
/* someone else inserted it first */
return (odb);
}
return (db);
}
typedef struct dbuf_prefetch_arg {
int dpa_epbs; /* Entries (blkptr_t's) Per Block Shift. */
int dpa_curlevel; /* The current level that we're reading */
/*
* Actually issue the prefetch read for the block given.
*/
static void
{
return;
}
/*
* Called when an indirect block above our prefetch target is read in. This
* will either read in the next indirect block down the tree or issue the actual
* prefetch if the next block down is our target.
*/
static void
{
/*
* The dpa_dnode is only valid if we are called with a NULL
* zio. This indicates that the arc_read() returned without
* first calling zio_read() to issue a physical read. Once
* a physical read is made the dpa_dnode must be invalidated
* as the locks guarding it may have been dropped. If the
* dpa_dnode is still valid, then we want to add it to the dbuf
* cache. To do so, we must hold the dbuf associated with the block
* we just prefetched, read its contents so that we associate it
* with an arc_buf_t, and then release it.
*/
} else {
}
}
dpa->dpa_curlevel--;
} else {
&iter_aflags, &zb);
}
}
/*
* Issue prefetch reads for the given block on the given level. If the indirect
* blocks above that block are not in memory, we will read them in
* asynchronously. As a result, this call never blocks waiting for a read to
* complete.
*/
void
{
return;
return;
/*
* This dnode hasn't been written to disk yet, so there's nothing to
* prefetch.
*/
return;
return;
/*
* This dbuf already exists. It is either CACHED, or
* (we assume) about to be read or filled.
*/
return;
}
/*
* Find the closest ancestor (indirect block) of the target block
* that is present in the cache. In this indirect block, we will
* find the bp that is at curlevel, curblkid.
*/
break;
}
}
/* No cached indirect blocks found. */
}
if (BP_IS_HOLE(&bp))
return;
/*
* If we have the indirect just above us, no need to do the asynchronous
* prefetch chain; we'll just run the last step ourselves. If we're at
* a higher level, though, we want to issue the prefetches for all the
* indirect blocks asynchronously, so we can go on with whatever we were
* doing.
*/
} else {
&iter_aflags, &zb);
}
/*
* We use pio here instead of dpa_zio since it's possible that
* dpa may have already been freed.
*/
}
/*
* Returns with db_holds incremented, and db_mtx not held.
* Note: dn_struct_rwlock must be held.
*/
int
{
top:
/* dbuf_find() returns with db_mtx held */
int err;
if (fail_uncached)
if (fail_sparse) {
if (err) {
if (parent)
return (err);
}
}
return (err);
}
}
/*
* If this buffer is currently syncing out, and we are are
* still referencing it from db_data, we need to make a copy
* of it in case we decide we want to dirty it again in this txg.
*/
}
}
(void) refcount_remove_many(&dbuf_cache_size,
}
/* NOTE: we can't rele the parent until after we drop the db_mtx */
if (parent)
return (0);
}
{
}
{
}
void
{
}
int
{
if (blksz == 0)
return (0);
}
void
{
}
void
{
}
void *tag)
{
else
}
}
return (result);
}
/*
* If you call dbuf_rele() you had better not be referencing the dnode handle
* unless you have some other direct or indirect hold on the dnode. (An indirect
* hold is a hold on one of the dnode's dbufs, including the bonus buffer.)
* Without that, the dbuf_rele() could lead to a dnode_rele() followed by the
* dnode's parent dbuf evicting its dnode handles.
*/
void
{
}
void
{
}
/*
* dbuf_rele() for an already-locked dbuf. This is necessary to allow
* db_dirtycnt and db_holds to be updated atomically.
*/
void
{
/*
* Remove the reference to the dbuf before removing its hold on the
* dnode so we can guarantee in dnode_move() that a referenced bonus
* buffer has a corresponding dnode hold.
*/
/*
* We can't freeze indirects if there is a possibility that they
* may be modified in the current syncing context.
*/
}
if (holds == 0) {
/*
* If the dnode moves here, we cannot cross this
* barrier until the move completes.
*/
/*
* Decrementing the dbuf count means that the bonus
* buffer's dnode hold is no longer discounted in
* dnode_move(). The dnode cannot move until after
* the dnode_rele() below.
*/
/*
* Do not reference db after its lock is dropped.
* Another thread may evict it.
*/
if (evict_dbuf)
/*
* This is a special case: we never associated this
* dbuf with any data allocated from the ARC.
*/
/*
* This dbuf has anonymous data associated with it.
*/
} else {
if (!DBUF_IS_CACHEABLE(db) &&
}
if (!DBUF_IS_CACHEABLE(db) ||
db->db_pending_evict) {
(void) refcount_add_many(&dbuf_cache_size,
}
if (do_arc_evict)
}
} else {
}
}
{
}
void *
{
else
return (old_user);
}
void *
{
}
void *
{
}
void *
{
}
void *
{
}
void
{
}
{
return (res);
}
blkptr_t *
{
}
objset_t *
{
}
static void
{
/* ASSERT(dmu_tx_is_syncing(tx) */
return;
return;
}
/*
* This buffer was allocated at a time when there was
* no available blkptrs from the dnode, or it was
* inappropriate to hook it in (i.e., nlevels mis-match).
*/
} else {
}
}
}
static void
{
/* Read the block if it hasn't been read yet. */
}
/* Indirect block size must match what the dnode thinks it is. */
/* Provide the pending dirty record to child dbufs */
}
static void
{
/*
* To be synced, we must be dirtied. But we
* might have been freed after the dirty.
*/
/* This buffer has been freed since it was dirtied */
/* This buffer was freed and is now being re-filled */
} else {
}
}
/*
* If this is a bonus buffer, simply copy the bonus data into the
* dnode. It will be written out when the dnode is synced (and it
* will be synced, since it must have been dirty for dbuf_sync to
* be called).
*/
}
return;
}
/*
* This function may have dropped the db_mtx lock allowing a dmu_sync
* operation to sneak in. As a result, we need to ensure that we
* don't check the dr_override_state until we have returned from
* dbuf_check_blkptr.
*/
/*
* If this buffer is in the middle of an immediate write,
* wait for the synchronous IO to complete.
*/
}
/*
* If this buffer is currently "in use" (i.e., there
* are active holds and db_data still references it),
* then make a copy before we start the write so that
* any modifications from the open txg will not leak
* into this write.
*
* NOTE: this copy does not need to be made for
* objects only modified in the syncing context (e.g.
* DNONE_DNODE blocks).
*/
}
} else {
/*
* Although zio_nowait() does not "wait for an IO", it does
* initiate the IO. If this is an empty write it seems plausible
* that the IO could actually be completed before the nowait
* returns. We need to DB_DNODE_EXIT() first in case
* zio_nowait() invalidates the dbuf.
*/
}
}
void
{
/*
* If we find an already initialized zio then we
* are processing the meta-dnode, and we have finished.
* The dbufs for all dnodes are put back on the list
* during processing, so that we can zio_wait()
* these IOs after initiating all child IOs.
*/
break;
}
}
else
}
}
/* ARGSUSED */
static void
{
int i;
BP_IS_EMBEDDED(bp));
}
#ifdef ZFS_DEBUG
}
#endif
i--, dnp++) {
fill++;
}
} else {
if (BP_IS_HOLE(bp)) {
fill = 0;
} else {
fill = 1;
}
}
} else {
if (BP_IS_HOLE(ibp))
continue;
}
}
if (!BP_IS_EMBEDDED(bp))
}
/* ARGSUSED */
/*
* This function gets called just prior to running through the compression
* stage of the zio pipeline. If we're an indirect block comprised of only
* holes, then we want this indirect to be compressed away to a hole. In
* order to do that we must zero out any information about the holes that
* this indirect points to prior to before we try to compress it.
*/
static void
{
uint64_t i;
int epbs;
/* Determine if all our children are holes */
if (!BP_IS_HOLE(bp))
break;
}
/*
* If all the children are holes, then zero them all out so that
* we may get compressed away.
*/
if (i == 1 << epbs) {
/* didn't find any non-holes */
}
}
/*
* The SPA will call this callback several times for each zio - once
* for every physical child i/o (zio->io_phys_children times). This
* allows the DMU to monitor the progress of each logical i/o. For example,
* there may be 2 copies of an indirect block, or many fragments of a RAID-Z
* so this callback allows us to retire dirty space gradually, as the physical
*/
/* ARGSUSED */
static void
{
int delta = 0;
/*
* The callback will be called io_phys_children times. Retire one
* portion of our dirty space each time we are called. Any rounding
* error will be cleaned up by dsl_pool_sync()'s call to
* dsl_pool_undirty_space().
*/
}
/* ARGSUSED */
static void
{
/*
* For nopwrites and rewrites we ensure that the bp matches our
* original and bypass all the accounting.
*/
} else {
}
#ifdef ZFS_DEBUG
}
#endif
}
} else {
int epbs =
}
}
}
static void
{
}
static void
{
}
static void
{
}
static void
{
if (!BP_IS_HOLE(obp))
}
}
/* Issue I/O to commit a dirty buffer to disk. */
static void
{
int wp_flag = 0;
/*
* Private object buffers are released here rather
* than in dbuf_dirty() since they are only modified
* in the syncing context and we don't want the
* overhead of making multiple copies of the data.
*/
} else {
}
}
}
/* Our parent is an indirect block. */
/* We have a dirty parent that has been scheduled for write. */
/* Our parent's buffer is one level closer to the dnode. */
/*
* We're about to modify our parent's db_data by modifying
* our block pointer, so the parent must be released.
*/
} else {
/* Our parent is the dnode itself. */
}
/*
* We copy the blkptr now (rather than when we instantiate the dirty
* record), because its value can change between open context and
* syncing context. We do not need to hold dn_struct_rwlock to read
* db_blkptr because we are in syncing context.
*/
/*
* The BP for this block has been provided by open context
* (by dmu_sync() or dmu_buf_write_embedded()).
*/
} else {
/*
* For indirect blocks, we want to setup the children
* ready callback so that we can properly handle an indirect
* block that only contains holes.
*/
}
}