Skip to content

allocate: thread-local allocations.#212

Open
iskamag wants to merge 10 commits into
froggey:masterfrom
iskamag:tlabka
Open

allocate: thread-local allocations.#212
iskamag wants to merge 10 commits into
froggey:masterfrom
iskamag:tlabka

Conversation

@iskamag
Copy link
Copy Markdown
Contributor

@iskamag iskamag commented May 8, 2026

No description provided.

@iskamag iskamag marked this pull request as ready for review May 8, 2026 09:10
@iskamag iskamag marked this pull request as draft May 14, 2026 22:07
@iskamag iskamag marked this pull request as ready for review May 14, 2026 22:12
@froggey
Copy link
Copy Markdown
Owner

froggey commented May 17, 2026

Due to cross-cpu migration I don't think this is SMP-safe at the moment. Each cpu has it's own tlab bump/limit, but there's no synchronization here ensuring the correct limit is compared against if a migration occurs between the limit load and bump update.

  1. %do-allocate-from-general-area called
  2. Load fs:tlab-limit
  3. Migration occurs. This switches cpu and changes fs, makes the loaded limit stale
  4. Fetch/inc fs:tlab-base
  5. Compare new bump pointer against the stale limit (this is effectively another cpu's limit)

Same issue on arm64.

Possible solutions:

  1. put tlab in the thread object instead of the cpu. means we have more tlabs and memory pressure increases but then they are truly thread-local. keeping the allocation meters accurate might be a pain here. the advantage is that no synchronization is needed at all on the hot path and a thread's thread object is inherently stable.
  2. disable interrupts on the hot path? ugly, scary. disabling interrupts is dangerous. Very tricky when also needing to write arbitrary heap memory
  3. keep the tlab on the cpu, but go back to using atomics and load the cpu struct at the start of %do-allocate-from-general-area, this way it's consistent the whole way through
  4. something else? secret fourth thing?

Aside from this, I really like the approach. It's surprisingly non-invasive

@froggey
Copy link
Copy Markdown
Owner

froggey commented May 17, 2026

arm64 build completes successfully with my changes btw

@iskamag
Copy link
Copy Markdown
Contributor Author

iskamag commented May 17, 2026

TSX would've fixed this.

Anyway, I think option 1 is better. Since Claimore would be thread-local...

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