Re: Limiting memory allocation

From: Jan Wieck <jan(at)wi3ck(dot)info>
To: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Oleksii Kliukin <alexk(at)hintbits(dot)com>
Cc: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Limiting memory allocation
Date: 2022-05-23 12:59:33
Message-ID: c4279b7e-a785-1503-7489-a35e72fc4f45@wi3ck.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5/20/22 19:08, Tomas Vondra wrote:
> Well, we already have the memory-accounting built into the memory
> context infrastructure. It kinda does the same thing as the malloc()
> wrapper, except that it does not publish the information anywhere and
> it's per-context (so we have to walk the context recursively).
>
> So maybe we could make this on-request somehow? Say, we'd a signal to
> the process, and it'd run MemoryContextMemAllocated() on the top memory
> context and store the result somewhere.

One remaining problem with all this is that we don't get any feedback
from calling free() telling if any memory has been returned to the OS or
not.

How portable would using sbrk() with a zero size be? If that is an
option then I could envision counting actual calls to malloc() and
whenever a GUC configurable amount is reached, use sbrk() to find out,
do the accounting in shared memory and react accordingly.

This way we are not creating another highly contended lock and use
authoritative information.

Regards, Jan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2022-05-23 13:32:15 Re: Zstandard support for toast compression
Previous Message Bharath Rupireddy 2022-05-23 12:13:49 Re: Enforce "max_wal_size/ min_wal_size must be at least twice wal_segment_size" limit while setting GUCs