FreeBSD ZFS
The Zettabyte File System
Defines | Functions | Variables

dbuf.c File Reference

#include <sys/zfs_context.h>
#include <sys/dmu.h>
#include <sys/dmu_impl.h>
#include <sys/dbuf.h>
#include <sys/dmu_objset.h>
#include <sys/dsl_dataset.h>
#include <sys/dsl_dir.h>
#include <sys/dmu_tx.h>
#include <sys/spa.h>
#include <sys/zio.h>
#include <sys/dmu_zfetch.h>
#include <sys/sa.h>
#include <sys/sa_impl.h>
Include dependency graph for dbuf.c:

Go to the source code of this file.

Defines

#define DBUF_HASH(os, obj, level, blkid)   dbuf_hash(os, obj, level, blkid);
#define DBUF_EQUAL(dbuf, os, obj, level, blkid)

Functions

static void dbuf_destroy (dmu_buf_impl_t *db)
static int dbuf_undirty (dmu_buf_impl_t *db, dmu_tx_t *tx)
 Undirty a buffer, clearing dirty records.
static void dbuf_write (dbuf_dirty_record_t *dr, arc_buf_t *data, dmu_tx_t *tx)
 Commit a dirty buffer to disk.
static int dbuf_cons (void *vdb, void *unused, int kmflag)
static void dbuf_dest (void *vdb, void *unused)
static uint64_t dbuf_hash (void *os, uint64_t obj, uint8_t lvl, uint64_t blkid)
dmu_buf_impl_tdbuf_find (dnode_t *dn, uint8_t level, uint64_t blkid)
static dmu_buf_impl_tdbuf_hash_insert (dmu_buf_impl_t *db)
 Insert an entry into the hash table.
static void dbuf_hash_remove (dmu_buf_impl_t *db)
 Remove an entry from the hash table.
static void dbuf_evict_user (dmu_buf_impl_t *db)
boolean_t dbuf_is_metadata (dmu_buf_impl_t *db)
void dbuf_evict (dmu_buf_impl_t *db)
void dbuf_init (void)
void dbuf_fini (void)
static void dbuf_update_data (dmu_buf_impl_t *db)
static void dbuf_set_data (dmu_buf_impl_t *db, arc_buf_t *buf)
 Set the dbuf's buffer to the ARC buffer, including any associated state, such as db_data.
arc_buf_tdbuf_loan_arcbuf (dmu_buf_impl_t *db)
 Loan out an arc_buf for read.
uint64_t dbuf_whichblock (dnode_t *dn, uint64_t offset)
static void dbuf_read_done (zio_t *zio, arc_buf_t *buf, void *vdb)
static void dbuf_read_impl (dmu_buf_impl_t *db, zio_t *zio, uint32_t *flags)
int dbuf_read (dmu_buf_impl_t *db, zio_t *zio, uint32_t flags)
static void dbuf_noread (dmu_buf_impl_t *db)
static void dbuf_fix_old_data (dmu_buf_impl_t *db, uint64_t txg)
 This is our just-in-time copy function.
void dbuf_unoverride (dbuf_dirty_record_t *dr)
 Signal that the dirty record is about to be re-dirtied after sync.
void dbuf_free_range (dnode_t *dn, uint64_t start, uint64_t end, dmu_tx_t *tx)
 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.
static int dbuf_block_freeable (dmu_buf_impl_t *db)
void dbuf_new_size (dmu_buf_impl_t *db, int size, dmu_tx_t *tx)
void dbuf_release_bp (dmu_buf_impl_t *db)
dbuf_dirty_record_tdbuf_dirty (dmu_buf_impl_t *db, dmu_tx_t *tx)
 Mark a dbuf as dirty.
void dbuf_will_dirty (dmu_buf_impl_t *db, dmu_tx_t *tx)
void dmu_buf_will_not_fill (dmu_buf_t *db_fake, dmu_tx_t *tx)
void dmu_buf_will_fill (dmu_buf_t *db_fake, dmu_tx_t *tx)
void dbuf_fill_done (dmu_buf_impl_t *db, dmu_tx_t *tx)
void dbuf_assign_arcbuf (dmu_buf_impl_t *db, arc_buf_t *buf, dmu_tx_t *tx)
 Directly assign a provided arc buf to a given dbuf if it's not referenced by anybody except our caller.
void dbuf_clear (dmu_buf_impl_t *db)
 "Clear" the contents of this dbuf.
static int dbuf_findbp (dnode_t *dn, int level, uint64_t blkid, int fail_sparse, dmu_buf_impl_t **parentp, blkptr_t **bpp)
static dmu_buf_impl_tdbuf_create (dnode_t *dn, uint8_t level, uint64_t blkid, dmu_buf_impl_t *parent, blkptr_t *blkptr)
static int dbuf_do_evict (void *private)
void dbuf_prefetch (dnode_t *dn, uint64_t blkid)
int dbuf_hold_impl (dnode_t *dn, uint8_t level, uint64_t blkid, int fail_sparse, void *tag, dmu_buf_impl_t **dbp)
 Returns with db_holds incremented, and db_mtx not held.
dmu_buf_impl_tdbuf_hold (dnode_t *dn, uint64_t blkid, void *tag)
dmu_buf_impl_tdbuf_hold_level (dnode_t *dn, int level, uint64_t blkid, void *tag)
void dbuf_create_bonus (dnode_t *dn)
int dbuf_spill_set_blksz (dmu_buf_t *db_fake, uint64_t blksz, dmu_tx_t *tx)
void dbuf_rm_spill (dnode_t *dn, dmu_tx_t *tx)
void dbuf_add_ref (dmu_buf_impl_t *db, void *tag)
void dbuf_rele (dmu_buf_impl_t *db, void *tag)
void dbuf_rele_and_unlock (dmu_buf_impl_t *db, void *tag)
 dbuf_rele() for an already-locked dbuf.
uint64_t dbuf_refcount (dmu_buf_impl_t *db)
void * dmu_buf_set_user (dmu_buf_t *db_fake, void *user_ptr, void *user_data_ptr_ptr, dmu_buf_evict_func_t *evict_func)
void * dmu_buf_set_user_ie (dmu_buf_t *db_fake, void *user_ptr, void *user_data_ptr_ptr, dmu_buf_evict_func_t *evict_func)
 The same as set_user, but request immediate eviction when hold count goes to zero.
void * dmu_buf_update_user (dmu_buf_t *db_fake, void *old_user_ptr, void *user_ptr, void *user_data_ptr_ptr, dmu_buf_evict_func_t *evict_func)
void * dmu_buf_get_user (dmu_buf_t *db_fake)
boolean_t dmu_buf_freeable (dmu_buf_t *dbuf)
 Tells if the given dbuf is freeable.
static void dbuf_check_blkptr (dnode_t *dn, dmu_buf_impl_t *db)
static void dbuf_sync_indirect (dbuf_dirty_record_t *dr, dmu_tx_t *tx)
static void dbuf_sync_leaf (dbuf_dirty_record_t *dr, dmu_tx_t *tx)
void dbuf_sync_list (list_t *list, dmu_tx_t *tx)
static void dbuf_write_ready (zio_t *zio, arc_buf_t *buf, void *vdb)
static void dbuf_write_done (zio_t *zio, arc_buf_t *buf, void *vdb)
static void dbuf_write_nofill_ready (zio_t *zio)
static void dbuf_write_nofill_done (zio_t *zio)
static void dbuf_write_override_ready (zio_t *zio)
static void dbuf_write_override_done (zio_t *zio)

Variables

static kmem_cache_t * dbuf_cache
 Global data structures and functions for the dbuf cache.
static dbuf_hash_table_t dbuf_hash_table
 dbuf hash table routines
static uint64_t dbuf_hash_count
static arc_evict_func_t dbuf_do_evict

Define Documentation

#define DBUF_EQUAL (   dbuf,
  os,
  obj,
  level,
  blkid 
)
Value:
((dbuf)->db.db_object == (obj) &&               \
        (dbuf)->db_objset == (os) &&                    \
        (dbuf)->db_level == (level) &&                  \
        (dbuf)->db_blkid == (blkid))

Definition at line 101 of file dbuf.c.

#define DBUF_HASH (   os,
  obj,
  level,
  blkid 
)    dbuf_hash(os, obj, level, blkid);

Definition at line 99 of file dbuf.c.


Function Documentation

void dbuf_add_ref ( dmu_buf_impl_t db,
void *  tag 
)

Definition at line 2045 of file dbuf.c.

void dbuf_assign_arcbuf ( dmu_buf_impl_t db,
arc_buf_t buf,
dmu_tx_t tx 
)

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.

Definition at line 1481 of file dbuf.c.

static int dbuf_block_freeable ( dmu_buf_impl_t db) [static]

Definition at line 918 of file dbuf.c.

static void dbuf_check_blkptr ( dnode_t dn,
dmu_buf_impl_t db 
) [static]

Definition at line 2235 of file dbuf.c.

void dbuf_clear ( dmu_buf_impl_t db)

"Clear" the contents of this dbuf.

This will mark the dbuf EVICTING and clear *most* of its references. Unfortunately, when we are not holding the dn_dbufs_mtx, we can't clear the entry in the dn_dbufs list. We have to wait until dbuf_destroy() in this case.

For callers from the DMU we will usually see:

For the arc callback, we will usually see:

Sometimes, though, we will get a mix of these two:

Definition at line 1564 of file dbuf.c.

static int dbuf_cons ( void *  vdb,
void *  unused,
int  kmflag 
) [static]

Definition at line 52 of file dbuf.c.

static dmu_buf_impl_t* dbuf_create ( dnode_t dn,
uint8_t  level,
uint64_t  blkid,
dmu_buf_impl_t parent,
blkptr_t blkptr 
) [static]

Definition at line 1696 of file dbuf.c.

void dbuf_create_bonus ( dnode_t dn)

Definition at line 2004 of file dbuf.c.

static void dbuf_dest ( void *  vdb,
void *  unused 
) [static]

Definition at line 65 of file dbuf.c.

static void dbuf_destroy ( dmu_buf_impl_t db) [static]

Definition at line 1801 of file dbuf.c.

dbuf_dirty_record_t* dbuf_dirty ( dmu_buf_impl_t db,
dmu_tx_t tx 
)

Mark a dbuf as dirty.

Definition at line 1025 of file dbuf.c.

static int dbuf_do_evict ( void *  private) [static]

Definition at line 1778 of file dbuf.c.

void dbuf_evict ( dmu_buf_impl_t db)

Definition at line 239 of file dbuf.c.

static void dbuf_evict_user ( dmu_buf_impl_t db) [static]

Definition at line 207 of file dbuf.c.

void dbuf_fill_done ( dmu_buf_impl_t db,
dmu_tx_t tx 
)

Definition at line 1457 of file dbuf.c.

dmu_buf_impl_t* dbuf_find ( dnode_t dn,
uint8_t  level,
uint64_t  blkid 
)

Definition at line 108 of file dbuf.c.

static int dbuf_findbp ( dnode_t dn,
int  level,
uint64_t  blkid,
int  fail_sparse,
dmu_buf_impl_t **  parentp,
blkptr_t **  bpp 
) [static]

Definition at line 1629 of file dbuf.c.

void dbuf_fini ( void  )

Definition at line 283 of file dbuf.c.

static void dbuf_fix_old_data ( dmu_buf_impl_t db,
uint64_t  txg 
) [static]

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.

Definition at line 728 of file dbuf.c.

void dbuf_free_range ( dnode_t dn,
uint64_t  start,
uint64_t  end,
dmu_tx_t tx 
)

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.

Also, if we happen accross any level-1 dbufs in the range that have not already been marked dirty, mark them dirty so they stay in memory.

Definition at line 818 of file dbuf.c.

static uint64_t dbuf_hash ( void *  os,
uint64_t  obj,
uint8_t  lvl,
uint64_t  blkid 
) [static]

Definition at line 81 of file dbuf.c.

static dmu_buf_impl_t* dbuf_hash_insert ( dmu_buf_impl_t db) [static]

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.

Definition at line 139 of file dbuf.c.

static void dbuf_hash_remove ( dmu_buf_impl_t db) [static]

Remove an entry from the hash table.

This operation will fail if there are any existing holds on the db.

Definition at line 176 of file dbuf.c.

dmu_buf_impl_t* dbuf_hold ( dnode_t dn,
uint64_t  blkid,
void *  tag 
)

Definition at line 1988 of file dbuf.c.

int dbuf_hold_impl ( dnode_t dn,
uint8_t  level,
uint64_t  blkid,
int  fail_sparse,
void *  tag,
dmu_buf_impl_t **  dbp 
)

Returns with db_holds incremented, and db_mtx not held.

Note:
dn_struct_rwlock must be held.

Definition at line 1900 of file dbuf.c.

dmu_buf_impl_t* dbuf_hold_level ( dnode_t dn,
int  level,
uint64_t  blkid,
void *  tag 
)

Definition at line 1996 of file dbuf.c.

void dbuf_init ( void  )

Definition at line 250 of file dbuf.c.

boolean_t dbuf_is_metadata ( dmu_buf_impl_t db)

Definition at line 223 of file dbuf.c.

arc_buf_t* dbuf_loan_arcbuf ( dmu_buf_impl_t db)

Loan out an arc_buf for read.

Returns:
the loaned arc_buf.

Definition at line 448 of file dbuf.c.

void dbuf_new_size ( dmu_buf_impl_t db,
int  size,
dmu_tx_t tx 
)

Definition at line 948 of file dbuf.c.

static void dbuf_noread ( dmu_buf_impl_t db) [static]

Definition at line 690 of file dbuf.c.

void dbuf_prefetch ( dnode_t dn,
uint64_t  blkid 
)

Definition at line 1845 of file dbuf.c.

int dbuf_read ( dmu_buf_impl_t db,
zio_t zio,
uint32_t  flags 
)

Definition at line 600 of file dbuf.c.

static void dbuf_read_done ( zio_t zio,
arc_buf_t buf,
void *  vdb 
) [static]

Definition at line 482 of file dbuf.c.

static void dbuf_read_impl ( dmu_buf_impl_t db,
zio_t zio,
uint32_t *  flags 
) [static]

Definition at line 516 of file dbuf.c.

uint64_t dbuf_refcount ( dmu_buf_impl_t db)

Definition at line 2163 of file dbuf.c.

void dbuf_rele ( dmu_buf_impl_t db,
void *  tag 
)
Note:
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.

Definition at line 2062 of file dbuf.c.

void dbuf_rele_and_unlock ( dmu_buf_impl_t db,
void *  tag 
)

dbuf_rele() for an already-locked dbuf.

This is necessary to allow db_dirtycnt and db_holds to be updated atomically.

Definition at line 2073 of file dbuf.c.

void dbuf_release_bp ( dmu_buf_impl_t db)

Definition at line 1001 of file dbuf.c.

void dbuf_rm_spill ( dnode_t dn,
dmu_tx_t tx 
)

Definition at line 2038 of file dbuf.c.

static void dbuf_set_data ( dmu_buf_impl_t db,
arc_buf_t buf 
) [static]

Set the dbuf's buffer to the ARC buffer, including any associated state, such as db_data.

Definition at line 423 of file dbuf.c.

int dbuf_spill_set_blksz ( dmu_buf_t db_fake,
uint64_t  blksz,
dmu_tx_t tx 
)

Definition at line 2013 of file dbuf.c.

static void dbuf_sync_indirect ( dbuf_dirty_record_t dr,
dmu_tx_t tx 
) [static]

Definition at line 2280 of file dbuf.c.

static void dbuf_sync_leaf ( dbuf_dirty_record_t dr,
dmu_tx_t tx 
) [static]

Definition at line 2326 of file dbuf.c.

void dbuf_sync_list ( list_t *  list,
dmu_tx_t tx 
)

Definition at line 2466 of file dbuf.c.

static int dbuf_undirty ( dmu_buf_impl_t db,
dmu_tx_t tx 
) [static]

Undirty a buffer, clearing dirty records.

Definition at line 1302 of file dbuf.c.

void dbuf_unoverride ( dbuf_dirty_record_t dr)

Signal that the dirty record is about to be re-dirtied after sync.

This function is used to notify, if necessary, that a dbuf is about to be dirtied again after having an immediate write via dmu_sync().

Definition at line 775 of file dbuf.c.

static void dbuf_update_data ( dmu_buf_impl_t db) [static]

Definition at line 409 of file dbuf.c.

uint64_t dbuf_whichblock ( dnode_t dn,
uint64_t  offset 
)

Definition at line 471 of file dbuf.c.

void dbuf_will_dirty ( dmu_buf_impl_t db,
dmu_tx_t tx 
)

Definition at line 1412 of file dbuf.c.

static void dbuf_write ( dbuf_dirty_record_t dr,
arc_buf_t data,
dmu_tx_t tx 
) [static]

Commit a dirty buffer to disk.

Definition at line 2726 of file dbuf.c.

static void dbuf_write_done ( zio_t zio,
arc_buf_t buf,
void *  vdb 
) [static]

Definition at line 2569 of file dbuf.c.

static void dbuf_write_nofill_done ( zio_t zio) [static]

Definition at line 2690 of file dbuf.c.

static void dbuf_write_nofill_ready ( zio_t zio) [static]

Definition at line 2684 of file dbuf.c.

static void dbuf_write_override_done ( zio_t zio) [static]

Definition at line 2705 of file dbuf.c.

static void dbuf_write_override_ready ( zio_t zio) [static]

Definition at line 2696 of file dbuf.c.

static void dbuf_write_ready ( zio_t zio,
arc_buf_t buf,
void *  vdb 
) [static]

Definition at line 2493 of file dbuf.c.

boolean_t dmu_buf_freeable ( dmu_buf_t dbuf)

Tells if the given dbuf is freeable.

Definition at line 2222 of file dbuf.c.

void* dmu_buf_get_user ( dmu_buf_t db)
Returns:
The user_ptr set with dmu_buf_set_user(), or NULL if not set.

Definition at line 2213 of file dbuf.c.

void* dmu_buf_set_user ( dmu_buf_t db,
void *  user_ptr,
void *  user_data_ptr_ptr,
dmu_buf_evict_func_t evict_func 
)
Parameters:
user_ptrFor use by the user and can be obtained via dmu_buf_get_user()
user_data_ptr_ptrShould be NULL, or a pointer to a pointer which will be set to db->db_data when the caller is allowed to access it. Note that db->db_data can change when dmu_buf_read, dmu_buf_tryupgrade, dmu_buf_will_dirty, or dmu_buf_will_fill are called. *user_data_ptr_ptr will be set to the new value when it changes.
evict_funcIf not NULL, evict_func will be called when this buffer is being excised from the cache, so that the data structure pointed to by user_data_ptr_ptr can be cleaned up.
Returns:
NULL on success, or the existing user ptr if it's already been set.

dmu_evict_user() will call the evict_func for all buffers in a objset with a given pageout func.

Definition at line 2169 of file dbuf.c.

void* dmu_buf_set_user_ie ( dmu_buf_t db_fake,
void *  user_ptr,
void *  user_data_ptr_ptr,
dmu_buf_evict_func_t evict_func 
)

The same as set_user, but request immediate eviction when hold count goes to zero.

Definition at line 2177 of file dbuf.c.

void* dmu_buf_update_user ( dmu_buf_t db_fake,
void *  old_user_ptr,
void *  user_ptr,
void *  user_data_ptr_ptr,
dmu_buf_evict_func_t evict_func 
)

Definition at line 2188 of file dbuf.c.

void dmu_buf_will_fill ( dmu_buf_t db_fake,
dmu_tx_t tx 
)

Definition at line 1438 of file dbuf.c.

void dmu_buf_will_not_fill ( dmu_buf_t db_fake,
dmu_tx_t tx 
)

Definition at line 1428 of file dbuf.c.


Variable Documentation

kmem_cache_t* dbuf_cache [static]

Global data structures and functions for the dbuf cache.

Definition at line 48 of file dbuf.c.

arc_evict_func_t dbuf_do_evict [static]

Definition at line 204 of file dbuf.c.

uint64_t dbuf_hash_count [static]

Definition at line 78 of file dbuf.c.

dbuf hash table routines

Definition at line 76 of file dbuf.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines