Re: Avoid stack frame setup in performance critical routines using tail calls

Andres Freund <andres@anarazel.de>

From: "Andres Freund" <andres@anarazel.de>
To: "David Rowley" <dgrowleyml@gmail.com>
Cc: "PostgreSQL Development" <pgsql-hackers@postgresql.org>, "Robert Haas" <robertmhaas@gmail.com>, "Michael Paquier" <michael.paquier@gmail.com>, "Tomas Vondra" <tv@fuzzy.cz>
Date: 2021-07-20T07:03:51Z
Lists: pgsql-hackers
Hi,

On Mon, Jul 19, 2021, at 23:53, David Rowley wrote:
> On Tue, 20 Jul 2021 at 18:17, Andres Freund <andres@anarazel.de> wrote:
> > Any chance you could show a `perf annotate AllocSetAlloc` and `perf annotate
> > palloc` from a patched run? And perhaps how high their percentages of the
> > total work are. E.g. using something like
> > perf report -g none|grep -E 'AllocSetAlloc|palloc|MemoryContextAlloc|pfree'
> 
> Sure. See attached.
> 
> David
> 
> Attachments:
> * AllocateSetAlloc.txt
> * palloc.txt
> * percent.txt

Huh, that's interesting. You have some control flow enforcement stuff turned on (the endbr64). And it looks like it has a non zero cost (or maybe it's just skid). Did you enable that intentionally? If not, what compiler/version/distro is it? I think at least on GCC that's -fcf-protection=...

Andres



Commits

  1. Optimize GenerationAlloc() and SlabAlloc()

  2. Refactor AllocSetAlloc(), separating hot and cold paths

  3. Adjust memory allocation functions to allow sibling calls