[PATCH] Extend MXactCache lifetime from per-transaction to per-session
JoongHyuk Shin <sjh910805@gmail.com>
From: JoongHyuk Shin <sjh910805@gmail.com>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-20T09:38:52Z
Lists: pgsql-hackers
Attachments
- 0001-Extend-MXactCache-lifetime-from-per-transaction-to-p.patch (application/octet-stream) patch 0001
The MultiXact member cache (MXactCache) is allocated under TopTransactionContext and destroyed at every transaction end, so cross-transaction lookups of the same MultiXactId always fall through to SLRU. There is a FIXME comment in multixact.c (added in commit 0ac5ad5134f2) noting this is "plain wrong now that multixact's may contain update Xids." Since MultiXact member lists are immutable once created, cached entries stay valid regardless of transaction boundaries. The attached patch moves the cache to CacheMemoryContext so it persists for the backend session, and adds an oldestMultiXactId staleness check at lookup time to evict truncated entries. The oldestMultiXactId read is lockless; a stale read just keeps an entry slightly longer, which is harmless since the value only advances monotonically. This is consistent with the existing lockless MultiXactId read precedent in AtEOXact_MultiXact. For PostPrepare_MultiXact, explicit MemoryContextDelete is added since the context is no longer auto-destroyed with the transaction. I confirmed the improvement via pg_stat_slru: repeated GetMultiXactIdMembers calls across transactions go from SLRU hits every time to zero additional SLRU accesses after the first lookup. Patch attached.
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Improve concurrency of foreign key locking
- 0ac5ad5134f2 9.3.0 cited