Skip to content

Use trylock in tcache_flush when possible - #800

Merged
interwq merged 2 commits into
jemalloc:devfrom
interwq:tcache_lock
Apr 26, 2017
Merged

interwq merged 2 commits into
jemalloc:devfrom
interwq:tcache_lock

Conversation

@interwq

@interwq interwq commented Apr 25, 2017

Copy link
Copy Markdown
Contributor

In a production workload,
free -> je_tcache_bin_flush_small -> mutex_lock and
tcache_event_hard -> tcache_bin_flush_small -> mutex_lock paths are ranked 2nd and 3rd hottest among all mutex related paths. This change tries to use trylock to make it non-blocking whenever possible, similar to what we did for decay_lock.

Comment thread src/tcache.c
void *ptr = *(tbin->avail - 1 - i);
assert(ptr != NULL);
extent = iealloc(tsd_tsdn(tsd), ptr);
extent = item_extent[i];

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.

This was fixed separately in #799. Will rebase past that before landing.

Comment thread src/tcache.c Outdated
}

bool merged_stats = false;
unsigned nflushed = 0, nskipped = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Style nit: For declarations incorporating initialization, only declare one variable per statement.

Comment thread src/tcache.c
malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
}
if (must_flush ||
!malloc_mutex_trylock(tsd_tsdn(tsd), &bin->lock)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Subtle logic here. Add a malloc_mutex_assert_owner() to make it obvious that the mutex is owned inside the block?

@interwq
interwq force-pushed the tcache_lock branch 2 times, most recently from f9c11d9 to 9fc8e20 Compare April 26, 2017 00:09
interwq added 2 commits April 25, 2017 17:11
During tcache gc, use tcache_bin_try_flush_small / _large so that we can skip
items with their bins locked already.
Only do must_flush if try_flush didn't manage to free anything.
@interwq

interwq commented Apr 26, 2017

Copy link
Copy Markdown
Contributor Author

Only style changes were made. Merging.

@interwq
interwq merged commit b0c2a28 into jemalloc:dev Apr 26, 2017
@interwq
interwq deleted the tcache_lock branch April 26, 2017 00:21
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