Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UjvrP-0005TN-56 for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Jun 2013 18:21:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UjvrO-0000oG-L3 for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Jun 2013 18:21:30 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UjvrN-0000oB-Uw for pgsql-bugs@postgresql.org; Tue, 04 Jun 2013 18:21:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UjvrL-0001BK-Cx for pgsql-bugs@postgresql.org; Tue, 04 Jun 2013 18:21:29 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r54ILL2N029610; Tue, 4 Jun 2013 14:21:21 -0400 (EDT) From: Tom Lane To: Stephen Frost cc: Andres Freund , Heikki Linnakangas , Naoya Anzai , pgsql-bugs@postgresql.org, Akio Iwaasa Subject: Re: Memory-leak in BackgroundWriter(and Checkpointer) In-reply-to: <20130604180525.GK5871@tamriel.snowman.net> References: <20130604122736.GH5871@tamriel.snowman.net> <51ADEA34.4080704@vmware.com> <20130604132758.GC2854@alap2.anarazel.de> <20130604134927.GI5871@tamriel.snowman.net> <28228.1370368383@sss.pgh.pa.us> <20130604180525.GK5871@tamriel.snowman.net> Comments: In-reply-to Stephen Frost message dated "Tue, 04 Jun 2013 14:05:25 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <29603.1370370068.0@sss.pgh.pa.us> Date: Tue, 04 Jun 2013 14:21:20 -0400 Message-ID: <29609.1370370080@sss.pgh.pa.us> X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29603.1370370068.1@sss.pgh.pa.us> Stephen Frost writes: > * Tom Lane (tgl@sss.pgh.pa.us) wrote: >> I think the proposed fix is fine code-wise; the real problem here is >> crummy commenting. GetRunningTransactionLocks isn't documented as >> returning a palloc'd array, and why the heck do we have a long comment >> about its implementation in LogStandbySnapshot? > Certainly good questions and better comments would have helped here. I > can go back and rework the patch either way. I'm already working on back-patching the attached. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-patch; charset="us-ascii" Content-ID: <29603.1370370068.2@sss.pgh.pa.us> Content-Description: leak.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/st= andby.c index 615278b8ca2adf3057e5f21057c3cedfc66480aa..c704412366d5bc4b6512e9ab673= 855c46f7d993f 100644 *** a/src/backend/storage/ipc/standby.c --- b/src/backend/storage/ipc/standby.c *************** LogStandbySnapshot(void) *** 865,880 **** =20=20 /* * Get details of any AccessExclusiveLocks being held at the moment. - * - * XXX GetRunningTransactionLocks() currently holds a lock on all - * partitions though it is possible to further optimise the locking. By - * reference counting locks and storing the value on the ProcArray entry - * for each backend we can easily tell if any locks need recording witho= ut - * trying to acquire the partition locks and scanning the lock table. */ locks =3D GetRunningTransactionLocks(&nlocks); if (nlocks > 0) LogAccessExclusiveLocks(nlocks, locks); =20=20 /* * Log details of all in-progress transactions. This should be the last --- 865,875 ---- =20=20 /* * Get details of any AccessExclusiveLocks being held at the moment. */ locks =3D GetRunningTransactionLocks(&nlocks); if (nlocks > 0) LogAccessExclusiveLocks(nlocks, locks); + pfree(locks); =20=20 /* * Log details of all in-progress transactions. This should be the last diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/loc= k.c index 8cd871f4b40d7bfc8b0aaa7650241d5865c79ffe..273c72230274b46ba6a46bb8b29= 5ef5375aaa36d 100644 *** a/src/backend/storage/lmgr/lock.c --- b/src/backend/storage/lmgr/lock.c *************** GetLockStatusData(void) *** 3398,3415 **** } =20=20 /* ! * Returns a list of currently held AccessExclusiveLocks, for use ! * by GetRunningTransactionData(). */ xl_standby_lock * GetRunningTransactionLocks(int *nlocks) { PROCLOCK *proclock; HASH_SEQ_STATUS seqstat; int i; int index; int els; - xl_standby_lock *accessExclusiveLocks; =20=20 /* * Acquire lock on the entire shared lock data structure. --- 3398,3423 ---- } =20=20 /* ! * Returns a list of currently held AccessExclusiveLocks, for use by ! * LogStandbySnapshot(). The result is a palloc'd array, ! * with the number of elements returned into *nlocks. ! * ! * XXX This currently takes a lock on all partitions of the lock table, ! * but it's possible to do better. By reference counting locks and stori= ng ! * the value in the ProcArray entry for each backend we could tell if any ! * locks need recording without having to acquire the partition locks and ! * scan the lock table. Whether that's worth the additional overhead ! * is pretty dubious though. */ xl_standby_lock * GetRunningTransactionLocks(int *nlocks) { + xl_standby_lock *accessExclusiveLocks; PROCLOCK *proclock; HASH_SEQ_STATUS seqstat; int i; int index; int els; =20=20 /* * Acquire lock on the entire shared lock data structure. *************** GetRunningTransactionLocks(int *nlocks) *** 3467,3472 **** --- 3475,3482 ---- } } =20=20 + Assert(index <=3D els); +=20 /* * And release locks. We do this in reverse order for two reasons: (1) * Anyone else who needs more than one of the locks will be trying to lo= ck ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--