Re: Limiting memory allocation - Mailing list pgsql-hackers

From Jan Wieck
Subject Re: Limiting memory allocation
Date
Msg-id c4279b7e-a785-1503-7489-a35e72fc4f45@wi3ck.info
Whole thread Raw
In response to Re: Limiting memory allocation  (Tomas Vondra <tomas.vondra@enterprisedb.com>)
List 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



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Enforce "max_wal_size/ min_wal_size must be at least twice wal_segment_size" limit while setting GUCs
Next
From: Robert Haas
Date:
Subject: Re: Zstandard support for toast compression