public inbox for [email protected]  
help / color / mirror / Atom feed
From: Rui Zhao <[email protected]>
To: Aleksander Alekseev <[email protected]>
To: pgsql-hackers <[email protected]>
Cc: hlinnaka <[email protected]>
Cc: robertmhaas <[email protected]>
Cc: tgl <[email protected]>
Subject: Re:Detach shared memory in Postmaster child if not needed
Date: Tue, 30 Jul 2024 01:25:02 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAJ7c6TPU6CLsVgHs1yRtpDH+H79ghh3kHt0GH85EY2ZUjnxZ-w@mail.gmail.com>
References: <[email protected]>
	<CAJ7c6TPU6CLsVgHs1yRtpDH+H79ghh3kHt0GH85EY2ZUjnxZ-w@mail.gmail.com>

Thanks for your reply.
> Thanks for the patch. How do you estimate its performance impact?
In my patch, ony child processes that set
(child_process_kinds[child_type].shmem_attach == false)
will detach from shared memory.
Child processes with B_STANDALONE_BACKEND and B_INVALID don't call
postmaster_child_launch().
Therefore, currently, only the syslogger will be affected,
which should be harmless.
> Note the comments for postmaster_child_launch(). This function is
> exposed to the third-party code and guarantees to attach shared
> memory. I doubt that there is much third-party code in existence to
> break but you should change to comment.
Thank you for your reminder. My v2 patch will include the comments for
postmaster_child_launch().
--
Best regards,
Rui Zhao


Attachments:

  [application/octet-stream] 0001-Detach-shared-memory-in-Postmaster-child-if-not-needed-v2.patch (1.5K, ../[email protected]/3-0001-Detach-shared-memory-in-Postmaster-child-if-not-needed-v2.patch)
  download | inline diff:
From 96f869371e77e21047e1b842692872d3ebf445de Mon Sep 17 00:00:00 2001
From: "Rui Zhao" <[email protected]>
Date: Mon, 29 Jul 2024 16:55:04 +0800
Subject: [PATCH] Detach shared memory in Postmaster child if not needed

---
 src/backend/postmaster/launch_backend.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c
index 8d4589846a..0037772c4f 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -219,7 +219,8 @@ PostmasterChildName(BackendType child_type)
  * Start a new postmaster child process.
  *
  * The child process will be restored to roughly the same state whether
- * EXEC_BACKEND is used or not: it will be attached to shared memory, and fds
+ * EXEC_BACKEND is used or not: it will be attached to shared memory if
+ * shmem_attach is set to true and will be detached if it is not, and fds
  * and other resources that we've inherited from postmaster that are not
  * needed in a child process have been closed.
  *
@@ -249,6 +250,13 @@ postmaster_child_launch(BackendType child_type,
 		/* Detangle from postmaster */
 		InitPostmasterChild();
 
+		/* Detach from shared memory if it is not needed. */
+		if (!child_process_kinds[child_type].shmem_attach)
+		{
+			dsm_detach_all();
+			PGSharedMemoryDetach();
+		}
+
 		/*
 		 * Enter the Main function with TopMemoryContext.  The startup data is
 		 * allocated in PostmasterContext, so we cannot release it here yet.
-- 
2.39.3



view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Re:Detach shared memory in Postmaster child if not needed
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox