Re: copy.c allocation constant

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: copy.c allocation constant
Date: 2018-01-24 20:43:41
Message-ID: CAEepm=1LTfCGGfQxoDLeWgKKC9VaRMVgZZjQCDZv7rS_EW2gqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 25, 2018 at 9:35 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> The BSD memory allocator used to allocate in powers of two, and keep the
> header in a separate location. They did this so they could combine two
> free, identically-sized memory blocks into a single one that was double
> the size. I have no idea how it works now.

According to "man malloc" on my FreeBSD 11.1 box (which uses jemalloc,
I think NetBSD and OpenBSD use something else), the code Andrew showed
at the top of this thread will waste ~16kB (because it'll round up to
80kB) and nodeHash.c will waste ~8kB for every ~32kB chunk of tuples
as described in that other thread.

+----------------------------------------------------------+
|Category Spacing Size |
|Small lg [8] |
| 16 [16, 32, 48, 64, 80, 96, 112, 128] |
| 32 [160, 192, 224, 256] |
| 64 [320, 384, 448, 512] |
| 128 [640, 768, 896, 1024] |
| 256 [1280, 1536, 1792, 2048] |
| 512 [2560, 3072, 3584, 4096] |
| 1 KiB [5 KiB, 6 KiB, 7 KiB, 8 KiB] |
| 2 KiB [10 KiB, 12 KiB, 14 KiB] |
|Large 2 KiB [16 KiB] |
| 4 KiB [20 KiB, 24 KiB, 28 KiB, 32 KiB] |
| 8 KiB [40 KiB, 48 KiB, 54 KiB, 64 KiB] |
| 16 KiB [80 KiB, 96 KiB, 112 KiB, 128 KiB] |
| 32 KiB [160 KiB, 192 KiB, 224 KiB, 256 KiB] |
| 64 KiB [320 KiB, 384 KiB, 448 KiB, 512 KiB] |
| 128 KiB [640 KiB, 768 KiB, 896 KiB, 1 MiB] |
| 256 KiB [1280 KiB, 1536 KiB, 1792 KiB] |
|Huge 256 KiB [2 MiB] |
| 512 KiB [2560 KiB, 3 MiB, 3584 KiB, 4 MiB] |
| 1 MiB [5 MiB, 6 MiB, 7 MiB, 8 MiB] |
| 2 MiB [10 MiB, 12 MiB, 14 MiB, 16 MiB] |
| 4 MiB [20 MiB, 24 MiB, 28 MiB, 32 MiB] |
| 8 MiB [40 MiB, 48 MiB, 56 MiB, 64 MiB] |
| ... ... |
| 512 PiB [2560 PiB, 3 EiB, 3584 PiB, 4 EiB] |
| 1 EiB [5 EiB, 6 EiB, 7 EiB] |
+----------------------------------------------------------+

--
Thomas Munro
http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-01-24 20:43:59 Re: pgsql: Add parallel-aware hash joins.
Previous Message Tom Lane 2018-01-24 20:36:35 Re: pgsql: Add parallel-aware hash joins.