Re: Attach to shared memory after fork()

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: 邱宇航(烛远) <yuhang(dot)qyh(at)alibaba-inc(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Attach to shared memory after fork()
Date: 2021-04-27 11:23:16
Message-ID: ffbb1ea8-0f4d-0b6c-a35e-8bb1f5e8b982@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 4/26/21 11:56 PM, 邱宇航(烛远) wrote:
> 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?
>

Windows has CreateProcess, which isn't available elsewhere. If you build
with EXEC_BACKEND on *nix it will fork() followed by exec(), the classic
Unix pattern. You can benchmark that but I doubt you will like the results.

This is one of the reasons for using a connection pooler like pgbouncer,
which can vastly reduce the number of new process creations Postgres has
to do.

Better shared memory management might be more promising.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2021-04-27 11:43:33 Re: Enhanced error message to include hint messages for redundant options error
Previous Message Aleksander Alekseev 2021-04-27 10:29:02 Re: Better sanity checking for message length words