Page MenuHomeFreeBSD

Ensure 'struct thread' is aligned to a cache line
ClosedPublic

Authored by olce on Oct 17 2023, 3:04 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jun 9, 3:11 AM
Unknown Object (File)
May 14 2024, 3:16 PM
Unknown Object (File)
Apr 30 2024, 5:37 AM
Unknown Object (File)
Apr 30 2024, 5:10 AM
Unknown Object (File)
Apr 30 2024, 5:06 AM
Unknown Object (File)
Apr 29 2024, 10:08 PM
Unknown Object (File)
Jan 27 2024, 7:11 AM
Unknown Object (File)
Dec 31 2023, 11:04 AM
Subscribers

Details

Summary

Using the new UMA_ALIGN_CACHE_AND_MASK() facility, which allows to
simultaneously guarantee a minimum of 32 bytes of alignment (the 5 lower
bits are always 0).

For the record, to this day, here's a (possibly non-exhaustive) list of
synchronization primitives using lower bits to store flags in pointers
to thread structures:

  • lockmgr, rwlock and sx all use the 5 bits directly.
  • rmlock indirectly relies on sx, so can use the 5 bits.
  • mtx (non-spin) relies on the 3 lower bits.

MFC after: 2 week
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

olce requested review of this revision.Oct 17 2023, 3:04 PM

This is preliminary work for struct thread fields re-ordering (standalone, this commit doesn't have that much value; but older commit messages mention the intention to do it).

markj added inline comments.
sys/kern/kern_thread.c
579

This would be a good time to add a comment explaining why we require some minimum alignment (synchronization primitives expect to be able to use low bits of a thread address).

This revision is now accepted and ready to land.Oct 17 2023, 3:46 PM
olce marked an inline comment as done.
olce edited the summary of this revision. (Show Details)

Add a comment explaining the reason for the minimal alignment constraint.

This revision now requires review to proceed.Oct 19 2023, 8:19 AM
sys/kern/kern_thread.c
573
575

I do not think that listing the primitives and exact bits used is needed there. In particular, nobody would even guess that there is such place to fix if doing a work on the locks.

sys/kern/kern_thread.c
575

I agree, we do not need to be so specific, the comment will just become stale over time.

olce marked 3 inline comments as done.
olce edited the summary of this revision. (Show Details)

More generic comment. Move the current list of synchronization primitives to the commit message.

sys/kern/kern_thread.c
575

I certainly would look at the alignment for allocated thread structures if I had to use one more bit in one of the synchronization primitives. And probably would I look here as well if I was removing the use of one of them. Plus I suspect these don't change very often. But OK.

This revision is now accepted and ready to land.Oct 19 2023, 9:41 PM
This revision was automatically updated to reflect the committed changes.