GiST does palloc's in critical section

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: GiST does palloc's in critical section
Date: 2014-04-02 08:22:03
Message-ID: 533BC8AB.6010401@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I just noticed that the GiST functions that write WAL records,
gistXLogSplit and gistXLogUpdate, call palloc while in a critical
section. That's bad because a palloc can fail if you run out of memory,
and if that happens in a critical section, you get a PANIC. It's a small
risk in practice, but we ought to fix it anyway.

The functions went through some refactoring in 9.1, but earlier versions
had the same issue.

Most XLogInsert callers allocate all the memory they need in stack, as
local variables. That's how we should fix these too. We'll need some
upper limit on the amount of memory needed, and use that to size the
variables.

gistXLogSplit needs two XLogRecData for each page in the split. There is
no theoretical limit for that, although in practice more than 3-4 would
be extraordinary. Currently, it's only limited by the number of LWLocks
that can be held simultaneously. Let's add an explicit limit on that.

So, attached is a patch to fix this. This should apply to 9.1 - master
easily, but 9.0 and 8.4 will need some adjustment.

- Heikki

Attachment Content-Type Size
fix-gist-palloc-in-crit-section.patch text/x-diff 4.8 KB

Browse pgsql-bugs by date

  From Date Subject
Next Message fburgess 2014-04-02 18:07:49 Configuring Standby Server in PostgreSQL 9.3.3
Previous Message Michael Paquier 2014-04-02 03:54:52 Re: [BUGS] Timezone error when casting. Maybe daylight saving