pgsql: Allow repalloc() to give back space when a large chunk is downsi

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow repalloc() to give back space when a large chunk is downsi
Date: 2019-10-03 17:56:49
Message-ID: E1iG5LN-0006Lg-JC@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow repalloc() to give back space when a large chunk is downsized.

Up to now, if you resized a large (>8K) palloc chunk down to a smaller
size, aset.c made no attempt to return any space to the malloc pool.
That's unpleasant if a really large allocation is resized to a
significantly smaller size. I think no such cases existed when this
code was designed, and I'm not sure whether they're common even yet,
but an upcoming fix to encoding conversion will certainly create such
cases. Therefore, fix AllocSetRealloc so that it gives realloc()
a chance to do something with the block. This doesn't noticeably
increase complexity, we mostly just have to change the order in which
the cases are considered.

Back-patch to all supported branches.

Discussion: https://postgr.es/m/20190816181418.GA898@alvherre.pgsql
Discussion: https://postgr.es/m/3614.1569359690@sss.pgh.pa.us

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9a407209a075b53b9ef7141c0f87e91dba41b8b1

Modified Files
--------------
src/backend/utils/mmgr/aset.c | 142 +++++++++++++++++++++++-------------------
1 file changed, 77 insertions(+), 65 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2019-10-03 21:34:49 pgsql: Avoid unnecessary out-of-memory errors during encoding conversio
Previous Message Robert Haas 2019-10-03 13:48:32 Re: pgsql: Implement jsonpath .datetime() method