Re: MemoryContextCreate change in PG 11 how should contexts be created

From: Paul Ramsey <pramsey(at)cleverelephant(dot)ca>
To: Regina Obe <lr(at)pcorp(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: MemoryContextCreate change in PG 11 how should contexts be created
Date: 2017-12-19 14:34:30
Message-ID: CACowWR33zCgeX4_HdUN3Gsfx31FLwdFkqQaFvvXaMaRtG3aX1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 19, 2017 at 12:24 AM, Regina Obe <lr(at)pcorp(dot)us> wrote:
> On December 13th this change to context creation was committed, which broke
> PostGIS trunk compile against PostgreSQL 11 head.
> https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=9fa6f00b1308d
> d10da4eca2f31ccbfc7b35bb461
>
> Ticketed in PostGIS here:
> https://trac.osgeo.org/postgis/ticket/3946
>
>
> It's been broken for a couple of months
> https://trac.osgeo.org/postgis/ticket/3904 with just core dumping but at
> least it used to compile before December 13th.
>
>
> In going thru the changes I see that MemoryContextCreate was changed to not
> return a context anymore and to take in pointer to the context that should
> be returned among other changes.
>
> I also notice that MemoryContextCreate seems to be rarely used in PostgreSQL
> code in places I would expect and instead AllocSetContextCreateExtended is
> used.
>
> So is the preferred approach to not use MemoryContextCreate in extensions
> and instead for PG < 11 use AllocSetContextCreate and PG >= use
> AllocSetContextCreateExtended?
>
> Sorry if my questions don't make any sense. Still trying to grapple with
> all these memory context functions and how each is different from the other.
>
> For reference, one of the slices of code we have in place that broke looks
> something like this and we've got I think at least 5 more such instances
> sprinkled in PostGIS code base.
>
> https://git.osgeo.org/gitea/postgis/postgis/src/branch/svn-trunk/libpgcommon
> /lwgeom_transform.c#L550
>
>
>
> MemoryContext PJMemoryContext;
> POSTGIS_DEBUGF(3, "adding SRID %d with proj4text \"%s\" to query
> cache at index %d", srid, proj_str, PROJ4Cache->PROJ4SRSCacheCount);
>
> PJMemoryContext = MemoryContextCreate(T_AllocSetContext, 8192,
> &PROJ4SRSCacheContextMethods,
>
> PROJ4Cache->PROJ4SRSCacheContext,
> "PostGIS PROJ4 PJ Memory
> Context");

As Regina noted, we're working in https://trac.osgeo.org/postgis/ticket/3946

Our use of MemoryContextCreate is solely in order to get use
MemoryContextDelete as a callback so that, at the end of a statement,
we can clean up externally allocated memory that we're holding in a
cache. If we had some other callback to use for "the statement is
complete, you can clean up now", we could avoid all this mucking
around with raw MemoryContexts entirely. The MemoryContext trick/hack
is very old, perhaps a callback or hook has been added since then that
we could make use of?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2017-12-19 14:50:22 Re: Basebackups reported as idle
Previous Message Aleksandr Parfenov 2017-12-19 14:31:09 Re: [HACKERS] Flexible configuration for full-text search