Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit767bc02

Browse files
committed
Allow DSM segments to be created as pinned
dsm_create and dsm_attach assumed that a current resource owner wasalways in place. Exploration with the API show that this isinconvenient: sometimes one must create a dummy resowner, create/attachthe DSM, only to pin the mapping later, which is wasteful. Changecreate/attach so that if there is no current resowner, the dsm iseffectively pinned right from the start.Discussion:https://postgr.es/m/20170324232710.32acsfsvjqfgc6ud@alvherre.pgsqlReviewed by Thomas Munro.
1 parent2c4debb commit767bc02

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(Sizesize,intflags)
@@ -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_handleh)
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp