Re: Sharing DSA pointer between parallel workers after they've been created

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: "Ma, Marcus" <marcjma(at)amazon(dot)com>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Sharing DSA pointer between parallel workers after they've been created
Date: 2022-06-10 16:11:03
Message-ID: CA+TgmobwTdN_NJc_AMvgHe7EU6seRVVo-qDu7HdHu+0TQSiC6Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 9, 2022 at 2:36 PM Ma, Marcus <marcjma(at)amazon(dot)com> wrote:
> I’m currently working on a parallelization optimization of the Sequential Scan in the codebase, and I need to share information between the workers as they scan a relation. I’ve done a decent amount of testing, and I know that the parallel workers all share the same dsa_area in the plan state. However, by the time I’m actually able to allocate a dsa_pointer via dsa_allocate0(), the separate parallel workers have already been created so I can’t actually share the pointer with them. Since the workers all share the same dsa_area, all I need to do is be able to share the single dsa_pointer with them but so far I’ve been out of luck. Any advice?

Generally, the way you share information with a parallel worker is by
making an entry in a DSM TOC using a well-known value as the key, and
then the parallel worker reads that entry. That entry might contain
things like a dsa_pointer, in which case you can hang any amount of
additional stuff off of that storage. In the case of the executor, the
well-known value used as the key the plan_node_id. See
ExecSeqScanInitializeDSM and ExecSeqScanInitializeWorker for an
example of how to share data that is known before starting the workers
advance. In your case you'd need to adapt that technique. But notice
that all we're doing here is making a TOC entry for a
ParallelTableScanDesc. The contents of that struct can be anything.
For instance, it could contain a dsa_pointer and an LWLock protecting
the pointer and a ConditionVariable to wait for the pointer to change.

Another approach would be to set up a shm_mq and transmit the
dsa_pointer through it as a message.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2022-06-10 16:13:34 Re: better page-level checksums
Previous Message Stephen Frost 2022-06-10 16:08:22 Re: better page-level checksums