spa_sync() spends 5-10% of its time in metaslab_sync() (when not condensing)
zfs - Zettabyte File System
From Matt Ahrens's original bug report at Delphix:
Typically, metaslab_sync() accounts for about 5-10% of the total spa_sync(). This is when we are not condensing a metaslab (when that happens, metaslab_sync() is >50% of spa_sync()). Most of this time is due to the first call to space_map_walk(), where we move the freemap to the freed_map. When this happens, the freed_map is initially empty, and after doing this we will remove all entries from the freemap. So rather than transferring each entry, we can simply change the pointer to the avl trees so that the freed_map points to what was the freemap. This will require some changes to space_map_sync(), to make it not remove the entires from the provided spacemap.