Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve zfs destroy performance with zio_t-free zio_free() #10034

Merged
merged 2 commits into from Feb 28, 2020

Conversation

ahrens
Copy link
Member

@ahrens ahrens commented Feb 20, 2020

Motivation and Context

When "zfs destroy" is run, it completes quickly, and in the background
we locate the blocks to free and free them. This background activity
can be observed with zpool get freeing and zpool wait -t free ....

This background activity is processed by a single thread (the spa_sync
thread) which calls zio_free() on each of the blocks to free. With even
modest storage performance, the CPU consumption of zio_free() can be the
performance bottleneck.

Description

Performance of zio_free() can be improved by not actually creating a
zio_t in the common case (non-dedup, non-gang), instead calling
metaslab_free() directly. This avoids the CPU cost of allocating the
zio_t, and more importantly the cost of adding and later removing this
zio_t from the parent zio's child list.

The result is that performance of background freeing more than doubles,
from 0.6 million blocks per second to 1.3 million blocks per second.

How Has This Been Tested?

sudo zfs destroy -r domain0/recvd; time zpool wait domain0 1

The filesystem is 1.14TiB, containing 536,823,751 blocks.

Baseline: 15m10s elapsed (1310MB/s, 589,000 blocks/sec)

image

With Changes: 6m45s elapsed (2951MB/s, 1,325,000 blocks/sec) (2.25x)

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

@ahrens ahrens added Status: Code Review Needed Ready for review and testing Type: Performance Performance improvement or performance problem labels Feb 20, 2020
Copy link
Contributor

@pcd1193182 pcd1193182 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a clear win, though the title of the PR is definitely confusing until you've read the description 😛

@ahrens
Copy link
Member Author

ahrens commented Feb 20, 2020

@pcd1193182 My first draft was simply zio-free zio_free. Hopefully I settled on a title that preserves some of the cuteness while adding at least a little context :-)

@codecov
Copy link

codecov bot commented Feb 21, 2020

Codecov Report

Merging #10034 into master will increase coverage by 0.16%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10034      +/-   ##
==========================================
+ Coverage   79.19%   79.36%   +0.16%     
==========================================
  Files         386      386              
  Lines      122448   122458      +10     
==========================================
+ Hits        96977    97186     +209     
+ Misses      25471    25272     -199     
Flag Coverage Δ
#kernel 79.45% <95.23%> (+0.03%) ⬆️
#user 66.85% <86.95%> (+0.35%) ⬆️
Impacted Files Coverage Δ
include/os/linux/zfs/sys/trace_zio.h 66.66% <0.00%> (-33.34%) ⬇️
module/os/linux/zfs/vdev_file.c 80.37% <0.00%> (-1.87%) ⬇️
module/zcommon/zfs_uio.c 90.52% <0.00%> (-1.06%) ⬇️
module/icp/api/kcf_cipher.c 16.18% <0.00%> (-0.42%) ⬇️
module/os/linux/zfs/vdev_disk.c 83.63% <0.00%> (-0.37%) ⬇️
module/zfs/vdev_removal.c 97.23% <0.00%> (-0.35%) ⬇️
module/zfs/zvol.c 84.06% <0.00%> (-0.34%) ⬇️
module/lua/lauxlib.c 59.69% <0.00%> (-0.31%) ⬇️
module/zfs/zio.c 89.91% <0.00%> (-0.29%) ⬇️
module/zfs/arc.c 84.45% <0.00%> (-0.26%) ⬇️
... and 49 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 873cd18...34f07d6. Read the comment docs.

module/zfs/dsl_scan.c Outdated Show resolved Hide resolved
When "zfs destroy" is run, it completes quickly, and in the background
we locate the blocks to free and free them.  This background activity
can be observed with `zpool get freeing` and `zpool wait -t free ...`.

This background activity is processed by a single thread (the spa_sync
thread) which calls zio_free() on each of the blocks to free.  With even
modest storage performance, the CPU consumption of zio_free() can be the
performance bottleneck.

Performance of zio_free() can be improved by not actually creating a
zio_t in the common case (non-dedup, non-gang), instead calling
metaslab_free() directly.  This avoids the CPU cost of allocating the
zio_t, and more importantly the cost of adding and later removing this
zio_t from the parent zio's child list.

The result is that performance of background freeing more than doubles,
from 0.6 million blocks per second to 1.3 million blocks per second.

Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Feb 26, 2020
@behlendorf behlendorf merged commit 9cdf7b1 into openzfs:master Feb 28, 2020
ahrens added a commit to ahrens/zfs that referenced this pull request Apr 29, 2020
…rformance with zio_t-free zio_free()

When "zfs destroy" is run, it completes quickly, and in the background
we locate the blocks to free and free them.  This background activity
can be observed with `zpool get freeing` and `zpool wait -t free ...`.

This background activity is processed by a single thread (the spa_sync
thread) which calls zio_free() on each of the blocks to free.  With even
modest storage performance, the CPU consumption of zio_free() can be the
performance bottleneck.

Performance of zio_free() can be improved by not actually creating a
zio_t in the common case (non-dedup, non-gang), instead calling
metaslab_free() directly.  This avoids the CPU cost of allocating the
zio_t, and more importantly the cost of adding and later removing this
zio_t from the parent zio's child list.

The result is that performance of background freeing more than doubles,
from 0.6 million blocks per second to 1.3 million blocks per second.

Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Wilson <gwilson@delphix.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes openzfs#10034
@adamdmoss
Copy link
Contributor

Perhaps an overly optimistic question, but is a similar optimization applicable to file deletion? That has an option to be applied lazily but can take quite a while. Perhaps not CPU-bound though, so not similar.

@ahrens
Copy link
Member Author

ahrens commented Aug 28, 2020

@adamdmoss Yeah performance depends on a lot of things. As mentioned in the PR, the baseline (before this change) was 0.6 million blocks per second. So if you're getting much less than that, the bottleneck is likely elsewhere.

jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
When "zfs destroy" is run, it completes quickly, and in the background
we locate the blocks to free and free them.  This background activity
can be observed with `zpool get freeing` and `zpool wait -t free ...`.

This background activity is processed by a single thread (the spa_sync
thread) which calls zio_free() on each of the blocks to free.  With even
modest storage performance, the CPU consumption of zio_free() can be the
performance bottleneck.

Performance of zio_free() can be improved by not actually creating a
zio_t in the common case (non-dedup, non-gang), instead calling
metaslab_free() directly.  This avoids the CPU cost of allocating the
zio_t, and more importantly the cost of adding and later removing this
zio_t from the parent zio's child list.

The result is that performance of background freeing more than doubles,
from 0.6 million blocks per second to 1.3 million blocks per second.

Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Wilson <gwilson@delphix.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes openzfs#10034
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested) Type: Performance Performance improvement or performance problem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants