Re: Excessive CPU usage in StandbyReleaseLocks()

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Simon Riggs <simon(at)2ndquadrant(dot)com>, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>
Subject: Re: Excessive CPU usage in StandbyReleaseLocks()
Date: 2018-06-20 10:54:27
Message-ID: CAEepm=2rKHLRYF+ZUb-3oY8JnkO0UPBpjixz5qeyisvHGeqy7g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Adding Simon and David R.

On Wed, Jun 20, 2018 at 5:44 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Hence, I have a modest proposal: use elog(LOG) followed by Assert(false),
> so that debug builds report such problems loudly but production builds
> do not. We've done that before, see e.g. load_relcache_init_file around
> relcache.c:5718.

Done. (This elog(LOG) isn't new BTW, I merely moved it.)

On Tue, Jun 19, 2018 at 6:30 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> On 2018-06-19 17:43:42 +1200, Thomas Munro wrote:
>> + RecoveryLockLists = hash_create("RecoveryLockLists",
>> + 4096,
>> + &hash_ctl,
>
> Isn't that initial size needlessly big?

Changed to 64.

>> - RecoveryLockList = lappend(RecoveryLockList, newlock);
>> + entry->locks = lappend(entry->locks, newlock);
>
> Gotta be careful with lappend et al - it's really easy to leak memory
> without explicit context usage. Have you checked that we don't here?

The list and contents are explicitly freed when xids end and the locks
are released (because xid committed/aborted, or older than known
oldest running transaction, or we release all on promotion). The
existing code seems to assume that TopMemoryContext is current (or
some context that'll last all the way until our promotion), which
seems OK to me. TopMemoryContext is inherited from PostgresMain() and
any redo handler that changes it without restoring it would be buggy,
and errors are FATAL here.

I had missed one small thing though: I should call hash_destroy() in
ShutdownRecoveryTransactionEnvironment() to free the hash table itself
on promotion. Fixed.

Why does StandbyReleaseLocks() handle an invalid xid by removing all
locks (if (!TransactionIdIsValid(xid) || lock->xid == xid)) in master?

V2 attached.

--
Thomas Munro
http://www.enterprisedb.com

Attachment Content-Type Size
0001-Move-RecoveryLockList-into-a-hash-table-v2.patch application/octet-stream 9.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2018-06-20 12:03:45 Re: documentation is now XML
Previous Message Alexander Korotkov 2018-06-20 09:00:31 Re: [HACKERS] GUC for cleanup indexes threshold.