summaryrefslogtreecommitdiffstats
path: root/module/zfs/space_map.c
diff options
context:
space:
mode:
authorGeorge Wilson <[email protected]>2013-05-06 10:14:52 -0700
committerBrian Behlendorf <[email protected]>2013-05-06 12:39:34 -0700
commit55d85d5a8c45c4559a4a0e675c37b0c3afb19c2f (patch)
treede4e1e0564aa00bb1dcb8b91c15e9655f7f36248 /module/zfs/space_map.c
parent5853fe790d1df58c5dd85ea52c5e165b6d43013c (diff)
Illumos #3329, #3330, #3331, #3335
3329 spa_sync() spends 10-20% of its time in spa_free_sync_cb() 3330 space_seg_t should have its own kmem_cache 3331 deferred frees should happen after sync_pass 1 3335 make SYNC_PASS_* constants tunable Reviewed by: Adam Leventhal <[email protected]> Reviewed by: Matt Ahrens <[email protected]> Reviewed by: Christopher Siden <[email protected]> Reviewed by: Eric Schrock <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Dan McDonald <[email protected]> Approved by: Eric Schrock <[email protected]> References: illumos/illumos-gate@01f55e48fb4d524eaf70687728aa51b7762e2e97 https://www.illumos.org/issues/3329 https://www.illumos.org/issues/3330 https://www.illumos.org/issues/3331 https://www.illumos.org/issues/3335 Ported-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'module/zfs/space_map.c')
-rw-r--r--module/zfs/space_map.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/module/zfs/space_map.c b/module/zfs/space_map.c
index 9c0cdb6be..d99c7c0b3 100644
--- a/module/zfs/space_map.c
+++ b/module/zfs/space_map.c
@@ -29,6 +29,23 @@
#include <sys/zio.h>
#include <sys/space_map.h>
+static kmem_cache_t *space_seg_cache;
+
+void
+space_map_init(void)
+{
+ ASSERT(space_seg_cache == NULL);
+ space_seg_cache = kmem_cache_create("space_seg_cache",
+ sizeof (space_seg_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
+}
+
+void
+space_map_fini(void)
+{
+ kmem_cache_destroy(space_seg_cache);
+ space_seg_cache = NULL;
+}
+
/*
* Space map routines.
* NOTE: caller is responsible for all locking.
@@ -121,7 +138,7 @@ space_map_add(space_map_t *sm, uint64_t start, uint64_t size)
avl_remove(sm->sm_pp_root, ss_after);
}
ss_after->ss_start = ss_before->ss_start;
- kmem_free(ss_before, sizeof (*ss_before));
+ kmem_cache_free(space_seg_cache, ss_before);
ss = ss_after;
} else if (merge_before) {
ss_before->ss_end = end;
@@ -134,7 +151,7 @@ space_map_add(space_map_t *sm, uint64_t start, uint64_t size)
avl_remove(sm->sm_pp_root, ss_after);
ss = ss_after;
} else {
- ss = kmem_alloc(sizeof (*ss), KM_PUSHPAGE);
+ ss = kmem_cache_alloc(space_seg_cache, KM_PUSHPAGE);
ss->ss_start = start;
ss->ss_end = end;
avl_insert(&sm->sm_root, ss, where);
@@ -181,7 +198,7 @@ space_map_remove(space_map_t *sm, uint64_t start, uint64_t size)
avl_remove(sm->sm_pp_root, ss);
if (left_over && right_over) {
- newseg = kmem_alloc(sizeof (*newseg), KM_PUSHPAGE);
+ newseg = kmem_cache_alloc(space_seg_cache, KM_PUSHPAGE);
newseg->ss_start = end;
newseg->ss_end = ss->ss_end;
ss->ss_end = start;
@@ -194,7 +211,7 @@ space_map_remove(space_map_t *sm, uint64_t start, uint64_t size)
ss->ss_start = end;
} else {
avl_remove(&sm->sm_root, ss);
- kmem_free(ss, sizeof (*ss));
+ kmem_cache_free(space_seg_cache, ss);
ss = NULL;
}
@@ -234,7 +251,7 @@ space_map_vacate(space_map_t *sm, space_map_func_t *func, space_map_t *mdest)
while ((ss = avl_destroy_nodes(&sm->sm_root, &cookie)) != NULL) {
if (func != NULL)
func(mdest, ss->ss_start, ss->ss_end - ss->ss_start);
- kmem_free(ss, sizeof (*ss));
+ kmem_cache_free(space_seg_cache, ss);
}
sm->sm_space = 0;
}
@@ -406,7 +423,7 @@ space_map_sync(space_map_t *sm, uint8_t maptype,
spa_t *spa = dmu_objset_spa(os);
void *cookie = NULL;
space_seg_t *ss;
- uint64_t bufsize, start, size, run_len;
+ uint64_t bufsize, start, size, run_len, delta, sm_space;
uint64_t *entry, *entry_map, *entry_map_end;
ASSERT(MUTEX_HELD(sm->sm_lock));
@@ -435,11 +452,13 @@ space_map_sync(space_map_t *sm, uint8_t maptype,
SM_DEBUG_SYNCPASS_ENCODE(spa_sync_pass(spa)) |
SM_DEBUG_TXG_ENCODE(dmu_tx_get_txg(tx));
+ delta = 0;
+ sm_space = sm->sm_space;
while ((ss = avl_destroy_nodes(&sm->sm_root, &cookie)) != NULL) {
size = ss->ss_end - ss->ss_start;
start = (ss->ss_start - sm->sm_start) >> sm->sm_shift;
- sm->sm_space -= size;
+ delta += size;
size >>= sm->sm_shift;
while (size) {
@@ -461,7 +480,7 @@ space_map_sync(space_map_t *sm, uint8_t maptype,
start += run_len;
size -= run_len;
}
- kmem_free(ss, sizeof (*ss));
+ kmem_cache_free(space_seg_cache, ss);
}
if (entry != entry_map) {
@@ -473,8 +492,15 @@ space_map_sync(space_map_t *sm, uint8_t maptype,
smo->smo_objsize += size;
}
+ /*
+ * Ensure that the space_map's accounting wasn't changed
+ * while we were in the middle of writing it out.
+ */
+ VERIFY3U(sm->sm_space, ==, sm_space);
+
zio_buf_free(entry_map, bufsize);
+ sm->sm_space -= delta;
VERIFY3U(sm->sm_space, ==, 0);
}