Attach to shared memory after fork()

From: 邱宇航(烛远) <yuhang(dot)qyh(at)alibaba-inc(dot)com>
To: "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Attach to shared memory after fork()
Date: 2021-04-27 03:56:06
Message-ID: 4684bcc9-b653-4ccc-bbe7-450a602b405c.yuhang.qyh@alibaba-inc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fork is an expensive operation[1]. The major cost is the mm(VMA PTE...) copy.

ARM is especially weak on fork, which will invalid TLB entries one by one, and this is an expensive operation[2]. We could easily got 100% CPU on ARM machine. We also meet fork problem in x86, but not as serious as arm.

We can avoid this by enable hugepage(and 2MB doesn’t help us under arm, we got a huge shared buffer), but we still think it is a problem.

So I propose to remove shared buffers from postmaster and shmat them after fork. Not all of them, we still keep necessary shared memories in postmaster. Or maybe we just need to give up fork like under Windows?

Any good idea about it?

[1]. https://www.microsoft.com/en-us/research/publication/a-fork-in-the-road/
[2]. https://developer.arm.com/documentation/ddi0487/latest/
D5.10 TLB maintenance requirements and the TLB maintenance instructions:
Break-before-make sequence on changing from an old translation table entry to a new translation table entryrequires the following steps:
1. Replace the old translation table entry with an invalid entry, and execute a DSB instruction.
2. Invalidate the translation table entry with a broadcast TLB invalidation instruction, and execute a DSBinstruction to ensure the completion of that invalidation.
3. Write the new translation table entry, and execute a DSB instruction to ensure that the new entry is visible.

Regards.
Yuhang Qiu.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Nancarrow 2021-04-27 04:08:59 Re: [bug?] Missed parallel safety checks, and wrong parallel safety
Previous Message Ajin Cherian 2021-04-27 03:49:58 Re: logical replication empty transactions