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

Avoid extra memory copies during mirror scrub. #13593

Closed
wants to merge 1 commit into from

Conversation

amotin
Copy link
Member

@amotin amotin commented Jun 25, 2022

When several mirror scrub reads complete successfully, we do not need
to copy data from each of them into the parent ZIO buffer, the first
one is enough. This also moves the memory copy out of the ZIO locks,
that I expected to cause contention, though on my system they almost
didn't, had incorrect lock order and was partially not needed.

When scrubbing 4-way mirror with 1.5TB of 128KB ZVOL blocks, this
reduces CPU time spent in memcpy() by 75% and total CPU time by 31%.

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)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

When several mirror scrub reads complete successfully, we do not need
to copy data from each of them into the parent ZIO buffer, the first
one is enough.  This also moves the memory copy out of the ZIO locks,
that I expected to cause contention, though on my system they almost
didn't, had incorrect lock order and was partially not needed.

When scrubbing 4-way mirror with 1.5TB of 128KB ZVOL blocks, this
reduces CPU time spent in memcpy() by 75% and total CPU time by 31%.

Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored-By: iXsystems, Inc.
@amotin amotin added Type: Performance Performance improvement or performance problem Status: Code Review Needed Ready for review and testing labels Jun 25, 2022
Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

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

Looks good.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jun 27, 2022
while ((pio = zio_walk_parents(zio, &zl)) != NULL) {
mutex_enter(&pio->io_lock);
ASSERT3U(zio->io_size, >=, pio->io_size);
zio_t *pio = zio_unique_parent(zio);
Copy link
Contributor

Choose a reason for hiding this comment

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

The original algorithm walked all parents to do the copy... while it seems reasonable that there should generally be only a single parent here, do you have a reason to believe that is an invariant? Why did the original algorithm assume the possibility of multiple parents?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea what the original author was thinking about. zio_unique_parent() actually verifies there are not other parents, and the assertion didn't fire on my tests. My best guess is that it was some paranoia, same as unneeded locking.

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.

3 participants