Re: Backend memory dump analysis

Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>
Cc: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-03-27T23:32:54Z
Lists: pgsql-hackers
On 3/27/18 12:47, Tom Lane wrote:
> Here's an updated patch that adjusts the output format per discussion:
> 
> - context identifier at the end of the line, so it's easier to see the
>   numbers
> 
> - identifiers truncated at 100 bytes, control characters replaced by
>   spaces
> 
> Also, I hacked things so that dynahash hash tables continue to print
> the way they did before, since the hash table name is really what
> you want to see there.
> 
> Sample output is same test case as last time (dump at end of plpgsql.sql
> regression test script).
> 
> Barring objection I plan to push this shortly.

Cool.

How about this one as well:

diff --git a/src/backend/utils/mmgr/portalmem.c
b/src/backend/utils/mmgr/portalmem.c
index 75a6dde32b..c08dc260e2 100644
--- a/src/backend/utils/mmgr/portalmem.c
+++ b/src/backend/utils/mmgr/portalmem.c
@@ -200,6 +200,7 @@ CreatePortal(const char *name, bool allowDup, bool
dupSilent)
    portal->portalContext = AllocSetContextCreate(TopPortalContext,
                                                  "PortalContext",
                                                  ALLOCSET_SMALL_SIZES);
+   MemoryContextCopySetIdentifier(portal->portalContext, name);

    /* create a resource owner for the portal */
    portal->resowner = ResourceOwnerCreate(CurTransactionResourceOwner,


The term CopySetIdentifier has confused me a bit.  (What's a "set
identifier"?)  Maybe use CopyAndSetIdentifier?  (We similarly have
MemoryContextResetAndDeleteChildren.)

I'm also not clear why this doesn't undo the previous optimization that
preferred making the identifier a compile time-constant.  Aren't we now
just going back to doing a pstrdup() every time?

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Commits

  1. Add memory context identifier to portal context

  2. Rename MemoryContextCopySetIdentifier() for clarity

  3. Allow memory contexts to have both fixed and variable ident strings.

  4. Rethink MemoryContext creation to improve performance.