Memory leak in GIN index build - Mailing list pgsql-hackers

From Julien Rouhaud
Subject Memory leak in GIN index build
Date
Msg-id 571276DD.5050303@dalibo.com
Whole thread Raw
Responses Re: Memory leak in GIN index build  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hello,

Another colleague provided a report of memory leak, during a GIN index
build. Test case to reproduce the attached (need to create a gin index
on the val column after loading). Sorry, it generates a 24GB table, and
memory start leaking with a 1GB maintenance_work_mem after reaching 8 or
9 times the m_w_m setting, leading to ~ 9GB used in Gin build temporary
context.


After some digging, the leak comes from walbufbegin palloc in
registerLeafRecompressWALData().

IIUC, walbufbegin isn't pfree-d and can't be before XLogInsert() is
called, which happens in ginPlaceToPage().

I don't see a simple way to fix that. My first idea would be to change
GinBtreeData's placeToPage (and all other needed) functions signature to
pass a pointer to pfree in ginPlaceToPage() if needed, but it doesn't
really seem appealing. In any case, I'd be happy to work on a patch if
needed.

Also, in dataPlaceToPageLeaf() and ginVacuumPostingTreeLeaf(), shouldn't
the START_CRIT_SECTION() calls be placed before the xlog code?

Regards.

--
Julien Rouhaud
http://dalibo.com - http://dalibo.org

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Spinlocks and semaphores in 9.2 and 9.3
Next
From: Tom Lane
Date:
Subject: Re: Memory leak in GIN index build