Page MenuHomeFreeBSD

fix callout lock contention during thread creation/destruction
AbandonedPublic

Authored by mjg on Aug 25 2022, 10:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 13, 6:17 PM
Unknown Object (File)
Jan 26 2024, 9:13 PM
Unknown Object (File)
Dec 29 2023, 9:30 PM
Unknown Object (File)
Aug 21 2023, 11:09 PM
Unknown Object (File)
May 8 2023, 4:38 AM
Unknown Object (File)
Mar 22 2023, 6:38 PM
Unknown Object (File)
Mar 5 2023, 5:56 PM
Subscribers
None

Details

Reviewers
markj
Summary

The lock is top of the profile when applied to kernel with other patches (will post later):

294846572 (spin mutex:callout)   
1832520 (sleep mutex:TID lock)

disappears with the patch. bumps thread creation/destruction rate 2 -> 3 mln ops/s with 104 workers doing it.

commit 885ad80eaa83261a32815a4f5ec094d35cd5b620
Author: Mateusz Guzik <mjg@FreeBSD.org>
Date:   Thu Aug 25 22:42:42 2022 +0000

    thread: use callout_init_cpu(..., curcpu)
    
    Sorts out callout lock contention during heavy thread
    creation/destruction test.
    
    Reviewed by:
    Differential Revision:

commit fdd578e33ad1be7410ad5384b0e22ab351fb0803
Author: Mateusz Guzik <mjg@FreeBSD.org>
Date:   Thu Aug 25 22:42:08 2022 +0000

    callout: add callout_init_cpu
    
    Reviewed by:
    Differential Revision:

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

mjg requested review of this revision.Aug 25 2022, 10:58 PM
mjg created this revision.
mjg edited the summary of this revision. (Show Details)

Why are we reinitializing td_slpcallout each time a thread struct is reused? The callout is drained before the thread structure is reused. Can't the callout be initialized just once in thread_init()?

Why are we reinitializing td_slpcallout each time a thread struct is reused? The callout is drained before the thread structure is reused. Can't the callout be initialized just once in thread_init()?

I guess that wouldn't fix the actual problem, since in your microbenchmark the callout is never getting scheduled?

right. threads just show up and die.

Missing a man page update, and other callout init functions (callout_init_mtx() etc.) still don't have this variant. I'd expect it to be useful for p_limco as well?

IMO the following approach is more general and future-friendly:

  • add callout_init_flags() instead of callout_init_cpu()
  • add a new callout flag which means "bind it to the current CPU instead of the default CPU"
  • then there's no need for callout_init_mtx_cpu() etc., and callout_init_flags() can be further extended in the future without needing yet another function