Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit81fe138

Browse files
committed
Fix memory leak in LogStandbySnapshot().
The array allocated by GetRunningTransactionLocks() needs to be pfree'dwhen we're done with it. Otherwise we leak some memory during eachcheckpoint, if wal_level = hot_standby. This manifests as memory bloatin the checkpointer process, or in bgwriter in versions before we madethe checkpointer separate.Reported and fixed by Naoya Anzai. Back-patch to 9.0 where the issuewas introduced.In passing, improve comments for GetRunningTransactionLocks(), and addan Assert that we didn't overrun the palloc'd array.
1 parentcc510d9 commit81fe138

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

‎src/backend/storage/ipc/standby.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -875,16 +875,11 @@ LogStandbySnapshot(void)
875875

876876
/*
877877
* Get details of any AccessExclusiveLocks being held at the moment.
878-
*
879-
* XXX GetRunningTransactionLocks() currently holds a lock on all
880-
* partitions though it is possible to further optimise the locking. By
881-
* reference counting locks and storing the value on the ProcArray entry
882-
* for each backend we can easily tell if any locks need recording without
883-
* trying to acquire the partition locks and scanning the lock table.
884878
*/
885879
locks=GetRunningTransactionLocks(&nlocks);
886880
if (nlocks>0)
887881
LogAccessExclusiveLocks(nlocks,locks);
882+
pfree(locks);
888883

889884
/*
890885
* Log details of all in-progress transactions. This should be the last

‎src/backend/storage/lmgr/lock.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,18 +3353,26 @@ GetLockStatusData(void)
33533353
}
33543354

33553355
/*
3356-
* Returns a list of currently held AccessExclusiveLocks, for use
3357-
* by GetRunningTransactionData().
3356+
* Returns a list of currently held AccessExclusiveLocks, for use by
3357+
* LogStandbySnapshot(). The result is a palloc'd array,
3358+
* with the number of elements returned into *nlocks.
3359+
*
3360+
* XXX This currently takes a lock on all partitions of the lock table,
3361+
* but it's possible to do better. By reference counting locks and storing
3362+
* the value in the ProcArray entry for each backend we could tell if any
3363+
* locks need recording without having to acquire the partition locks and
3364+
* scan the lock table. Whether that's worth the additional overhead
3365+
* is pretty dubious though.
33583366
*/
33593367
xl_standby_lock*
33603368
GetRunningTransactionLocks(int*nlocks)
33613369
{
3370+
xl_standby_lock*accessExclusiveLocks;
33623371
PROCLOCK*proclock;
33633372
HASH_SEQ_STATUSseqstat;
33643373
inti;
33653374
intindex;
33663375
intels;
3367-
xl_standby_lock*accessExclusiveLocks;
33683376

33693377
/*
33703378
* Acquire lock on the entire shared lock data structure.
@@ -3422,6 +3430,8 @@ GetRunningTransactionLocks(int *nlocks)
34223430
}
34233431
}
34243432

3433+
Assert(index <=els);
3434+
34253435
/*
34263436
* And release locks. We do this in reverse order for two reasons: (1)
34273437
* Anyone else who needs more than one of the locks will be trying to lock

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp