Alvaro Herrera wrote: > Per > https://postgr.es/m/CAEepm=11ma_Z1HoPxPcSCANnh5ykHORa=hca1u1v1+5s_jw...@mail.gmail.com > it seems that the dsm.c API is a bit inconvenient right now. I proposed > in the first patch in that thread to change the API so that a segment is > marked as "pinned" if created with no ResourceOwner set as current; > which is essentially the same as creating a fake one, then marking the > segment as pinned. > > Thomas agrees with me, so I propose this patch as preparatory work for > the autovacuum/BRIN stuff I'm interested in.
Here's the proposed patch. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>From ded46066cb634f7714706c8d347af2acf267da17 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera <alvhe...@alvh.no-ip.org> Date: Fri, 24 Mar 2017 19:27:22 -0300 Subject: [PATCH] Change dsm.c API so that mappings are pinned if created with no resowner --- src/backend/storage/ipc/dsm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c index 54378bc..061a457 100644 --- a/src/backend/storage/ipc/dsm.c +++ b/src/backend/storage/ipc/dsm.c @@ -453,6 +453,11 @@ dsm_set_control_handle(dsm_handle h) /* * Create a new dynamic shared memory segment. + * + * If there is a CurrentResourceOwner, the new segment is born unpinned and the + * resource owner is in charge of destroying it (and will be blamed if it + * doesn't). If there's no current resource owner, then the segment starts in + * the pinned state, so it'll stay alive until explicitely unpinned. */ dsm_segment * dsm_create(Size size, int flags) @@ -1095,7 +1100,8 @@ dsm_create_descriptor(void) { dsm_segment *seg; - ResourceOwnerEnlargeDSMs(CurrentResourceOwner); + if (CurrentResourceOwner) + ResourceOwnerEnlargeDSMs(CurrentResourceOwner); seg = MemoryContextAlloc(TopMemoryContext, sizeof(dsm_segment)); dlist_push_head(&dsm_segment_list, &seg->node); @@ -1106,8 +1112,11 @@ dsm_create_descriptor(void) seg->mapped_address = NULL; seg->mapped_size = 0; - seg->resowner = CurrentResourceOwner; - ResourceOwnerRememberDSM(CurrentResourceOwner, seg); + if (CurrentResourceOwner) + { + seg->resowner = CurrentResourceOwner; + ResourceOwnerRememberDSM(CurrentResourceOwner, seg); + } slist_init(&seg->on_detach); -- 2.1.4
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers