pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedmemory leak in GIN
3+ messages / 3 participants
[nested] [flat]
* memory leak in GIN
@ 2016-03-12 07:40 Jaime Casanova <jaime.casanova@2ndquadrant.com>
2016-03-13 18:54 ` Re: memory leak in GIN Jeff Janes <jeff.janes@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Jaime Casanova @ 2016-03-12 07:40 UTC (permalink / raw)
To: pgsql-hackers
Hi,
On the spanish list, Felipe de Jesús Molina Bravo, reported a few days
back that a query that worked well in 9.4 consume all memory in 9.5.
With the self contained test he provided us i reproduced the problem
in 9.5 and 9.6dev.
To test, execute:
pba.sql -- to create the tables and populate
query_crash.sql -- this will consume all your memory and crash your
server eventually
If you drop the GIN indexes, the problem disappear.
I used valgrind to try to hunt the memory leak, attached the resulting
log showing the backend that executed the query. And from the little a
could say from the stack trace valgrind showed, the problem is around
ginPostingListDecodeAllSegments() but i don't see any modifications
there.
--
Jaime Casanova www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments:
valgrind_pg_4812.log (text/x-log, 9.9K) download
--00:05:09:29.334 5092-- core : 2373976064/2373976064 max/curr mmap'd, 0/3 unsplit/split sb unmmap'd, 1696422792/1695489400 max/curr, 22854147/160881025864 totalloc-blocks/bytes, 22869778 searches 8 rzB
--00:05:09:29.334 5092-- dinfo : 27672576/23576576 max/curr mmap'd, 8/8 unsplit/split sb unmmap'd, 26394000/20727360 max/curr, 514277/ 110942880 totalloc-blocks/bytes, 514632 searches 8 rzB
--00:05:09:29.334 5092-- client : 2172690432/2172690432 max/curr mmap'd, 0/0 unsplit/split sb unmmap'd, 2147831952/2147831952 max/curr, 150558/3798707488 totalloc-blocks/bytes, 4050601 searches 24 rzB
--00:05:09:29.334 5092-- demangle: 0/ 0 max/curr mmap'd, 0/0 unsplit/split sb unmmap'd, 0/ 0 max/curr, 0/ 0 totalloc-blocks/bytes, 0 searches 8 rzB
--00:05:09:29.334 5092-- ttaux : 929792/ 765952 max/curr mmap'd, 4/0 unsplit/split sb unmmap'd, 874448/ 662288 max/curr, 3638/ 1778912 totalloc-blocks/bytes, 3629 searches 8 rzB
--00:05:09:29.334 5092-- translate: fast SP updates identified: 30,893 ( 85.2%)
--00:05:09:29.334 5092-- translate: generic_known SP updates identified: 3,145 ( 8.6%)
--00:05:09:29.334 5092-- translate: generic_unknown SP updates identified: 2,197 ( 6.0%)
--00:05:09:29.334 5092-- tt/tc: 1,251,268 tt lookups requiring 1,280,145 probes
--00:05:09:29.334 5092-- tt/tc: 1,226,430 fast-cache updates, 5 flushes
--00:05:09:29.334 5092-- transtab: new 26,656 (793,293 -> 17,688,151; ratio 222:10) [0 scs]
--00:05:09:29.334 5092-- transtab: dumped 0 (0 -> ??)
--00:05:09:29.334 5092-- transtab: discarded 12 (379 -> ??)
--00:05:09:29.334 5092-- scheduler: 1,919,085,595 event checks.
--00:05:09:29.334 5092-- scheduler: 752,068,113 indir transfers, 1,199,210 misses (1 in 627)
--00:05:09:29.334 5092-- scheduler: 19,190/25,950,146 major/minor sched events.
--00:05:09:29.334 5092-- sanity: 19190 cheap, 174 expensive checks.
--00:05:09:29.334 5092-- exectx: 49,157 lists, 36,845 contexts (avg 0 per list)
--00:05:09:29.334 5092-- exectx: 16,410,668 searches, 16,455,893 full compares (1,002 per 1000)
--00:05:09:29.334 5092-- exectx: 0 cmp2, 40 cmp4, 0 cmpAll
--00:05:09:29.334 5092-- errormgr: 4 supplist searches, 180 comparisons during search
--00:05:09:29.334 5092-- errormgr: 34 errlist searches, 40 comparisons during search
--00:05:09:29.334 5092-- memcheck: freelist: vol 19999746 length 3845
--00:05:09:29.334 5092-- memcheck: sanity checks: 19190 cheap, 175 expensive
--00:05:09:29.334 5092-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
--00:05:09:29.334 5092-- memcheck: auxmaps_L1: 0 searches, 0 cmps, ratio 0:10
--00:05:09:29.334 5092-- memcheck: auxmaps_L2: 0 searches, 0 nodes
--00:05:09:29.334 5092-- memcheck: SMs: n_issued = 33066 (529056k, 516M)
--00:05:09:29.334 5092-- memcheck: SMs: n_deissued = 11 (176k, 0M)
--00:05:09:29.334 5092-- memcheck: SMs: max_noaccess = 1048575 (16777200k, 16383M)
--00:05:09:29.334 5092-- memcheck: SMs: max_undefined = 127 (2032k, 1M)
--00:05:09:29.334 5092-- memcheck: SMs: max_defined = 2711 (43376k, 42M)
--00:05:09:29.334 5092-- memcheck: SMs: max_non_DSM = 33055 (528880k, 516M)
--00:05:09:29.334 5092-- memcheck: max sec V bit nodes: 1 (0k, 0M)
--00:05:09:29.334 5092-- memcheck: set_sec_vbits8 calls: 2 (new: 1, updates: 1)
--00:05:09:29.334 5092-- memcheck: max shadow mem size: 537120k, 524M
--00:05:09:29.334 5092-- ocacheL1: 57,451,348,720 refs 82,841,158 misses (21,064,639 lossage)
--00:05:09:29.334 5092-- ocacheL1: 56,905,854,383 at 0 462,653,179 at 1
--00:05:09:29.334 5092-- ocacheL1: 0 at 2+ 86,455,636 move-fwds
--00:05:09:29.334 5092-- ocacheL1: 100,663,296 sizeB 67,108,864 useful
--00:05:09:29.334 5092-- ocacheL2: 184,649,351 refs 82,837,014 misses
--00:05:09:29.334 5092-- ocacheL2: 21,060,607 max nodes 21,060,607 curr nodes
--00:05:09:29.334 5092-- niacache: 1,455,268,977 refs 7,114,361 misses
host stacktrace:
==00:05:09:29.335 5092== at 0x380A48EF: show_sched_status_wrk (m_libcassert.c:319)
==00:05:09:29.335 5092== by 0x380B129E: vgPlain_out_of_memory_NORETURN (m_mallocfree.c:792)
==00:05:09:29.335 5092== by 0x38074AEA: copy_for_writing (mc_main.c:303)
==00:05:09:29.335 5092== by 0x38079611: get_secmap_for_writing_low (mc_main.c:631)
==00:05:09:29.335 5092== by 0x38079611: get_secmap_for_writing (mc_main.c:666)
==00:05:09:29.335 5092== by 0x38079611: set_vabits8_for_aligned_word32 (mc_main.c:762)
==00:05:09:29.335 5092== by 0x38079611: vgMemCheck_copy_address_range_state (mc_main.c:1906)
==00:05:09:29.335 5092== by 0x38072D5D: vgMemCheck_realloc (mc_malloc_wrappers.c:580)
==00:05:09:29.335 5092== by 0x380F6A1C: do_client_request (scheduler.c:1848)
==00:05:09:29.335 5092== by 0x380F6A1C: vgPlain_scheduler (scheduler.c:1409)
==00:05:09:29.335 5092== by 0x38105B60: thread_wrapper (syswrap-linux.c:103)
==00:05:09:29.335 5092== by 0x38105B60: run_a_thread_NORETURN (syswrap-linux.c:156)
sched status:
running_tid=1
Thread 1: status = VgTs_Runnable
==00:05:09:29.335 5092== at 0x4C2AF2E: realloc (vg_replace_malloc.c:692)
==00:05:09:29.335 5092== by 0x94EADB: AllocSetRealloc (aset.c:1102)
==00:05:09:29.335 5092== by 0x9513BC: repalloc (mcxt.c:970)
==00:05:09:29.335 5092== by 0x496B0C: ginPostingListDecodeAllSegments (ginpostinglist.c:327)
==00:05:09:29.335 5092== by 0x481A92: GinDataLeafPageGetItems (gindatapage.c:153)
==00:05:09:29.335 5092== by 0x48CA5F: startScanEntry (ginget.c:400)
==00:05:09:29.335 5092== by 0x48CFDD: startScan (ginget.c:536)
==00:05:09:29.335 5092== by 0x48FD0B: gingetbitmap (ginget.c:1812)
==00:05:09:29.335 5092== by 0x92B981: FunctionCall2Coll (fmgr.c:1323)
==00:05:09:29.335 5092== by 0x4D2F44: index_getbitmap (indexam.c:651)
==00:05:09:29.335 5092== by 0x67EA25: MultiExecBitmapIndexScan (nodeBitmapIndexscan.c:89)
==00:05:09:29.335 5092== by 0x6676A5: MultiExecProcNode (execProcnode.c:570)
==00:05:09:29.335 5092== by 0x67D966: BitmapHeapNext (nodeBitmapHeapscan.c:104)
==00:05:09:29.335 5092== by 0x67235F: ExecScanFetch (execScan.c:95)
==00:05:09:29.335 5092== by 0x6723CE: ExecScan (execScan.c:145)
==00:05:09:29.335 5092== by 0x67E4CD: ExecBitmapHeapScan (nodeBitmapHeapscan.c:440)
==00:05:09:29.335 5092== by 0x6673EF: ExecProcNode (execProcnode.c:430)
==00:05:09:29.335 5092== by 0x68DF4A: ExecNestLoop (nodeNestloop.c:174)
==00:05:09:29.335 5092== by 0x6674AC: ExecProcNode (execProcnode.c:469)
==00:05:09:29.335 5092== by 0x692B94: CteScanNext (nodeCtescan.c:103)
==00:05:09:29.335 5092== by 0x67235F: ExecScanFetch (execScan.c:95)
==00:05:09:29.335 5092== by 0x6723CE: ExecScan (execScan.c:145)
==00:05:09:29.335 5092== by 0x692C2F: ExecCteScan (nodeCtescan.c:155)
==00:05:09:29.335 5092== by 0x667458: ExecProcNode (execProcnode.c:450)
==00:05:09:29.335 5092== by 0x664900: ExecutePlan (execMain.c:1549)
==00:05:09:29.335 5092== by 0x662A20: standard_ExecutorRun (execMain.c:337)
==00:05:09:29.335 5092== by 0x6628B3: ExecutorRun (execMain.c:285)
==00:05:09:29.335 5092== by 0x5F70A5: ExplainOnePlan (explain.c:503)
==00:05:09:29.335 5092== by 0x5F6D8E: ExplainOneQuery (explain.c:357)
==00:05:09:29.335 5092== by 0x5F6A2D: ExplainQuery (explain.c:245)
==00:05:09:29.335 5092== by 0x7E4DC2: standard_ProcessUtility (utility.c:658)
==00:05:09:29.335 5092== by 0x7E45E0: ProcessUtility (utility.c:334)
==00:05:09:29.335 5092== by 0x7E36F6: PortalRunUtility (pquery.c:1183)
==00:05:09:29.335 5092== by 0x7E3458: FillPortalStore (pquery.c:1057)
==00:05:09:29.335 5092== by 0x7E2D87: PortalRun (pquery.c:781)
==00:05:09:29.336 5092== by 0x7DD0BC: exec_simple_query (postgres.c:1104)
==00:05:09:29.336 5092== by 0x7E1106: PostgresMain (postgres.c:4030)
==00:05:09:29.336 5092== by 0x760A9A: BackendRun (postmaster.c:4239)
==00:05:09:29.336 5092== by 0x760202: BackendStartup (postmaster.c:3913)
==00:05:09:29.336 5092== by 0x75CA9E: ServerLoop (postmaster.c:1684)
==00:05:09:29.336 5092== by 0x75C0DA: PostmasterMain (postmaster.c:1292)
==00:05:09:29.336 5092== by 0x6B5288: main (main.c:223)
client stack range: [0xFFEFDE000 0xFFF000FFF] client SP: 0xFFEFFF110
valgrind stack top usage: 14568 of 1048576
==00:05:09:29.337 5092==
==00:05:09:29.337 5092== Valgrind's memory management: out of memory:
==00:05:09:29.337 5092== memcheck:allocate new SecMap's request for 16384 bytes failed.
==00:05:09:29.337 5092== 5431873536 bytes have already been allocated.
==00:05:09:29.337 5092== Valgrind cannot continue. Sorry.
==00:05:09:29.337 5092==
==00:05:09:29.337 5092== There are several possible reasons for this.
==00:05:09:29.337 5092== - You have some kind of memory limit in place. Look at the
==00:05:09:29.337 5092== output of 'ulimit -a'. Is there a limit on the size of
==00:05:09:29.337 5092== virtual memory or address space?
==00:05:09:29.337 5092== - You have run out of swap space.
==00:05:09:29.337 5092== - Valgrind has a bug. If you think this is the case or you are
==00:05:09:29.337 5092== not sure, please let us know and we'll try to fix it.
==00:05:09:29.337 5092== Please note that programs can take substantially more memory than
==00:05:09:29.337 5092== normal when running under Valgrind tools, eg. up to twice or
==00:05:09:29.337 5092== more, depending on the tool. On a 64-bit machine, Valgrind
==00:05:09:29.337 5092== should be able to make use of up 32GB memory. On a 32-bit
==00:05:09:29.337 5092== machine, Valgrind should be able to use all the memory available
==00:05:09:29.337 5092== to a single process, up to 4GB if that's how you have your
==00:05:09:29.337 5092== kernel configured. Most 32-bit Linux setups allow a maximum of
==00:05:09:29.337 5092== 3GB per process.
==00:05:09:29.337 5092==
==00:05:09:29.337 5092== Whatever the reason, Valgrind cannot continue. Sorry.
pba.sql.gz (application/x-gzip, 1.6M) download
query_crash.sql (application/sql, 407B) download
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: memory leak in GIN
2016-03-12 07:40 memory leak in GIN Jaime Casanova <jaime.casanova@2ndquadrant.com>
@ 2016-03-13 18:54 ` Jeff Janes <jeff.janes@gmail.com>
2016-03-13 20:24 ` Re: memory leak in GIN Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Janes @ 2016-03-13 18:54 UTC (permalink / raw)
To: Jaime Casanova <jaime.casanova@2ndquadrant.com>; +Cc: pgsql-hackers
On Fri, Mar 11, 2016 at 11:40 PM, Jaime Casanova
<jaime.casanova@2ndquadrant.com> wrote:
> Hi,
>
> On the spanish list, Felipe de Jesús Molina Bravo, reported a few days
> back that a query that worked well in 9.4 consume all memory in 9.5.
> With the self contained test he provided us i reproduced the problem
> in 9.5 and 9.6dev.
>
> To test, execute:
>
> pba.sql -- to create the tables and populate
> query_crash.sql -- this will consume all your memory and crash your
> server eventually
>
> If you drop the GIN indexes, the problem disappear.
>
> I used valgrind to try to hunt the memory leak, attached the resulting
> log showing the backend that executed the query. And from the little a
> could say from the stack trace valgrind showed, the problem is around
> ginPostingListDecodeAllSegments() but i don't see any modifications
> there.
I bisected it down to:
d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf is the first bad commit
commit d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Wed Feb 4 17:40:25 2015 +0200
Use a separate memory context for GIN scan keys.
It was getting tedious to track and release all the different things that
form a scan key. We were leaking at least the queryCategories array, and
possibly more, on a rescan. That was visible if a GIN index was used in a
nested loop join. This also protects from leaks in extractQuery method.
No backpatching, given the lack of complaints from the field. Maybe later,
after this has received more field testing.
I won't have a chance to do any further analysis for a while.
Cheers,
Jeff
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: memory leak in GIN
2016-03-12 07:40 memory leak in GIN Jaime Casanova <jaime.casanova@2ndquadrant.com>
2016-03-13 18:54 ` Re: memory leak in GIN Jeff Janes <jeff.janes@gmail.com>
@ 2016-03-13 20:24 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Tom Lane @ 2016-03-13 20:24 UTC (permalink / raw)
To: Jeff Janes <jeff.janes@gmail.com>; +Cc: Jaime Casanova <jaime.casanova@2ndquadrant.com>; pgsql-hackers; Heikki Linnakangas <hlinnaka@iki.fi>
Jeff Janes <jeff.janes@gmail.com> writes:
> I bisected it down to:
> d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf is the first bad commit
> commit d88976cfa1302e8dccdcbfe55e9e29faee8c0cdf
> Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
> Date: Wed Feb 4 17:40:25 2015 +0200
> Use a separate memory context for GIN scan keys.
Yeah, I had come to the same conclusion. The leak comes from removing
this bit from ginFreeScanKeys():
- if (entry->list)
- pfree(entry->list);
Heikki evidently supposed that entry->list would be allocated in
the so->keyCtx, but as things stand, it is not: it gets allocated
in the query-lifespan context, so this change causes a leak of
potentially several kB per ginrescan cycle. And the test query
does about 120000 of those.
I think it would likely be a good thing to fix things so that that
assumption actually holds, but I'm not familiar enough with this code
to decide what's the best way to do that. (Basically, the question is
"how much of startScanEntry() ought to run with keyCtx as current memory
context?") As a short-term fix I plan to reinstall the above-cited pfree.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2016-03-13 20:24 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-12 07:40 memory leak in GIN Jaime Casanova <jaime.casanova@2ndquadrant.com>
2016-03-13 18:54 ` Jeff Janes <jeff.janes@gmail.com>
2016-03-13 20:24 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox