summaryrefslogtreecommitdiffstats
path: root/module/zfs/bpobj.c
diff options
context:
space:
mode:
authorMatthew Ahrens <[email protected]>2012-12-23 15:57:14 -0800
committerBrian Behlendorf <[email protected]>2013-01-08 10:35:43 -0800
commit753c38392ddff9d3cf140bb4d28f3bfba52c92d2 (patch)
tree628c9789ff88963dfdab65f37522640d13051dc8 /module/zfs/bpobj.c
parent91579709fccd3e55a21970742b66c388fb1403db (diff)
Illumos #3104: eliminate empty bpobjs
3104 eliminate empty bpobjs Reviewed by: George Wilson <[email protected]> Reviewed by: Adam Leventhal <[email protected]> Reviewed by: Christopher Siden <[email protected]> Reviewed by: Garrett D'Amore <[email protected]> Approved by: Eric Schrock <[email protected]> References: illumos/illumos-gate@f17457368189aa911f774c38c1f21875a568bdca illumos changeset: 13782:8f78aae28a63 https://www.illumos.org/issues/3104 Ported-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'module/zfs/bpobj.c')
-rw-r--r--module/zfs/bpobj.c58
1 files changed, 57 insertions, 1 deletions
diff --git a/module/zfs/bpobj.c b/module/zfs/bpobj.c
index 022921c66..d5f8d4072 100644
--- a/module/zfs/bpobj.c
+++ b/module/zfs/bpobj.c
@@ -20,13 +20,61 @@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2011 by Delphix. All rights reserved.
+ * Copyright (c) 2012 by Delphix. All rights reserved.
*/
#include <sys/bpobj.h>
#include <sys/zfs_context.h>
#include <sys/refcount.h>
#include <sys/dsl_pool.h>
+#include <sys/zfeature.h>
+#include <sys/zap.h>
+
+/*
+ * Return an empty bpobj, preferably the empty dummy one (dp_empty_bpobj).
+ */
+uint64_t
+bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx)
+{
+ zfeature_info_t *empty_bpobj_feat =
+ &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ];
+ spa_t *spa = dmu_objset_spa(os);
+ dsl_pool_t *dp = dmu_objset_pool(os);
+
+ if (spa_feature_is_enabled(spa, empty_bpobj_feat)) {
+ if (!spa_feature_is_active(spa, empty_bpobj_feat)) {
+ ASSERT3U(dp->dp_empty_bpobj, ==, 0);
+ dp->dp_empty_bpobj =
+ bpobj_alloc(os, SPA_MAXBLOCKSIZE, tx);
+ VERIFY(zap_add(os,
+ DMU_POOL_DIRECTORY_OBJECT,
+ DMU_POOL_EMPTY_BPOBJ, sizeof (uint64_t), 1,
+ &dp->dp_empty_bpobj, tx) == 0);
+ }
+ spa_feature_incr(spa, empty_bpobj_feat, tx);
+ ASSERT(dp->dp_empty_bpobj != 0);
+ return (dp->dp_empty_bpobj);
+ } else {
+ return (bpobj_alloc(os, blocksize, tx));
+ }
+}
+
+void
+bpobj_decr_empty(objset_t *os, dmu_tx_t *tx)
+{
+ zfeature_info_t *empty_bpobj_feat =
+ &spa_feature_table[SPA_FEATURE_EMPTY_BPOBJ];
+ dsl_pool_t *dp = dmu_objset_pool(os);
+
+ spa_feature_decr(dmu_objset_spa(os), empty_bpobj_feat, tx);
+ if (!spa_feature_is_active(dmu_objset_spa(os), empty_bpobj_feat)) {
+ VERIFY3U(0, ==, zap_remove(dp->dp_meta_objset,
+ DMU_POOL_DIRECTORY_OBJECT,
+ DMU_POOL_EMPTY_BPOBJ, tx));
+ VERIFY3U(0, ==, dmu_object_free(os, dp->dp_empty_bpobj, tx));
+ dp->dp_empty_bpobj = 0;
+ }
+}
uint64_t
bpobj_alloc(objset_t *os, int blocksize, dmu_tx_t *tx)
@@ -53,6 +101,7 @@ bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
int epb;
dmu_buf_t *dbuf = NULL;
+ ASSERT(obj != dmu_objset_pool(os)->dp_empty_bpobj);
VERIFY3U(0, ==, bpobj_open(&bpo, os, obj));
mutex_enter(&bpo.bpo_lock);
@@ -320,6 +369,12 @@ bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx)
ASSERT(bpo->bpo_havesubobj);
ASSERT(bpo->bpo_havecomp);
+ ASSERT(bpo->bpo_object != dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj);
+
+ if (subobj == dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj) {
+ bpobj_decr_empty(bpo->bpo_os, tx);
+ return;
+ }
VERIFY3U(0, ==, bpobj_open(&subbpo, bpo->bpo_os, subobj));
VERIFY3U(0, ==, bpobj_space(&subbpo, &used, &comp, &uncomp));
@@ -388,6 +443,7 @@ bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx)
blkptr_t *bparray;
ASSERT(!BP_IS_HOLE(bp));
+ ASSERT(bpo->bpo_object != dmu_objset_pool(bpo->bpo_os)->dp_empty_bpobj);
/* We never need the fill count. */
stored_bp.blk_fill = 0;