Re: pgsql: Add function to log the memory contexts of specified backend pro

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgsql: Add function to log the memory contexts of specified backend pro
Date: 2025-07-14 13:53:38
Message-ID: 27da56de-17c4-4af2-8032-3c58ae0c7b00@oss.nttdata.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On 2025/05/07 18:06, Fujii Masao wrote:
>
>
> On 2025/05/05 23:57, Robert Haas wrote:
>> On Fri, May 2, 2025 at 9:54 PM Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com> wrote:
>>> Thanks for the review and testing! I've fixed the issue you pointed out.
>>> Updated patch attached.
>>
>> Thanks for addressing this. However, I believe this commit may need to
>> take note of the following comment from elog.h:
>
> Thanks for the review!
>
>
>>   * Note: if a local variable of the function containing PG_TRY is modified
>>   * in the PG_TRY section and used in the PG_CATCH section, that variable
>>   * must be declared "volatile" for POSIX compliance.  This is not mere
>>   * pedantry; we have seen bugs from compilers improperly optimizing code
>>   * away when such a variable was not marked.  Beware that gcc's -Wclobbered
>>   * warnings are just about entirely useless for catching such oversights.
>>
>> Based on this comment, I believe in_progress must be declared volatile.
>
> You're right. OTOH, setting the flag inside the PG_TRY() block isn't necessary,
> so I've moved it outside instead of leaving it inside and marking the flag volatile.
>
>
>> As a stylistic comment, I think I would prefer making in_progress a
>> file-level global and giving it a less generic name (e.g.
>> LogMemoryContextInProgress). However, perhaps others will disagree.
>
> I'm fine with this. I've renamed the flag and made it a file-level global
> variable as suggested. Updated patch is attached.

I've attached the rebased versions of the patches.

The patch for v14–v16 is labeled with a .txt extension to prevent cfbot
from treating it as a patch for master, which would cause it to fail
when applying.

Regards,

--
Fujii Masao
NTT DATA Japan Corporation

Attachment Content-Type Size
v4-0001-PG14-PG16-Add-guard-to-prevent-recursive-memory-context-log.txt text/plain 4.2 KB
v4-0001-PG17-master-Add-guard-to-prevent-recursive-memory-context-log.patch text/plain 4.3 KB

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-07-14 20:13:39 pgsql: Stamp 18beta2.
Previous Message Fujii Masao 2025-07-14 11:06:13 pgsql: amcheck: Improve error message for partitioned index target.

Browse pgsql-hackers by date

  From Date Subject
Next Message Maxim Orlov 2025-07-14 13:54:33 Re: POC: make mxidoff 64 bits
Previous Message Andres Freund 2025-07-14 13:42:46 Re: Changing shared_buffers without restart