aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/zap_micro.c
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2019-01-10 14:37:43 -0800
committerGitHub <[email protected]>2019-01-10 14:37:43 -0800
commit6955b40138b959af724a332df32ae64c872d876b (patch)
tree14a0e26473d758f2533e2a1c4c81f4ac9e167a86 /module/zfs/zap_micro.c
parent58769a4ebd462461131f19cccf25c3d19a4dbfb5 (diff)
Provide more flexible object allocation interface
Object allocation performance can be improved for complex operations by providing an interface which returns the newly allocated dnode. This allows the caller to immediately use the dnode without incurring the expense of looking up the dnode by object number. The functions dmu_object_alloc_hold(), zap_create_hold(), and dmu_bonus_hold_by_dnode() were added for this purpose. The zap_create_* functions have been updated to take advantage of this new functionality. The dmu_bonus_hold_impl() function should really have never been included in sys/dmu.h and was removed. It's sole caller was converted to use dmu_bonus_hold_by_dnode(). The new symbols have been exported for use by Lustre. Reviewed-by: Tony Hutter <[email protected]> Reviewed by: Matt Ahrens <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #8015
Diffstat (limited to 'module/zfs/zap_micro.c')
-rw-r--r--module/zfs/zap_micro.c94
1 files changed, 67 insertions, 27 deletions
diff --git a/module/zfs/zap_micro.c b/module/zfs/zap_micro.c
index 8b4fd0652..fa369f797 100644
--- a/module/zfs/zap_micro.c
+++ b/module/zfs/zap_micro.c
@@ -699,17 +699,17 @@ mzap_upgrade(zap_t **zapp, void *tag, dmu_tx_t *tx, zap_flags_t flags)
* of them may be supplied.
*/
void
-mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
- dmu_tx_t *tx)
+mzap_create_impl(dnode_t *dn, int normflags, zap_flags_t flags, dmu_tx_t *tx)
{
dmu_buf_t *db;
- VERIFY0(dmu_buf_hold(os, obj, 0, FTAG, &db, DMU_READ_NO_PREFETCH));
+ VERIFY0(dmu_buf_hold_by_dnode(dn, 0, FTAG, &db, DMU_READ_NO_PREFETCH));
dmu_buf_will_dirty(db, tx);
mzap_phys_t *zp = db->db_data;
zp->mz_block_type = ZBT_MICRO;
- zp->mz_salt = ((uintptr_t)db ^ (uintptr_t)tx ^ (obj << 1)) | 1ULL;
+ zp->mz_salt =
+ ((uintptr_t)db ^ (uintptr_t)tx ^ (dn->dn_object << 1)) | 1ULL;
zp->mz_normflags = normflags;
if (flags != 0) {
@@ -724,6 +724,33 @@ mzap_create_impl(objset_t *os, uint64_t obj, int normflags, zap_flags_t flags,
}
}
+static uint64_t
+zap_create_impl(objset_t *os, int normflags, zap_flags_t flags,
+ dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
+ dmu_object_type_t bonustype, int bonuslen, int dnodesize,
+ dnode_t **allocated_dnode, void *tag, dmu_tx_t *tx)
+{
+ uint64_t obj;
+
+ ASSERT3U(DMU_OT_BYTESWAP(ot), ==, DMU_BSWAP_ZAP);
+
+ if (allocated_dnode == NULL) {
+ dnode_t *dn;
+ obj = dmu_object_alloc_hold(os, ot, 1ULL << leaf_blockshift,
+ indirect_blockshift, bonustype, bonuslen, dnodesize,
+ &dn, FTAG, tx);
+ mzap_create_impl(dn, normflags, flags, tx);
+ dnode_rele(dn, FTAG);
+ } else {
+ obj = dmu_object_alloc_hold(os, ot, 1ULL << leaf_blockshift,
+ indirect_blockshift, bonustype, bonuslen, dnodesize,
+ allocated_dnode, tag, tx);
+ mzap_create_impl(*allocated_dnode, normflags, flags, tx);
+ }
+
+ return (obj);
+}
+
int
zap_create_claim(objset_t *os, uint64_t obj, dmu_object_type_t ot,
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
@@ -754,12 +781,23 @@ zap_create_claim_norm_dnsize(objset_t *os, uint64_t obj, int normflags,
dmu_object_type_t ot, dmu_object_type_t bonustype, int bonuslen,
int dnodesize, dmu_tx_t *tx)
{
+ dnode_t *dn;
+ int error;
+
ASSERT3U(DMU_OT_BYTESWAP(ot), ==, DMU_BSWAP_ZAP);
- int err = dmu_object_claim_dnsize(os, obj, ot, 0, bonustype, bonuslen,
+ error = dmu_object_claim_dnsize(os, obj, ot, 0, bonustype, bonuslen,
dnodesize, tx);
- if (err != 0)
- return (err);
- mzap_create_impl(os, obj, normflags, 0, tx);
+ if (error != 0)
+ return (error);
+
+ error = dnode_hold(os, obj, FTAG, &dn);
+ if (error != 0)
+ return (error);
+
+ mzap_create_impl(dn, normflags, 0, tx);
+
+ dnode_rele(dn, FTAG);
+
return (0);
}
@@ -790,12 +828,8 @@ uint64_t
zap_create_norm_dnsize(objset_t *os, int normflags, dmu_object_type_t ot,
dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx)
{
- ASSERT3U(DMU_OT_BYTESWAP(ot), ==, DMU_BSWAP_ZAP);
- uint64_t obj = dmu_object_alloc_dnsize(os, ot, 0, bonustype, bonuslen,
- dnodesize, tx);
-
- mzap_create_impl(os, obj, normflags, 0, tx);
- return (obj);
+ return (zap_create_impl(os, normflags, 0, ot, 0, 0,
+ bonustype, bonuslen, dnodesize, NULL, NULL, tx));
}
uint64_t
@@ -812,20 +846,25 @@ zap_create_flags_dnsize(objset_t *os, int normflags, zap_flags_t flags,
dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx)
{
- ASSERT3U(DMU_OT_BYTESWAP(ot), ==, DMU_BSWAP_ZAP);
- uint64_t obj = dmu_object_alloc_dnsize(os, ot, 0, bonustype, bonuslen,
- dnodesize, tx);
-
- ASSERT(leaf_blockshift >= SPA_MINBLOCKSHIFT &&
- leaf_blockshift <= SPA_OLD_MAXBLOCKSHIFT &&
- indirect_blockshift >= SPA_MINBLOCKSHIFT &&
- indirect_blockshift <= SPA_OLD_MAXBLOCKSHIFT);
-
- VERIFY(dmu_object_set_blocksize(os, obj,
- 1ULL << leaf_blockshift, indirect_blockshift, tx) == 0);
+ return (zap_create_impl(os, normflags, flags, ot, leaf_blockshift,
+ indirect_blockshift, bonustype, bonuslen, dnodesize, NULL, NULL,
+ tx));
+}
- mzap_create_impl(os, obj, normflags, flags, tx);
- return (obj);
+/*
+ * Create a zap object and return a pointer to the newly allocated dnode via
+ * the allocated_dnode argument. The returned dnode will be held and the
+ * caller is responsible for releasing the hold by calling dnode_rele().
+ */
+uint64_t
+zap_create_hold(objset_t *os, int normflags, zap_flags_t flags,
+ dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
+ dmu_object_type_t bonustype, int bonuslen, int dnodesize,
+ dnode_t **allocated_dnode, void *tag, dmu_tx_t *tx)
+{
+ return (zap_create_impl(os, normflags, flags, ot, leaf_blockshift,
+ indirect_blockshift, bonustype, bonuslen, dnodesize,
+ allocated_dnode, tag, tx));
}
int
@@ -1596,6 +1635,7 @@ EXPORT_SYMBOL(zap_create_flags_dnsize);
EXPORT_SYMBOL(zap_create_claim);
EXPORT_SYMBOL(zap_create_claim_norm);
EXPORT_SYMBOL(zap_create_claim_norm_dnsize);
+EXPORT_SYMBOL(zap_create_hold);
EXPORT_SYMBOL(zap_destroy);
EXPORT_SYMBOL(zap_lookup);
EXPORT_SYMBOL(zap_lookup_by_dnode);