Skip to content

Commit 767bc02

Browse files
committed
Allow DSM segments to be created as pinned
dsm_create and dsm_attach assumed that a current resource owner was always in place. Exploration with the API show that this is inconvenient: sometimes one must create a dummy resowner, create/attach the DSM, only to pin the mapping later, which is wasteful. Change create/attach so that if there is no current resowner, the dsm is effectively pinned right from the start. Discussion: https://postgr.es/m/20170324232710.32acsfsvjqfgc6ud@alvherre.pgsql Reviewed by Thomas Munro.
1 parent 2c4debb commit 767bc02

File tree

1 file changed

+16
-2
lines changed
  • src/backend/storage/ipc

1 file changed

+16
-2
lines changed

src/backend/storage/ipc/dsm.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,13 @@ dsm_set_control_handle(dsm_handle h)
453453

454454
/*
455455
* Create a new dynamic shared memory segment.
456+
*
457+
* If there is a non-NULL CurrentResourceOwner, the new segment is associated
458+
* with it and must be detached before the resource owner releases, or a
459+
* warning will be logged. If CurrentResourceOwner is NULL, the segment
460+
* remains attached until explicitely detached or the session ends.
461+
* Creating with a NULL CurrentResourceOwner is equivalent to creating
462+
* with a non-NULL CurrentResourceOwner and then calling dsm_pin_mapping.
456463
*/
457464
dsm_segment *
458465
dsm_create(Size size, int flags)
@@ -544,6 +551,11 @@ dsm_create(Size size, int flags)
544551
* This can happen if we're asked to attach the segment, but then everyone
545552
* else detaches it (causing it to be destroyed) before we get around to
546553
* attaching it.
554+
*
555+
* If there is a non-NULL CurrentResourceOwner, the attached segment is
556+
* associated with it and must be detached before the resource owner releases,
557+
* or a warning will be logged. Otherwise the segment remains attached until
558+
* explicitely detached or the session ends. See the note atop dsm_create().
547559
*/
548560
dsm_segment *
549561
dsm_attach(dsm_handle h)
@@ -1095,7 +1107,8 @@ dsm_create_descriptor(void)
10951107
{
10961108
dsm_segment *seg;
10971109

1098-
ResourceOwnerEnlargeDSMs(CurrentResourceOwner);
1110+
if (CurrentResourceOwner)
1111+
ResourceOwnerEnlargeDSMs(CurrentResourceOwner);
10991112

11001113
seg = MemoryContextAlloc(TopMemoryContext, sizeof(dsm_segment));
11011114
dlist_push_head(&dsm_segment_list, &seg->node);
@@ -1107,7 +1120,8 @@ dsm_create_descriptor(void)
11071120
seg->mapped_size = 0;
11081121

11091122
seg->resowner = CurrentResourceOwner;
1110-
ResourceOwnerRememberDSM(CurrentResourceOwner, seg);
1123+
if (CurrentResourceOwner)
1124+
ResourceOwnerRememberDSM(CurrentResourceOwner, seg);
11111125

11121126
slist_init(&seg->on_detach);
11131127

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy