I looked at the patch set and found it quite useful. The first 7 patches are just refactoring and may be committed separately if needed. There were minor problems: patch #5 don't want to apply clearly and the #8 is complained about partitionLock is unused if we build without asserts. So, I add a PG_USED_FOR_ASSERTS_ONLY to solve the last issue.
Again, overall patch looks good and seems useful to me. Here is the rebased v5 version based on Heikki's patch set above. -- Best regards, Maxim Orlov.
v5-0004-Move-TRACE-calls-into-WaitOnLock.patch
Description: Binary data
v5-0001-Remove-LOCK_PRINT-call-that-could-point-to-garbag.patch
Description: Binary data
v5-0003-Set-MyProc-heldLocks-in-ProcSleep.patch
Description: Binary data
v5-0005-Remove-redundant-lockAwaited-global-variable.patch
Description: Binary data
v5-0002-Fix-comment-in-LockReleaseAll-on-when-locallock-n.patch
Description: Binary data
v5-0007-Release-partition-lock-a-little-earlier.patch
Description: Binary data
v5-0006-Update-local-lock-table-in-ProcSleep-s-caller.patch
Description: Binary data
v5-0008-Split-ProcSleep-function-into-JoinWaitQueue-and-P.patch
Description: Binary data