Re: copy.c allocation constant - Mailing list pgsql-hackers

From Andres Freund
Subject Re: copy.c allocation constant
Date
Msg-id 20180124184319.4k3qwpn4tu5fnhnh@alap3.anarazel.de
Whole thread Raw
In response to Re: copy.c allocation constant  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: copy.c allocation constant
List 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.vondra@2ndquadrant.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...

Greetings,

Andres Freund


pgsql-hackers by date:

Previous
From: Arthur Zakirov
Date:
Subject: Re: [PROPOSAL] Shared Ispell dictionaries
Next
From: Chapman Flack
Date:
Subject: Re: Would a BGW need shmem_access or database_connection to enumeratedatabases?