Some shared memory chunks are allocated even if related processes won't start - Mailing list pgsql-hackers

From Hayato Kuroda (Fujitsu)
Subject Some shared memory chunks are allocated even if related processes won't start
Date
Msg-id TYCPR01MB12077BFDFBC142086D424FDFEF5232@TYCPR01MB12077.jpnprd01.prod.outlook.com
Whole thread Raw
Responses Re: Some shared memory chunks are allocated even if related processes won't start
Re: Some shared memory chunks are allocated even if related processes won't start
List pgsql-hackers
Dear hackers,

While reading codes, I found that ApplyLauncherShmemInit() and AutoVacuumShmemInit()
are always called even if they would not be launched.
It may be able to reduce the start time to avoid the unnecessary allocation.
However, I know this improvement would be quite small because the allocated chunks are
quite small.

Anyway, there are several ways to fix:

1)
Skip calling ShmemInitStruct() if the related process would not be launched.
I think this approach is the easiest way. E.g.,

```
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -962,6 +962,9 @@ ApplyLauncherShmemInit(void)
 {
     bool        found;

+    if (max_logical_replication_workers == 0 || IsBinaryUpgrade)
+        return;
+
```

2)
Dynamically allocate the shared memory. This was allowed by recent commit [1].
I made a small PoC only for logical launcher to show what I meant. PSA diff file.
Since some processes (backend, apply worker, parallel apply worker, and tablesync worker)
refers the chunk, codes for attachment must be added on the several places.

If you agree it should be fixed, I will create a patch. Thought?

[1]: https://github.com/postgres/postgres/commit/8b2bcf3f287c79eaebf724cba57e5ff664b01e06

Best Regards,
Hayato Kuroda
FUJITSU LIMITED
https://www.fujitsu.com/


Attachment

pgsql-hackers by date:

Previous
From: Amul Sul
Date:
Subject: Re: PostgreSQL Contributors Updates
Next
From: Michael Paquier
Date:
Subject: Re: Injection points: some tools to wait and wake