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
Description: Binary data
-- Sent via pgsql-hackers mailing list (email@example.com) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers