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

WIP: Refactor representation of thread local state. #751

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mjp41
Copy link
Member

@mjp41 mjp41 commented Feb 20, 2025

  • Provides template parameter to perform initialisation
  • Reduces TLS to only two entries, rather than a fairly large entry.

Stacked on top of #750

@mjp41 mjp41 force-pushed the thread_local_refactor branch 2 times, most recently from 318a880 to 0614a01 Compare February 20, 2025 13:52
@mjp41 mjp41 changed the title WIP: Refactor representation of local state. WIP: Refactor representation of thread local state. Feb 20, 2025
@mjp41 mjp41 force-pushed the thread_local_refactor branch 3 times, most recently from 80d24e0 to 0fd6768 Compare February 21, 2025 14:22
@@ -4,7 +4,7 @@

namespace snmalloc
{
template<SNMALLOC_CONCEPT(IsConfig) Config>
template<SNMALLOC_CONCEPT(IsConfig) Config = Config>
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. I'm a little surprised these aren't triggering shadowing warnings?
  2. Are these functions ever invoked with non-default Configs? If not, maybe convert the template parameter and concept annotation to a suitable static_assert requires?

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 did Config_ in #750.

CMakeLists.txt Outdated

foreach(FLAVOUR ${FLAVOURS})
if (${FLAVOUR} STREQUAL "malloc")
set(DEFINES SNMALLOC_PASS_THROUGH)
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉

@nwf
Copy link
Collaborator

nwf commented Feb 21, 2025

Only found time to make it into "Restrict ThreadAlloc usage to globalalloc", but so far so great. Thanks for nwfifying the commit stack. :D

@mjp41 mjp41 force-pushed the thread_local_refactor branch 5 times, most recently from 41392d1 to 654bcfd Compare February 21, 2025 20:46
Copy link
Collaborator

@nwf nwf left a comment

Choose a reason for hiding this comment

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

This continues to look really nice. (Read up through "WIP", exclusive.)

return self->alloc_not_small<zero_mem, CheckInitDefault>(size);
},
size,
this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit of a pity that something so formulaic can't, AFAIK, be templated away.

The check init code was tightly integrated into LocalAllocator.  This commit pull that code out into ThreadAlloc, and passes a template parameter into the remaining LocalAllocator to perform the relevant TLS manipulations.  This removes some of the awkward layering around register_clean_up.
Fully disable lotsofthreads test

Need to investigate if the test is unreliable, or we have actually
regressed perf.  A quick mimalloc-bench didn't show any regressions.
This introduces one additional branch on when processing a batch of messages, but it is likely to only be hit when a lot of messages are processed.
@mjp41 mjp41 force-pushed the thread_local_refactor branch from 654bcfd to fdab65d Compare February 22, 2025 20:17
@mjp41
Copy link
Member Author

mjp41 commented Feb 22, 2025

@nwf thanks for the comments. I've addressed them. And I landed the first set of commits in #750.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants