Re: slab allocator performance issues

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org, Tomas Vondra <tv(at)fuzzy(dot)cz>
Subject: Re: slab allocator performance issues
Date: 2021-07-18 17:23:31
Message-ID: 37dc9b41-dd75-251d-a77e-16c72c794b00@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/18/21 3:06 AM, Andres Freund wrote:
> Hi,
>
> On 2021-07-17 16:10:19 -0700, Andres Freund wrote:
>> Instead of populating a linked list with all chunks upon creation of a block -
>> which requires touching a fair bit of memory - keep a per-block pointer (or an
>> offset) into "unused" area of the block. When allocating from the block and
>> theres still "unused" memory left, use that, instead of bothering with the
>> freelist.
>>
>> I tried that, and it nearly got slab up to the allocation/freeing performance
>> of aset.c (while winning after allocation, due to the higher memory density).
>
> Combining that with limiting the number of freelists, and some
> microoptimizations, allocation performance is now on par.
>
> Freeing still seems to be a tad slower, mostly because SlabFree()
> practically is immediately stalled on fetching the block, whereas
> AllocSetFree() can happily speculate ahead and do work like computing
> the freelist index. And then aset only needs to access memory inside the
> context - which is much more likely to be in cache than a freelist
> inside a block (there are many more).
>
> But that's ok, I think. It's close and it's only a small share of the
> overall runtime of my workload...
>

Sounds great! Thanks for investigating this and for the improvements.

It might be good to do some experiments to see how the changes affect
memory consumption for practical workloads. I'm willing to spend soem
time on that, if needed.

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2021-07-18 18:19:10 Re: cleaning up PostgresNode.pm
Previous Message Andrew Dunstan 2021-07-18 15:48:10 Re: cleaning up PostgresNode.pm