Re: Enhancing Memory Context Statistics Reporting

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: Enhancing Memory Context Statistics Reporting
Date: 2026-03-05 22:31:09
Message-ID: CAH2L28tU+aC1+OR5S1ATxHPeyuGp5JAfBVcs+7r-h_N2JRaxUw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

The email below provides a summary of the changes implemented since the
previous
update on December 18th.

1. I tested and verified that when ProcessGetMemoryContextInterrupt()
returns with error
from processes that don't start a transaction, it doesn't affect system
integrity.
In auxiliary processes like ioworker, archiver, and wal_receiver, the ERROR
causes
the process to exit, which ensures proper resource and lock release. In
other cases,
cleanup and release are managed by error recovery logic, allowing processes
to continue
running smoothly.

2. I verified that the only resources acquired in
ProcessGetMemoryContextInterrupt
are DSMs, which remain attached until the process exits.
During proc_exit, the release/detach of DSM runs via dsm_backend_shutdown().

3.The error reporting level in the interrupt handler has been adjusted from
ERROR
to NOTICE to prevent unnecessary errors from being raised in interrupted
transactions
due to minor issues.

4. Aborted transaction check has been added to allow returning without
processing
the interrupt if it is called from an aborted transaction.

5. DSHash key type has been changed from string to integer, now using
procNumber
directly. This eliminates string formatting overhead.

6. Timeout messaging has been changed from silently returning empty row to
issuing
a NOTICE and returning an empty row.

7. Documentation has been to GetNamedDSA() and GetNamedDSHash(), warning
that
errors thrown from these functions can propagate to any transaction calling
the CFI function

8. Subtracted elapsed time ((MEMORY_STATS_MAX_TIMEOUT * 1000) -
elapsed_time) from
timeout passed to ConditionVariableTimedSleep so the total wait doesn't
exceed the intended
timeout in case of spurious wakeups.

9. Fixed a race condition bug by ensuring ConditionVariableSignal is called
before
dshash_release_lock

Additionally, I included couple of assertions, renamed variables and
functions to enhance
clarity and consistency with the existing style, and made improvements to
the documentation
and tests.

Please find attached updated and rebased patches.

Thank you,
Rahila Syed

On Tue, Feb 24, 2026 at 5:27 PM Rahila Syed <rahilasyed90(at)gmail(dot)com> wrote:

> Hi Daniel,
>
> Thank you for the review. All the changes suggested in the v52comments.diff
> are incorporated in the attached patches.
>
> +#Server should have thrown error
>> +$node->psql(
>> + 'postgres',
>> + qq(select pg_get_process_memory_contexts($pid, true);),
>> + stderr => \$psql_err);
>>
>> This test doesn't validate that the server actually errored does it?
>> (There is
>> no proposed fix in the attached.)
>>
>>
> This has been fixed by adding a check for the error returned by the above
> command.
> While at it, I also added another crash test to the file, This is similar
> to the existing
> test for a client backend crash, but in this scenario, it crashes the
> server process
> instead.
>
> Thank you,
> Rahila Syed
>

Attachment Content-Type Size
v54-0002-Test-module-to-test-memory-context-reporting-wit.patch application/octet-stream 10.4 KB
v54-0001-Add-function-to-report-memory-context-statistics.patch application/octet-stream 60.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-03-05 22:44:06 Re: generating function default settings from pg_proc.dat
Previous Message Sami Imseih 2026-03-05 22:25:57 Re: [BUG + PATCH] DSA pagemap out-of-bounds in make_new_segment odd-sized path