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

Linux: Cleanup taskq threads spawn/exit #15873

Merged
merged 1 commit into from
Feb 13, 2024
Merged

Conversation

amotin
Copy link
Member

@amotin amotin commented Feb 9, 2024

This changes taskq_thread_should_stop() to limit maximum exit rate for idle threads to one per 5 seconds. I believe the previous one was broken, not allowing any thread exits for tasks arriving more than one at a time and so completing while others are running.

Also while there:

  • Remove taskq_thread_spawn() calls on task allocation errors.
  • Remove extra taskq_thread_should_stop() call.
  • Remove wake_up_all(&tq->tq_wait_waitq) on thread exit.

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:

This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
@rincebrain
Copy link
Contributor

I'm curious if this was causing a specific bottleneck that you saw, or is just you reviewing things for cleanup?

Was the 5s time picked based on some data about it changing the outcome? At least when I originally added it, the threshold was just picked based on experimental data of what number produced very little churn on my system, since I originally looked at this after noticing what fraction of my system's idle time was spent just creating and destroying threads transiently.

@amotin
Copy link
Member Author

amotin commented Feb 12, 2024

@rincebrain We are now trying to understand 10-20% performance degradation of ZFS 2.2 vs 2.1 we see in certain heavy Samba to RAIDZ write workloads. Unfortunately profiling does not show anything meaningful, only that CPU time is distributed slightly differently between code parts, that makes me wonder if it can be caused by some changes in scheduling on top of SMT or cache topology. Looking through the large list of changed I spotted your commit, that made me to look deeper. On FreeBSD some time ago I patched kernel taskq implementation to not implement fair round-robin among all the taskq threads, using only minimally required count (LIFO vs FIFO), since in general case all taskq threads should be identical, so extra threads do not affect scheduling. Unfortunately I haven't found an easy way to do it on Linux, so I was looking on reducing the number of threads. Unfortunately I don't have a performance numbers yet to prove or otherwise my guess, our perf team is busy. So I am just going from my understanding that the current logic after your 35a6247 commit may not shrink taskqs on certain workloads, that may complicate scheduler job.

5s change from 10s is more of a feeling. Since we may have dozens if not hundreds of threads, one thread exit per 10s with the logic I propose may take a long time to shrink. Same time values below 5s may fluctuate too much within one TXG commit interval.

@amotin amotin added the Status: Code Review Needed Ready for review and testing label Feb 12, 2024
@rincebrain
Copy link
Contributor

rincebrain commented Feb 12, 2024

We could also try adding more tracking of how many times we pass through this code and do/don't turnover per taskq to understand how much we're churning in different thread types, and go from there. (Not saying this should or shouldn't be done based on that, just speculating aloud how I'd try to isolate if that happening in some or all threads was related, for future more fine-grained options...)

Does turning off this change affect the workloads observed? Because a value to the tunable of "0" should make my change moot, for testing purposes, I believe...

@amotin
Copy link
Member Author

amotin commented Feb 12, 2024

Does turning off this change affect the workloads observed? Because a value to the tunable of "0" should make my change moot, for testing purposes, I believe...

Yes, that is exactly what I have asked our perf team. Was promised some results this week. But even if that is not the case of the slowdown we see, I still think your patch may not work as expected and propose to discuss mine.

@rincebrain
Copy link
Contributor

rincebrain commented Feb 12, 2024

Sure, I don't think anything about this is unreasonable, and I'll mark it as reviewed, I just wanted to understand whether you had tried turning off that change.

I don't particularly think the old patch should be able to cause many problems with teardown, since it should just come around and try again.

My only question is, have you tested this on FBSD 13, since the buildbot seems to be broken on FBSD atm? (I realize this change shouldn't affect anything on FBSD, I swear, I just am really cautious about not assuming FBSD isn't broken given previous "oops we broke it" experiences.)

@amotin
Copy link
Member Author

amotin commented Feb 12, 2024

I don't particularly think the old patch should be able to cause many problems with teardown, since it should just come around and try again.

As I have told, I believe that if you enqueue two or more tasks each time it will on each first completion reset tq->lastshouldstop = 0 and never allow other threads to exit after that.

My only question is, have you tested this on FBSD 13, since the buildbot seems to be broken on FBSD atm? (I realize this change shouldn't affect anything on FBSD, I swear, I just am really cautious about not assuming FBSD isn't broken given previous "oops we broke it" experiences.)

I can not imagine how it may affect FreeBSD. That code is not shared.

@rincebrain
Copy link
Contributor

Ah, I misunderstood your description, I didn't understand from previous exchanges that you meant it triggered the =0 reset always happening. Thank you for clarifying.

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.

This looks good

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Feb 13, 2024
@behlendorf behlendorf merged commit e0bd811 into openzfs:master Feb 13, 2024
25 of 26 checks passed
@amotin amotin deleted the linux_taskq branch February 13, 2024 19:15
@mmatuska
Copy link
Contributor

@amotin is this relevant for 2.2?

@behlendorf
Copy link
Contributor

It's applicable, but given it's not critical and how fresh it is I'd like to let it soak for a bit before backporting.

@amotin
Copy link
Member Author

amotin commented Feb 23, 2024

Does turning off this change affect the workloads observed? Because a value to the tunable of "0" should make my change moot, for testing purposes, I believe...

@rincebrain I've just got confirmation from our performance team that spl_taskq_thread_timeout_ms=0 fixes the performance issue. Now they should try this patch instead.

@rincebrain
Copy link
Contributor

Well, that's a useful data point. So if people think this is causing them problems, in some case, they can use that, at least, to restore status quo ante until this or some other patch rolls out with better behaviors.

ixhamza pushed a commit to truenas/zfs that referenced this pull request Feb 23, 2024
This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
Closes openzfs#15873
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Mar 13, 2024
This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
Closes openzfs#15873
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Mar 13, 2024
This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
Closes openzfs#15873
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Mar 13, 2024
This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
Closes openzfs#15873
amotin added a commit to amotin/zfs that referenced this pull request Apr 17, 2024
This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
Closes openzfs#15873
behlendorf pushed a commit that referenced this pull request Apr 19, 2024
This changes taskq_thread_should_stop() to limit maximum exit rate
for idle threads to one per 5 seconds.  I believe the previous one
was broken, not allowing any thread exits for tasks arriving more
than one at a time and so completing while others are running.

Also while there:
 - Remove taskq_thread_spawn() calls on task allocation errors.
 - Remove extra taskq_thread_should_stop() call.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Rich Ercolani <[email protected]>
Signed-off-by:	Alexander Motin <[email protected]>
Sponsored by:	iXsystems, Inc.
Closes #15873
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants