Re: copy.c allocation constant

From: Andres Freund <andres(at)anarazel(dot)de>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, 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 18:43:19
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2018-01-24 13:19:19 -0500, Robert Haas wrote:
> On Wed, Jan 24, 2018 at 12:25 PM, Tomas Vondra
> <tomas(dot)vondra(at)2ndquadrant(dot)com> wrote:
> > At the glibc level ... I'm not so sure. AFAIK glibc uses an allocator
> > with similar ideas (freelists, ...) so hopefully it's fine too.
> >
> > And then there are the systems without glibc, or with other libc
> > implementations. No idea about those.
> My guess is that a fairly common pattern for larger chunks will be to
> round the size up to a multiple of 4kB, the usual memory page size.

Indeed. Don't think RAW_BUF_SIZE is quite big enough for that on most
platforms though. From man mallopt:
Balancing these factors leads to a default setting of 128*1024 for the M_MMAP_THRESHOLD parameter.
Additionally, even when malloc() chooses to use mmap() to back an
allocation, it'll still needs a header to know the size of the
allocation and such. So exactly using a size of a multiple of 4KB will
still leave you with wasted space. Due to the latter I can't see it
mattering whether or not we add +1 to a power-of-two size.

There's malloc_usable_size() returning the actual size of an
allocation. It'd probably be worthwhile to use that in a few of our own
allocator routines. If not available on a platform we can just have a
stub that returns the requested size...


Andres Freund

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Chapman Flack 2018-01-24 18:48:05 Re: Would a BGW need shmem_access or database_connection to enumerate databases?
Previous Message Arthur Zakirov 2018-01-24 18:35:41 Re: [PROPOSAL] Shared Ispell dictionaries