Skip to content

zio_add_child: collapse into a single function #17382

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robn
Copy link
Member

@robn robn commented May 27, 2025

Motivation and Context

In my work I'm often hooking up different things to zios, and changing in both places is easy to miss. The only difference is the locking, and that's easy enough to handle with a boolean.

Description

Make zio_add_child_impl(), with a boolean_t first arg, and make the existing functions wrap it.

This inverts the lock order just to make the code more readable: the "lock/unlock unless first" conditional becomes a simple two-liner wrapping the guts.

How Has This Been Tested?

Very lightly sanity checked.

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)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • 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:

Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

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

The unification is fine. I was just thinking whether it could make sent to mark zio_add_child_impl() with inline. But I am not so sure you can change lock order that easily. It might need a deeper look to avoid LORs.

The child locking difference is simple enough to handle with a boolean.
The actual work is more involved, and it's easy to forget to change
things in both places when experimenting. Just collapse them.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <[email protected]>
@robn robn force-pushed the zio-add-child-dry branch from da68d80 to c496f6f Compare May 28, 2025 00:13
@robn
Copy link
Member Author

robn commented May 28, 2025

Yeah, I was thinking about the locks a bit more this morning, and everywhere else takes parent first, so there does seem like a chance.

I did it that way to try and keep the parent lock scoped as narrowly as possible, since I guessed you did it for a reason. If not, then it's less of an issue I think. Last push is the "easy" version, lmk.

Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

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

In zio_remove_child() we take parent lock first too. So if invert, then both. Even if they likely never conflict in practice, different order made me nervous. But I worry whether we may somewhere recurse with lock held or doing something else like it. I'd be happy to reduce the scope, since those function quite actively appear in profiles for some reason, but it just needs some care and possibly taking some risk.

@amotin amotin added the Status: Code Review Needed Ready for review and testing label May 28, 2025
@robn
Copy link
Member Author

robn commented May 28, 2025

@amotin I agree, makes me nervous too, and I hadn't thought very hard (just a little). I would prefer not change function in what's supposed to be a readability patch. So I'm happy to drop it if you think it will slow us down, or revisit it if it comes up again in profiling. A BIG REMINDER COMMENT to update both places might be good enough.

@behlendorf behlendorf self-requested a review May 29, 2025 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants