Skip to content

Embed tcache into tsd - #736

Merged
interwq merged 1 commit into
jemalloc:devfrom
interwq:tcache
Apr 7, 2017
Merged

interwq merged 1 commit into
jemalloc:devfrom
interwq:tcache

Conversation

@interwq

@interwq interwq commented Mar 30, 2017 •

Copy link
Copy Markdown
Contributor

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.

@interwq
interwq force-pushed the tcache branch 4 times, most recently from baf00f3 to ed0ca2f Compare March 30, 2017 22:04
@interwq
interwq requested a review from davidtgoldblatt March 30, 2017 22:11
@interwq

interwq commented Mar 30, 2017

Copy link
Copy Markdown
Contributor Author

This is ready for review. Please only look at the most recent commit "Integrate auto tcache into TSD."

@interwq interwq changed the title [Not ready for review yet] Embed tcache into tsd Embed tcache into tsd Mar 30, 2017
@interwq
interwq force-pushed the tcache branch 16 times, most recently from a5979c9 to fc11f4a Compare April 1, 2017 07:09
rtree_ctx->cache[i].leafkey = \
rtree_ctx->cache[i - 1].leafkey; \
rtree_ctx->cache[i].leaf = \
rtree_ctx->cache[i - 1].leaf; \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@interwq
interwq force-pushed the tcache branch 6 times, most recently from d454d9b to 731baec Compare April 5, 2017 05:01
Comment thread include/jemalloc/internal/tsd_types.h Outdated
} \
if (a_cleanup != malloc_tsd_no_cleanup && \
if (/* a_cleanup != malloc_tsd_no_cleanup && */ \
/* Verify compiler (mingw32+gcc) bug.*/ \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@interwq interwq Apr 5, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regarding workarounds to avoid the compiler issue:

  1. 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?)
  2. 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we care about the compiler optimization in case 2? This only matters once per thread, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

};

static const tsd_t tsd_initializer = TSD_INITIALIZER;
UNUSED static const void *malloc_tsd_no_cleanup = (void *)0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@interwq
interwq force-pushed the tcache branch 2 times, most recently from 6ec0de2 to 2c3c3e2 Compare April 6, 2017 06:21

@davidtgoldblatt davidtgoldblatt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A+++++ would review again

@interwq

interwq commented Apr 7, 2017

Copy link
Copy Markdown
Contributor Author

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.
@interwq
interwq merged commit fde3e20 into jemalloc:dev Apr 7, 2017
@interwq
interwq deleted the tcache branch April 7, 2017 16:55
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