‹ BackHN Continuity

Thread

Jemalloc 5.4.0

339 points · 94 comments · gkfasdfasdf

  1. skavi · · focus · HN ↗
    does anyone familiar with the art have thoughts on why only tcmalloc switched from thread caches to cpu caches? would it make linux behavior diverge too much from other platforms?
    1. rwmj · · focus · HN ↗
      (Not an expert but ...) unless you pin threads to cores, which is not the default and somewhat awkward in Linux for user applications, having a per-thread cache doesn't really make sense as your thread could be moved to another core and then your cache will no longer be local to the physical cache.
      1. loeg · · focus · HN ↗
        Don't you just take the current cpuid when you go to access the cache again? Then you mutex and access the per-cpu state. There is a tiny race window but 99.99% of the time you will be hitting the same cpu's cache as you just identified, and there will be ~zero contention.

        The main issue is thread preemption while you're holding a per-core cache mutex. Some other thread can't do meaningful work using the cache while the holder is sleeping.

        1. ckennelly · · focus · HN ↗
          With restartable sequences in Linux, there is no need for mutexes or RMW atomics. The mutual exclusion is guaranteed by the kernel.
          1. loeg · · focus · HN ↗
            Fair enough.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.