Repository navigation
Embed tcache into tsd - #736
Conversation
baf00f3 to
ed0ca2f
Compare
|
This is ready for review. Please only look at the most recent commit "Integrate auto tcache into TSD." |
a5979c9 to
fc11f4a
Compare
| rtree_ctx->cache[i].leafkey = \ | ||
| rtree_ctx->cache[i - 1].leafkey; \ | ||
| rtree_ctx->cache[i].leaf = \ | ||
| rtree_ctx->cache[i - 1].leaf; \ |
There was a problem hiding this comment.
With this diff, if we don't change the struct assignment to assigning leafkey and leaf separately, it triggers a gcc internal compiler error like this one: https://travis-ci.org/jemalloc/jemalloc/jobs/217459658
d454d9b to
731baec
Compare
| } \ | ||
| if (a_cleanup != malloc_tsd_no_cleanup && \ | ||
| if (/* a_cleanup != malloc_tsd_no_cleanup && */ \ | ||
| /* Verify compiler (mingw32+gcc) bug.*/ \ |
There was a problem hiding this comment.
Confirmed compiler bug. On Windows with MinGW64, the "a_cleanup != malloc_tsd_no_cleanup" is not computed correctly and is compiled to false incorrectly, even though we never actually passed in malloc_tsd_no_cleanup. This resulted in missing cleanups. Without this line of change (and L404), the test failure is reproducible in Windows, e.g. https://ci.appveyor.com/project/jasone/jemalloc/build/638/job/ulyou1yumv1b1o6a
I'll update with a workaround.
There was a problem hiding this comment.
Regarding workarounds to avoid the compiler issue:
- I tried replacing malloc_tsd_no_cleanup with NULL, i.e. changing "a_cleanup != malloc_tsd_no_cleanup" to "a_cleanup != NULL", and that worked fine, except that a bunch of warnings about the comparison will always be true as the address will never be NULL. (I suspect this was part of the reason to have malloc_tsd_no_cleanup?)
- keep malloc_tsd_no_cleanup (change it to an empty function instead of assert not_reached), but remove the check "a_cleanup != malloc_tsd_no_cleanup". Theoretically compiler should still be able to optimize this away when malloc_tsd_no_cleanup is actually used.
Thoughts @davidtgoldblatt?
There was a problem hiding this comment.
Do we care about the compiler optimization in case 2? This only matters once per thread, right?
There was a problem hiding this comment.
Yeah the overhead should be minimal -- happen only once per thread and only a dull function call (if it's not optimized away).
In fact, since currently we don't use the _no_cleanup. It doesn't matter at all.
b4505c0 to
525b36c
Compare
| }; | ||
|
|
||
| static const tsd_t tsd_initializer = TSD_INITIALIZER; | ||
| UNUSED static const void *malloc_tsd_no_cleanup = (void *)0; |
There was a problem hiding this comment.
As mentioned previously, this change is to avoid a compiler issue, where the empty function version before this diff cannot be compared correctly in "a_cleanup != malloc_tsd_no_cleanup" under Windows MinGW64.
6ec0de2 to
2c3c3e2
Compare
davidtgoldblatt
left a comment
There was a problem hiding this comment.
A+++++ would review again
|
Had a small initialization tweak. To be safe will wait for the tests before pushing. |
The embedded tcache is initialized upon tsd initialization. The avail arrays for the tbins will be allocated / deallocated accordingly during init / cleanup. With this change, the pointer to the auto tcache will always be available, as long as we have access to the TSD. tcache_available() (called in tcache_get()) is provided to check if we should use tcache.
Integrate auto tcache into TSD.
The embedded tcache is initialized upon tsd initialization. The avail arrays
for the tbins will be allocated / deallocated accordingly during init / cleanup.
With this change, the pointer to the auto tcache will always be available, as
long as we have access to the TSD. tcache_available() (called in tcache_get())
is provided to check if we should use tcache.
This is part of #701.