From bea3d7e3831fa6a1395eadbad7d97cebc7aa8aee Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Sat, 8 Apr 2023 21:52:35 +1200 Subject: Use MemoryContext API for regex memory management. Previously, regex_t objects' memory was managed with malloc() and free() directly. Switch to palloc()-based memory management instead. Advantages: * memory used by cached regexes is now visible with MemoryContext observability tools * cleanup can be done automatically in certain failure modes (something that later commits will take advantage of) * cleanup can be done in bulk On the downside, there may be more fragmentation (wasted memory) due to per-regex MemoryContext objects. This is a problem shared with other cached objects in PostgreSQL and can probably be improved with later tuning. Thanks to Noah Misch for suggesting this general approach, which unblocks later work on interrupts. Suggested-by: Noah Misch Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com --- src/include/regex/regcustom.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/include/regex') diff --git a/src/include/regex/regcustom.h b/src/include/regex/regcustom.h index fc158e1bb7..8f4025128e 100644 --- a/src/include/regex/regcustom.h +++ b/src/include/regex/regcustom.h @@ -49,9 +49,9 @@ /* overrides for regguts.h definitions, if any */ #define FUNCPTR(name, args) (*name) args -#define MALLOC(n) malloc(n) -#define FREE(p) free(VS(p)) -#define REALLOC(p,n) realloc(VS(p),n) +#define MALLOC(n) palloc_extended((n), MCXT_ALLOC_NO_OOM) +#define FREE(p) pfree(VS(p)) +#define REALLOC(p,n) repalloc_extended(VS(p),(n), MCXT_ALLOC_NO_OOM) #define assert(x) Assert(x) /* internal character type and related */ -- cgit v1.2.3