Re: Stale hash entries when reusing an auxiliary resource owner

From: Rahila Syed <rahilasyed90(at)gmail(dot)com>
To: Jingtang Zhang <mrdrivingduck(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, pgsql-hackers mailing list <pgsql-hackers(at)lists(dot)postgresql(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Stale hash entries when reusing an auxiliary resource owner
Date: 2026-11-26 05:57:33
Message-ID: CAH2L28vNm1OqCJRnOMs=G5u6XmbqQgTCpiEKAhvHqNYWx2DUcQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thank you for running the benchmark and updating the patch.
Please find my comments inline below.

>
> All microbenchmark cases below use one resource kind. Columns are:
>
> Timing: Release = all three release phases;
> Reset = Reset alone after release has completed.
> Live/peak: resource count before release / peak registered count.
> For Reset, the peak is established before timing.
> Baseline: unpatched.
> A: clear hash entries during sorting and bulk release.
> B: clear the retained hash table in Reset.

I think the most interesting cases are when the live count or the
number of resources held at a given time exceed 32.
That is when the hash table, and so the v4 patch's code, gets used.

>
> | Timing | Live/peak | Baseline | A | B |
> +----------+-------------+-----------+-----------+-----------+
> | Release | 0/0 | 0.026 | 0.029 | 0.027 |
> | Release | 16/16 | 0.108 | 0.116 | 0.107 |
> | Release | 32/32 | 0.202 | 0.207 | 0.198 |
> | Release | 33/33 | 0.282 | 0.277 | 0.268 |
> | Release | 64/64 | 0.463 | 0.466 | 0.456 |
> | Release | 128/128 | 0.954 | 0.977 | 0.939 |
> | Release | 1024/1024 | 11.617 | 11.341 | 11.825 |
> | Release | 16384/16384 | 239.506 | 256.352 | 237.873 |
> | Release | 0/1024 | 0.040 | 0.044 | 0.038 |
> | Release | 16/1024 | 2.051 | 1.790 | 1.854 |
>
> For Release, the smaller cases tested show small absolute differences.
> The difference is more apparent with 16,384 resources.
>
Clearing entries on release costs about 7% more at ~16k live resources.
That case could be rare: in a scale-100 pgbench run, no owner held
more than 150 resources at once, so I don't expect a noticeable TPS
regression.

> To check whether A's extra release work affects SQL throughput,
> I also ran pgbench -S -M prepared -c 1 -j 1 at scale 1. TPS values
> below are medians; differences compare those medians with baseline.
>
> +----------+------------+------------+--------+
> | Run | Baseline | A | A diff |
> +----------+------------+------------+--------+
> | First | 43736.94 | 43035.63 | -1.60% |
> | Repeat | 43340.50 | 43574.31 | +0.54% |
> +----------+------------+------------+--------+
>
Nice. Additionally, to rule out any TPS regression it would be nice to
repeat this with a higher
scale and with a read-write workload.

>
> Given these results, I prefer clearing during sorting and bulk
> release. It avoids clearing the full retained table in Reset, and
> these pgbench runs did not show a consistent throughput regression.
> Attached with v4.

+1 for clearing while sorting and release.

> * If 'sorted' is set, the contents are no longer hashed, but sorted by
>- * release priority. The first 'nhash' elements are occupied, the rest
>- * are empty.
>+ * release priority. The first 'nhash' elements contain the remaining
>+ * resources; entries after that are not used until the owner is reset or
>+ * deleted.

This change no longer holds with the recent patch. The older comment was
more appropriate given the latest changes.

>+ Assert(owner->nlocks == 0 || owner->nlocks == MAX_RESOWNER_LOCKS + 1);
>+ Assert(dlist_is_empty(&owner->aio_handles));
>+
>+ for (child = owner->firstchild; child != NULL; child = child->nextchild)
>+ ResourceOwnerReset(child);
>+
>+ owner->nlocks = 0;

A comment explaining why it is safe to set nlocks to 0 even when the
old value is
MAX_RESOWNER_LOCKS + 1 , would be useful.
Do we also need to reset the owner->locks along with it?

I suggest backpatching only the changes that clear the unused entries,
through v17 and keeping the changes to add the new API ResourceOwnerReset()
for master only.

Thank you,
Rahila Syed

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayush Tiwari 2026-11-26 06:21:23 [PATCH] Share WAL summary filtering logic
Previous Message shveta malik 2026-11-26 05:54:09 Re: DOC: Minor updates for logical replication conflicts