]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - include/sys/dnode.h
New upstream version 0.7.2
[mirror_zfs-debian.git] / include / sys / dnode.h
index 50e01155903aa3e2b7b1be879dd31e62ddcba5e6..c7efe55935660dff29503b2bde2e7345e0ec46f4 100644 (file)
@@ -20,7 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
+ * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
  */
 
@@ -35,6 +35,7 @@
 #include <sys/refcount.h>
 #include <sys/dmu_zfetch.h>
 #include <sys/zrlock.h>
+#include <sys/multilist.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -57,8 +58,14 @@ extern "C" {
  * Fixed constants.
  */
 #define        DNODE_SHIFT             9       /* 512 bytes */
-#define        DN_MIN_INDBLKSHIFT      10      /* 1k */
-#define        DN_MAX_INDBLKSHIFT      14      /* 16k */
+#define        DN_MIN_INDBLKSHIFT      12      /* 4k */
+/*
+ * If we ever increase this value beyond 20, we need to revisit all logic that
+ * does x << level * ebps to handle overflow.  With a 1M indirect block size,
+ * 4 levels of indirect blocks would not be able to guarantee addressing an
+ * entire object, so 5 levels will be used, but 5 * (20 - 7) = 65.
+ */
+#define        DN_MAX_INDBLKSHIFT      17      /* 128k */
 #define        DNODE_BLOCK_SHIFT       14      /* 16k */
 #define        DNODE_CORE_SIZE         64      /* 64 bytes for dnode sans blkptrs */
 #define        DN_MAX_OBJECT_SHIFT     48      /* 256 trillion (zfs_fid_t limit) */
@@ -79,21 +86,39 @@ extern "C" {
 /*
  * Derived constants.
  */
-#define        DNODE_SIZE      (1 << DNODE_SHIFT)
-#define        DN_MAX_NBLKPTR  ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
-#define        DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
+#define        DNODE_MIN_SIZE          (1 << DNODE_SHIFT)
+#define        DNODE_MAX_SIZE          (1 << DNODE_BLOCK_SHIFT)
+#define        DNODE_BLOCK_SIZE        (1 << DNODE_BLOCK_SHIFT)
+#define        DNODE_MIN_SLOTS         (DNODE_MIN_SIZE >> DNODE_SHIFT)
+#define        DNODE_MAX_SLOTS         (DNODE_MAX_SIZE >> DNODE_SHIFT)
+#define        DN_BONUS_SIZE(dnsize)   ((dnsize) - DNODE_CORE_SIZE - \
+       (1 << SPA_BLKPTRSHIFT))
+#define        DN_SLOTS_TO_BONUSLEN(slots)     DN_BONUS_SIZE((slots) << DNODE_SHIFT)
+#define        DN_OLD_MAX_BONUSLEN     (DN_BONUS_SIZE(DNODE_MIN_SIZE))
+#define        DN_MAX_NBLKPTR  ((DNODE_MIN_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
 #define        DN_MAX_OBJECT   (1ULL << DN_MAX_OBJECT_SHIFT)
-#define        DN_ZERO_BONUSLEN        (DN_MAX_BONUSLEN + 1)
+#define        DN_ZERO_BONUSLEN        (DN_BONUS_SIZE(DNODE_MAX_SIZE) + 1)
 #define        DN_KILL_SPILLBLK (1)
 
+#define        DN_SLOT_UNINIT          ((void *)NULL)  /* Uninitialized */
+#define        DN_SLOT_FREE            ((void *)1UL)   /* Free slot */
+#define        DN_SLOT_ALLOCATED       ((void *)2UL)   /* Allocated slot */
+#define        DN_SLOT_INTERIOR        ((void *)3UL)   /* Interior allocated slot */
+#define        DN_SLOT_IS_PTR(dn)      ((void *)dn > DN_SLOT_INTERIOR)
+#define        DN_SLOT_IS_VALID(dn)    ((void *)dn != NULL)
+
 #define        DNODES_PER_BLOCK_SHIFT  (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
 #define        DNODES_PER_BLOCK        (1ULL << DNODES_PER_BLOCK_SHIFT)
+
+/*
+ * This is inaccurate if the indblkshift of the particular object is not the
+ * max.  But it's only used by userland to calculate the zvol reservation.
+ */
 #define        DNODES_PER_LEVEL_SHIFT  (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
 #define        DNODES_PER_LEVEL        (1ULL << DNODES_PER_LEVEL_SHIFT)
 
-/* The +2 here is a cheesy way to round up */
-#define        DN_MAX_LEVELS   (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \
-       (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT)))
+#define        DN_MAX_LEVELS   (DIV_ROUND_UP(DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT, \
+       DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT) + 1)
 
 #define        DN_BONUS(dnp)   ((void*)((dnp)->dn_bonus + \
        (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
@@ -114,11 +139,14 @@ enum dnode_dirtycontext {
 };
 
 /* Is dn_used in bytes?  if not, it's in multiples of SPA_MINBLOCKSIZE */
-#define        DNODE_FLAG_USED_BYTES           (1<<0)
-#define        DNODE_FLAG_USERUSED_ACCOUNTED   (1<<1)
+#define        DNODE_FLAG_USED_BYTES                   (1 << 0)
+#define        DNODE_FLAG_USERUSED_ACCOUNTED           (1 << 1)
 
 /* Does dnode have a SA spill blkptr in bonus? */
-#define        DNODE_FLAG_SPILL_BLKPTR (1<<2)
+#define        DNODE_FLAG_SPILL_BLKPTR                 (1 << 2)
+
+/* User/Group dnode accounting */
+#define        DNODE_FLAG_USEROBJUSED_ACCOUNTED        (1 << 3)
 
 typedef struct dnode_phys {
        uint8_t dn_type;                /* dmu_object_type_t */
@@ -131,7 +159,8 @@ typedef struct dnode_phys {
        uint8_t dn_flags;               /* DNODE_FLAG_* */
        uint16_t dn_datablkszsec;       /* data block size in 512b sectors */
        uint16_t dn_bonuslen;           /* length of dn_bonus */
-       uint8_t dn_pad2[4];
+       uint8_t dn_extra_slots;         /* # of subsequent slots consumed */
+       uint8_t dn_pad2[3];
 
        /* accounting is protected by dn_dirty_mtx */
        uint64_t dn_maxblkid;           /* largest allocated block ID */
@@ -140,8 +169,11 @@ typedef struct dnode_phys {
        uint64_t dn_pad3[4];
 
        /*
-        * The tail region is 448 bytes, and there are three ways to
-        * look at it.
+        * The tail region is 448 bytes for a 512 byte dnode, and
+        * correspondingly larger for larger dnode sizes. The spill
+        * block pointer, when present, is always at the end of the tail
+        * region. There are three ways this space may be used, using
+        * a 512 byte dnode for this diagram:
         *
         * 0       64      128     192     256     320     384     448 (offset)
         * +---------------+---------------+---------------+-------+
@@ -149,24 +181,28 @@ typedef struct dnode_phys {
         * +---------------+---------------+---------------+-------+
         * | dn_blkptr[0]  | dn_bonus[0..319]                      |
         * +---------------+-----------------------+---------------+
-        * | dn_blkptr[0]  | /                     | dn_spill      |
+        * | dn_blkptr[0]  | dn_bonus[0..191]      | dn_spill      |
         * +---------------+-----------------------+---------------+
         */
        union {
-               blkptr_t dn_blkptr[1+DN_MAX_BONUSLEN/sizeof (blkptr_t)];
+               blkptr_t dn_blkptr[1+DN_OLD_MAX_BONUSLEN/sizeof (blkptr_t)];
                struct {
                        blkptr_t __dn_ignore1;
-                       uint8_t dn_bonus[DN_MAX_BONUSLEN];
+                       uint8_t dn_bonus[DN_OLD_MAX_BONUSLEN];
                };
                struct {
                        blkptr_t __dn_ignore2;
-                       uint8_t __dn_ignore3[DN_MAX_BONUSLEN-sizeof (blkptr_t)];
+                       uint8_t __dn_ignore3[DN_OLD_MAX_BONUSLEN -
+                           sizeof (blkptr_t)];
                        blkptr_t dn_spill;
                };
        };
 } dnode_phys_t;
 
-typedef struct dnode {
+#define        DN_SPILL_BLKPTR(dnp)    (blkptr_t *)((char *)(dnp) + \
+       (((dnp)->dn_extra_slots + 1) << DNODE_SHIFT) - (1 << SPA_BLKPTRSHIFT))
+
+struct dnode {
        /*
         * Protects the structure of the dnode, including the number of levels
         * of indirection (dn_nlevels), dn_maxblkid, and dn_next_*
@@ -202,6 +238,7 @@ typedef struct dnode {
        uint32_t dn_datablksz;          /* in bytes */
        uint64_t dn_maxblkid;
        uint8_t dn_next_type[TXG_SIZE];
+       uint8_t dn_num_slots;           /* metadnode slots consumed on disk */
        uint8_t dn_next_nblkptr[TXG_SIZE];
        uint8_t dn_next_nlevels[TXG_SIZE];
        uint8_t dn_next_indblkshift[TXG_SIZE];
@@ -212,11 +249,9 @@ typedef struct dnode {
 
        /* protected by dn_dbufs_mtx; declared here to fill 32-bit hole */
        uint32_t dn_dbufs_count;        /* count of dn_dbufs */
-       /* There are no level-0 blocks of this blkid or higher in dn_dbufs */
-       uint64_t dn_unlisted_l0_blkid;
 
        /* protected by os_lock: */
-       list_node_t dn_dirty_link[TXG_SIZE];    /* next on dataset's dirty */
+       multilist_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */
 
        /* protected by dn_mtx: */
        kmutex_t dn_mtx;
@@ -242,7 +277,7 @@ typedef struct dnode {
         * duplicate entries, we order the dbufs by an arbitrary value -
         * their address in memory. This means that dn_dbufs cannot be used to
         * directly look up a dbuf. Instead, callers must use avl_walk, have
-        * a reference to the dbuf, or look up a non-existant node with
+        * a reference to the dbuf, or look up a non-existent node with
         * db_state = DB_SEARCH (see dbuf_free_range for an example).
         */
        avl_tree_t dn_dbufs;
@@ -264,7 +299,7 @@ typedef struct dnode {
 
        /* holds prefetch structure */
        struct zfetch   dn_zfetch;
-} dnode_t;
+};
 
 /*
  * Adds a level of indirection between the dbuf and the dnode to avoid
@@ -299,7 +334,7 @@ void dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx);
 
 int dnode_hold(struct objset *dd, uint64_t object,
     void *ref, dnode_t **dnp);
-int dnode_hold_impl(struct objset *dd, uint64_t object, int flag,
+int dnode_hold_impl(struct objset *dd, uint64_t object, int flag, int dn_slots,
     void *ref, dnode_t **dnp);
 boolean_t dnode_add_ref(dnode_t *dn, void *ref);
 void dnode_rele(dnode_t *dn, void *ref);
@@ -307,9 +342,9 @@ void dnode_rele_and_unlock(dnode_t *dn, void *tag);
 void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx);
 void dnode_sync(dnode_t *dn, dmu_tx_t *tx);
 void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
-    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
+    dmu_object_type_t bonustype, int bonuslen, int dn_slots, dmu_tx_t *tx);
 void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
-    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
+    dmu_object_type_t bonustype, int bonuslen, int dn_slots, dmu_tx_t *tx);
 void dnode_free(dnode_t *dn, dmu_tx_t *tx);
 void dnode_byteswap(dnode_phys_t *dnp);
 void dnode_buf_byteswap(void *buf, size_t size);
@@ -317,7 +352,6 @@ void dnode_verify(dnode_t *dn);
 int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx);
 void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx);
 void dnode_diduse_space(dnode_t *dn, int64_t space);
-void dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx);
 void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t);
 uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid);
 void dnode_init(void);
@@ -327,6 +361,144 @@ int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off,
 void dnode_evict_dbufs(dnode_t *dn);
 void dnode_evict_bonus(dnode_t *dn);
 
+#define        DNODE_IS_CACHEABLE(_dn)                                         \
+       ((_dn)->dn_objset->os_primary_cache == ZFS_CACHE_ALL ||         \
+       (DMU_OT_IS_METADATA((_dn)->dn_type) &&                          \
+       (_dn)->dn_objset->os_primary_cache == ZFS_CACHE_METADATA))
+
+#define        DNODE_META_IS_CACHEABLE(_dn)                                    \
+       ((_dn)->dn_objset->os_primary_cache == ZFS_CACHE_ALL ||         \
+       (_dn)->dn_objset->os_primary_cache == ZFS_CACHE_METADATA)
+
+/*
+ * Used for dnodestats kstat.
+ */
+typedef struct dnode_stats {
+       /*
+        * Number of failed attempts to hold a meta dnode dbuf.
+        */
+       kstat_named_t dnode_hold_dbuf_hold;
+       /*
+        * Number of failed attempts to read a meta dnode dbuf.
+        */
+       kstat_named_t dnode_hold_dbuf_read;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) was able
+        * to hold the requested object number which was allocated.  This is
+        * the common case when looking up any allocated object number.
+        */
+       kstat_named_t dnode_hold_alloc_hits;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) was not
+        * able to hold the request object number because it was not allocated.
+        */
+       kstat_named_t dnode_hold_alloc_misses;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) was not
+        * able to hold the request object number because the object number
+        * refers to an interior large dnode slot.
+        */
+       kstat_named_t dnode_hold_alloc_interior;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) needed
+        * to retry acquiring slot zrl locks due to contention.
+        */
+       kstat_named_t dnode_hold_alloc_lock_retry;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) did not
+        * need to create the dnode because another thread did so after
+        * dropping the read lock but before acquiring the write lock.
+        */
+       kstat_named_t dnode_hold_alloc_lock_misses;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) found
+        * a free dnode instantiated by dnode_create() but not yet allocated
+        * by dnode_allocate().
+        */
+       kstat_named_t dnode_hold_alloc_type_none;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) was able
+        * to hold the requested range of free dnode slots.
+        */
+       kstat_named_t dnode_hold_free_hits;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) was not
+        * able to hold the requested range of free dnode slots because
+        * at least one slot was allocated.
+        */
+       kstat_named_t dnode_hold_free_misses;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) was not
+        * able to hold the requested range of free dnode slots because
+        * after acquiring the zrl lock at least one slot was allocated.
+        */
+       kstat_named_t dnode_hold_free_lock_misses;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) needed
+        * to retry acquiring slot zrl locks due to contention.
+        */
+       kstat_named_t dnode_hold_free_lock_retry;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) requested
+        * a range of dnode slots which were held by another thread.
+        */
+       kstat_named_t dnode_hold_free_refcount;
+       /*
+        * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) requested
+        * a range of dnode slots which would overflow the dnode_phys_t.
+        */
+       kstat_named_t dnode_hold_free_overflow;
+       /*
+        * Number of times a dnode_hold(...) was attempted on a dnode
+        * which had already been unlinked in an earlier txg.
+        */
+       kstat_named_t dnode_hold_free_txg;
+       /*
+        * Number of new dnodes allocated by dnode_allocate().
+        */
+       kstat_named_t dnode_allocate;
+       /*
+        * Number of dnodes re-allocated by dnode_reallocate().
+        */
+       kstat_named_t dnode_reallocate;
+       /*
+        * Number of meta dnode dbufs evicted.
+        */
+       kstat_named_t dnode_buf_evict;
+       /*
+        * Number of times dmu_object_alloc*() reached the end of the existing
+        * object ID chunk and advanced to a new one.
+        */
+       kstat_named_t dnode_alloc_next_chunk;
+       /*
+        * Number of times multiple threads attempted to allocate a dnode
+        * from the same block of free dnodes.
+        */
+       kstat_named_t dnode_alloc_race;
+       /*
+        * Number of times dmu_object_alloc*() was forced to advance to the
+        * next meta dnode dbuf due to an error from  dmu_object_next().
+        */
+       kstat_named_t dnode_alloc_next_block;
+       /*
+        * Statistics for tracking dnodes which have been moved.
+        */
+       kstat_named_t dnode_move_invalid;
+       kstat_named_t dnode_move_recheck1;
+       kstat_named_t dnode_move_recheck2;
+       kstat_named_t dnode_move_special;
+       kstat_named_t dnode_move_handle;
+       kstat_named_t dnode_move_rwlock;
+       kstat_named_t dnode_move_active;
+} dnode_stats_t;
+
+extern dnode_stats_t dnode_stats;
+
+#define        DNODE_STAT_INCR(stat, val) \
+    atomic_add_64(&dnode_stats.stat.value.ui64, (val));
+#define        DNODE_STAT_BUMP(stat) \
+    DNODE_STAT_INCR(stat, 1);
+
 #ifdef ZFS_DEBUG
 
 /*