Skip to content

Hotpatch out remaining fast-path option branches - #353

Closed
djwatson wants to merge 1 commit into
jemalloc:devfrom
djwatson:hotpatch
Closed

djwatson wants to merge 1 commit into
jemalloc:devfrom
djwatson:hotpatch

Conversation

@djwatson

@djwatson djwatson commented Mar 9, 2016

Copy link
Copy Markdown

commit f4a0f32 sped up the fast-path substantially, but we still have
an init check (slow_path), and a prof / prof_active check. Using
dynamic runtime code patching, we can remove all of them.

This depends on asm goto in gcc, and static global addresses, so optimize
mode is also required. Code is provided for x86_64 only, but
the same technique should work on most arches.

Note that although we patch the option, currently running threads
may still take the old branch for a while until the cache flushes,
so this is only an optimization.

Testing:

In microbenchmarks, this is a 2% cpu improvement. It's so small it is hard
to tell in production though. By comparison, sized-deallocations are 10% cpu
in a microbenchmark.

linux's perf utility was used to view currently executing asm. Used mallctl
to flip prof_active on/off, checked that it appeared to be working correctly.

Tested building in debug / opt mode, but don't have anything else besides
x86_64 to check that the compile options are correct.

@djwatson

djwatson commented Mar 9, 2016

Copy link
Copy Markdown
Author

It may be wise to make this a configure option also?

@djwatson
djwatson force-pushed the hotpatch branch 4 times, most recently from d13747f to cb33fce Compare March 10, 2016 00:08
@jasone

jasone commented Mar 11, 2016

Copy link
Copy Markdown
Member

Re: configure option, at a minimum we need a configure test to conditionally enable this code for the supported platform (gcc+x86_64).

@jasone jasone added this to the 4.2.0 milestone Mar 11, 2016
@djwatson
djwatson force-pushed the hotpatch branch 2 times, most recently from 90e158b to 88d422e Compare March 15, 2016 21:03
@djwatson

Copy link
Copy Markdown
Author

@interwq 's comments

  • Attempted to add to configure.ac, could probably still be more pedantic.
  • The prof_active check does seem to work correctly in prof_alloc_prep, but we have to use the var directly and not the param. Could probably use an additional cleanup diff there, the param is always 'prof_active_get_unlocked'

Comment thread include/jemalloc/internal/prof.h Outdated

if (!prof_active || likely(prof_sample_accum_update(tsd, usize, update,
&tdata)))
if (!malloc_option_default_on(&prof_active) ||

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.

This isn't safe, because there are code paths that require consistency re: prof_active across a series of function invocations, e.g. in irealloc_prof(). Should I just revert this particular change, or is there some other way we can accomplish this safely?

@jasone jasone modified the milestones: 5.0.0, 4.2.0 May 6, 2016
@djwatson

djwatson commented Jul 6, 2016

Copy link
Copy Markdown
Author
  • rebased
  • dropped PROF_ACTIVE check, it doesn't make nearly as big of a difference as the other two (.5% vs 3-4% in microbench)
  • I was never able to repro the build failure, even with the same OS/compiler. Changed the functions to be macros instead, which seems to also work for debug builds - the macros provide a constant to emit in inline assembly, instead of relying on the inliner to provide a constant address for global values.

@djwatson
djwatson force-pushed the hotpatch branch 3 times, most recently from 12f84b2 to fa73ac8 Compare July 6, 2016 21:55
commit f4a0f32 sped up the fast-path substantially, but we still have
an init check (slow_path), and a prof / prof_active check.  Using
dynamic runtime code patching, we can remove all of them.

This depends on asm goto in gcc, and static global addresses, so optimize
mode is also required.  Code is provided for x86_64 only, but
the same technique should work on most arches.

Note that although we patch the option, currently running threads
may still take the old branch for a while until the cache flushes,
so this is only an optimization.

Testing:

In microbenchmarks, this is a 2% cpu improvement.  It's so small it is hard
to tell in production though.  By comparison, sized-deallocations are 10% cpu
in a microbenchmark.

linux's perf utility was used to view currently executing asm.  Used mallctl
to flip prof_active on/off, checked that it appeared to be working correctly.

Tested building in debug / opt mode, but don't have anything else besides
x86_64 to check that the compile options are correct.
@djwatson

djwatson commented Jan 9, 2017

Copy link
Copy Markdown
Author

5.0 is looking big, would prefer to punt until later, possibly a minor release since this doesn't change any APIs.

A recent paper on this technique: http://www.cs.indiana.edu/~rrnewton/papers/pldi16-crossmod.pdf
May need to add align statements to the asm, but otherwise looks like it should work fine.

May conflict with #501 , since it might remove some of the slow path branches needed to support reentrancy. The config option branches could probably still be removed though

@jasone

jasone commented Jan 9, 2017

Copy link
Copy Markdown
Member

Punting to a later release, per @djwatson's recommendation.

@jasone jasone removed this from the 5.0.0 milestone Jan 9, 2017
@jasone

jasone commented Jan 11, 2017

Copy link
Copy Markdown
Member

Closing, now that #539 is tracking the hotpatching.

@jasone jasone closed this Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants