This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] Annotate malloc conditions with glibc_likely.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Will Newton <will dot newton at linaro dot org>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Tue, 10 Dec 2013 17:16:50 +0100
- Subject: Re: [PATCH] Annotate malloc conditions with glibc_likely.
- Authentication-results: sourceware.org; auth=none
- References: <20131209204454 dot GA6225 at domone dot podge> <CANu=DmjE_RR-kWwOLw92HNr9OmKTAswnsqi2hgCTWi7QigY2xg at mail dot gmail dot com>
On Tue, Dec 10, 2013 at 09:54:31AM +0000, Will Newton wrote:
> On 9 December 2013 20:44, OndÅej BÃlka <email@example.com> wrote:
> > Hi,
> > Another little optimization in malloc is annotate that fastbins are
> > likely case. These should be fast path and given that other path
> > slower it should pay off.
> In general I am not in favour of adding these types of annotations
> unless we can show they improve performance as they make code harder
> to read. They are also something of a blunt instrument - does "likely"
> mean will happen with 75% likelihood? 90%? 99%? I guess the results
> will vary with compiler and architecture as to whether or not the
> annotation helps or not.
A malloc is one of hottest place based on profiling data, followed by
assembly routines and code after these is not that frequent.
For most projects you can replace expects by creating test run and using
profile feedback. For libc you would first need to hack gcov for
that/make oprofile feedback reliable/write userspace profiler.
As how much this help actual probability does not matter much as
compiler do not have yet optimization where these make a difference.
Here benefits are mainly that gcc without hints does stupid things like
spilling five registers at start of function even these are unlikely
Then there are icache and branch cache factors (taken path should be
more probable for static prediction and avoiding cache pollution.)
which are more relevant for cold code.