mirror of
https://github.com/postgres/postgres.git
synced 2025-10-29 22:49:41 +03:00
Refactor GetLockStatusData() to skip backends/groups without fast-path locks.
Previously, GetLockStatusData() checked all slots for every backend to gather fast-path lock data, which could be inefficient. This commit refactors it by skipping backends with PID=0 (since they don't hold fast-path locks) and skipping groups with no registered fast-path locks, improving efficiency. This refactoring is particularly beneficial, for example when max_connections and max_locks_per_transaction are set high, as it reduces unnecessary checks across numerous slots. Author: Fujii Masao Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/a0a00c44-31e9-4c67-9846-fb9636213ac9@oss.nttdata.com
This commit is contained in:
@@ -3731,16 +3731,26 @@ GetLockStatusData(void)
|
|||||||
for (i = 0; i < ProcGlobal->allProcCount; ++i)
|
for (i = 0; i < ProcGlobal->allProcCount; ++i)
|
||||||
{
|
{
|
||||||
PGPROC *proc = &ProcGlobal->allProcs[i];
|
PGPROC *proc = &ProcGlobal->allProcs[i];
|
||||||
uint32 f;
|
|
||||||
|
/* Skip backends with pid=0, as they don't hold fast-path locks */
|
||||||
|
if (proc->pid == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
LWLockAcquire(&proc->fpInfoLock, LW_SHARED);
|
LWLockAcquire(&proc->fpInfoLock, LW_SHARED);
|
||||||
|
|
||||||
for (f = 0; f < FP_LOCK_SLOTS_PER_BACKEND; ++f)
|
for (uint32 g = 0; g < FastPathLockGroupsPerBackend; g++)
|
||||||
|
{
|
||||||
|
/* Skip groups without registered fast-path locks */
|
||||||
|
if (proc->fpLockBits[g] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int j = 0; j < FP_LOCK_SLOTS_PER_GROUP; j++)
|
||||||
{
|
{
|
||||||
LockInstanceData *instance;
|
LockInstanceData *instance;
|
||||||
|
uint32 f = FAST_PATH_SLOT(g, j);
|
||||||
uint32 lockbits = FAST_PATH_GET_BITS(proc, f);
|
uint32 lockbits = FAST_PATH_GET_BITS(proc, f);
|
||||||
|
|
||||||
/* Skip unallocated slots. */
|
/* Skip unallocated slots */
|
||||||
if (!lockbits)
|
if (!lockbits)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -3770,6 +3780,7 @@ GetLockStatusData(void)
|
|||||||
|
|
||||||
el++;
|
el++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (proc->fpVXIDLock)
|
if (proc->fpVXIDLock)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user