From: Jaime Casanova <jaime.casanova@2ndquadrant.com>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: memory leak in GIN
Date: Sat, 12 Mar 2016 02:40:53 -0500
Message-ID: <CAJGNTeMR1ndMU2Thpr8GPDUfiHTV7idELJRFusA5UXUGY1y-eA@mail.gmail.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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-hackersAttachments: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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: jaime.casanova@2ndquadrant.com
Subject: Re: memory leak in GIN
In-Reply-To: <CAJGNTeMR1ndMU2Thpr8GPDUfiHTV7idELJRFusA5UXUGY1y-eA@mail.gmail.com>
References: <CAJGNTeMR1ndMU2Thpr8GPDUfiHTV7idELJRFusA5UXUGY1y-eA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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