dsm_unpin_segment

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: dsm_unpin_segment
Date: 2016-08-08 22:15:24
Message-ID: CAEepm=0jvs=J6vR==N0qSswp5O+6487vCP1woYc7iLWKhD5NJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

DSM segments have a concept of 'pinning'. Normally, segments are
destroyed when they are no longer mapped by any backend, using a
reference counting scheme. If you call dsm_pin_segment(segment), that
is disabled so that the segment won't be destroyed until the cluster
is shut down. It works by incrementing the reference count an extra
time.

Please find attached a patch to add a corresponding operation
'dsm_unpin_segment'. This gives you a way to ask for the segment to
survive only until you decide to unpin it, at which point the usual
reference counting semantics apply again. It decrements the reference
count, undoing the effect of dsm_pin_segment and destroying the
segment if appropriate.

I think this is very useful for any core or extension code that wants
to store data in dynamic shared memory that survives even when no
backends are running, without having to commit to keeping the segment
forever. We have several projects in the 10.x pipeline which make use
of DSM segments, and we ran into the need for this finer grained
control of their lifetime.

Thanks to my colleague Amit Kapila for the Windows part, and also to
Robert Haas for internal feedback on an earlier version. The Windows
implementation has an extra quirk: Windows has its own reference
counting scheme that destroys mapped memory when there are no attached
processes, so pinning is implemented by sending a duplicate of the
handle into the Postmaster process to keep the segment alive. This
patch needs to close that handle when unpinning. Amazingly, that can
be done without any cooperation from the postmaster.

I'd be grateful for any feedback or thoughts, and will add this to the
commitfest.

--
Thomas Munro
http://www.enterprisedb.com

Attachment Content-Type Size
dsm-unpin-segment.patch application/octet-stream 9.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2016-08-08 22:56:09 Re: Slowness of extended protocol
Previous Message Bruce Momjian 2016-08-08 22:09:20 Re: Wait events monitoring future development