Skip to content

Optimizing TSD and thread cache layout. - #752

Merged
interwq merged 2 commits into
jemalloc:devfrom
interwq:tcache_fast
Apr 7, 2017
Merged

interwq merged 2 commits into
jemalloc:devfrom
interwq:tcache_fast

Conversation

@interwq

@interwq interwq commented Apr 7, 2017

Copy link
Copy Markdown
Contributor
  1. Re-organize TSD so that frequently accessed fields are closer to the
    beginning and more compact. Assuming 64-bit, the first 3.5 cachelines now
    contains everything needed on tcache fast path, expect the tcache struct itself.

  2. Re-organize tcache and tbins. Take lg_fill_div out of tbin, and reduce tbin
    to 24 bytes (down from 32). Split tbins into tbins_small and tbins_large, and
    place tbins_small close to the beginning.

@interwq

interwq commented Apr 7, 2017

Copy link
Copy Markdown
Contributor Author

Only the top commit "Optimizing TSD and thread cache layout." is relevant.

@interwq

interwq commented Apr 7, 2017

Copy link
Copy Markdown
Contributor Author

micro-benchmark shows no difference with this diff. However this makes tsd and tbins more compact, and will reduce cache footprint. I expect this to be helpful in production workload.

Along with #736, this completes #701.

With the tcache change, we plan to leave some blank space when !config_debug
(unused tbins, witnesses) at the end of the tsd. Let's not touch the memory.
@davidtgoldblatt

Copy link
Copy Markdown
Contributor

I think this works better with a helper "Get bin N" function. This introduces enough fiddly details into every tcache access that I think we should be pretty skeptical of doing it without performance data backing it up.

@interwq

interwq commented Apr 7, 2017

Copy link
Copy Markdown
Contributor Author

@davidtgoldblatt: yeah a get_bin helper makes sense. I'll update the diff with that.

Regarding perf data, u-benchmark confirms no regression with this. Since this is pretty tightly coupled with #736, I'd say let's land this and benchmark together?

@davidtgoldblatt

Copy link
Copy Markdown
Contributor

Seems reasonable.

1) Re-organize TSD so that frequently accessed fields are closer to the
beginning and more compact.  Assuming 64-bit, the first 2.5 cachelines now
contains everything needed on tcache fast path, expect the tcache struct itself.

2) Re-organize tcache and tbins.  Take lg_fill_div out of tbin, and reduce tbin
to 24 bytes (down from 32). Split tbins into tbins_small and tbins_large, and
place tbins_small close to the beginning.
@interwq

interwq commented Apr 7, 2017

Copy link
Copy Markdown
Contributor Author

Just updated with:
tcache_small_bin_get() and tcache_large_bin_get().

I have the 2 explicit versions instead of just tcache_bin_get() and checks bin index internal, because:

  1. in almost all cases, we do know we want small or large bins.
  2. more importantly, even with opt build at a few places the redundant binind branch inside tcache_bin_get wasn't optimized away.

So in the end I went with the two getters above.

@interwq
interwq merged commit 36bd90b into jemalloc:dev Apr 7, 2017
@interwq
interwq deleted the tcache_fast branch April 7, 2017 21:06
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