making bgworkers without shmem access actually not have shmem access

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: making bgworkers without shmem access actually not have shmem access
Date: 2014-05-07 18:37:54
Message-ID: CA+Tgmob1Ok2erRfVB-8Zj+nW5gFzBPrY5_dCk8a9xB2CbS-w8A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I've complained about this problem a few times before: there's nothing
to prevent a background worker which doesn't request shared memory
access from calling InitProcess() and then accessing shared memory
anyway. The attached patch is a first crack at fixing it.
Unfortunately, there's still a window between when we fork() and when
we detach shared memory, but that's also true for processes like
syslogger, whose death is nevertheless does not cause a
crash-and-restart. Also unfortunately, in the EXEC_BACKEND case, we
actually have to attach shared memory first, to get our background
worker entry details. This is undesirable, but I'm not sure there's
any good way to fix it at all, and certainly not in time for 9.4.
Hopefully, the window when shared memory is attached with this patch
is short enough to make things relatively safe.

At a minimum, it's got to be better than the status quo, where shared
memory is accessible throughout the entire lifetime of
non-shmem-access background workers.

Attached is also a new background worker called say_hello which I used
for testing this patch. That's obviously not for commit.

Comments?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Attachment Content-Type Size
bgworker-detach-shmem.patch text/x-patch 3.0 KB
say-hello.patch text/x-patch 4.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-05-07 18:38:32 Re: proposal: Set effective_cache_size to greater of .conf value, shared_buffers
Previous Message Merlin Moncure 2014-05-07 18:32:41 Re: proposal: Set effective_cache_size to greater of .conf value, shared_buffers