mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 19:28:53 +03:00
Optimize allocation throttling
Remove mc_lock use from metaslab_class_throttle_*(). The math there is based on refcounts and so atomic, so the only race possible there is between zfs_refcount_count() and zfs_refcount_add(). But in most cases metaslab_class_throttle_reserve() is called with the allocator lock held, which covers the race. In cases where the lock is not held, GANG_ALLOCATION() or METASLAB_MUST_RESERVE are set, and so we do not use zfs_refcount_count(). And even if we assume some other non-existing scenario, the worst that may happen from this race is few more I/Os get to allocation earlier, that is not a problem. Move locks and data of different allocators into different cache lines to avoid false sharing. Group spa_alloc_* arrays together into single array of aligned struct spa_alloc spa_allocs. Align struct metaslab_class_allocator. Reviewed-by: Paul Dagnelie <pcd@delphix.com> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Reviewed-by: Don Brady <don.brady@delphix.com> Signed-off-by: Alexander Motin <mav@FreeBSD.org> Sponsored-By: iXsystems, Inc. Closes #12314
This commit is contained in:
+9
-12
@@ -700,13 +700,12 @@ spa_add(const char *name, nvlist_t *config, const char *altroot)
|
||||
spa->spa_root = spa_strdup(altroot);
|
||||
|
||||
spa->spa_alloc_count = spa_allocators;
|
||||
spa->spa_alloc_locks = kmem_zalloc(spa->spa_alloc_count *
|
||||
sizeof (kmutex_t), KM_SLEEP);
|
||||
spa->spa_alloc_trees = kmem_zalloc(spa->spa_alloc_count *
|
||||
sizeof (avl_tree_t), KM_SLEEP);
|
||||
spa->spa_allocs = kmem_zalloc(spa->spa_alloc_count *
|
||||
sizeof (spa_alloc_t), KM_SLEEP);
|
||||
for (int i = 0; i < spa->spa_alloc_count; i++) {
|
||||
mutex_init(&spa->spa_alloc_locks[i], NULL, MUTEX_DEFAULT, NULL);
|
||||
avl_create(&spa->spa_alloc_trees[i], zio_bookmark_compare,
|
||||
mutex_init(&spa->spa_allocs[i].spaa_lock, NULL, MUTEX_DEFAULT,
|
||||
NULL);
|
||||
avl_create(&spa->spa_allocs[i].spaa_tree, zio_bookmark_compare,
|
||||
sizeof (zio_t), offsetof(zio_t, io_alloc_node));
|
||||
}
|
||||
avl_create(&spa->spa_metaslabs_by_flushed, metaslab_sort_by_flushed,
|
||||
@@ -799,13 +798,11 @@ spa_remove(spa_t *spa)
|
||||
}
|
||||
|
||||
for (int i = 0; i < spa->spa_alloc_count; i++) {
|
||||
avl_destroy(&spa->spa_alloc_trees[i]);
|
||||
mutex_destroy(&spa->spa_alloc_locks[i]);
|
||||
avl_destroy(&spa->spa_allocs[i].spaa_tree);
|
||||
mutex_destroy(&spa->spa_allocs[i].spaa_lock);
|
||||
}
|
||||
kmem_free(spa->spa_alloc_locks, spa->spa_alloc_count *
|
||||
sizeof (kmutex_t));
|
||||
kmem_free(spa->spa_alloc_trees, spa->spa_alloc_count *
|
||||
sizeof (avl_tree_t));
|
||||
kmem_free(spa->spa_allocs, spa->spa_alloc_count *
|
||||
sizeof (spa_alloc_t));
|
||||
|
||||
avl_destroy(&spa->spa_metaslabs_by_flushed);
|
||||
avl_destroy(&spa->spa_sm_logs_by_txg);
|
||||
|
||||
Reference in New Issue
Block a user