ShmemIndexLock rewrite

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-patches(at)postgreSQL(dot)org
Subject: ShmemIndexLock rewrite
Date: 2006-01-03 02:47:57
Message-ID: 7111.1136256477@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Here is a proposed patch pursuant to the idea of turning ShmemIndexLock
into an LWLock instead of a spinlock, as discussed last week. I remember
now that we tried to do that before, and found out it was a pain in the
neck :-(. The problem is that you can't use LWLocks until you have a
PGPROC, and in the existing code backends don't acquire a PGPROC until
down inside InitPostgres. So some rearrangement of the startup sequence
is needed to make this work.

What I've done in the attached patch is to split InitProcess into two
parts, one that just creates a PGPROC (and is actually pretty comparable
to InitDummyProcess) and one that inserts the PGPROC into the shared
ProcArray. So a backend that has done just the first part is in a state
comparable to the way that dummy processes run for their entire existence:
it has a PGPROC but is not a member of ProcArray or the sinval ring.
This means it can grab LWLocks, but can't run transactions.

InitProcessPhase2 is still called from the same place in InitPostgres,
but InitProcess is moved elsewhere: in the ExecBackend case it's done
in SubPostmasterMain before calling CreateSharedMemoryAndSemaphores,
and otherwise it's done wherever convenient.

I found I also had to move the on_exit_reset calls, because that has to
happen before InitProcess, else we lose the shutdown callback that it
has to install for releasing the PGPROC.

Lastly, I split BackendRun into two parts, so that SubPostmasterMain
could perform client authentication before it runs InitProcess. This
avoids holding a PGPROC before we know the client is legit. (I could
alternatively have put the InitProcess call into the middle of
BackendRun, but this seemed cleaner.)

One advantage of doing this is that autovac is able to acquire its PGPROC
before it does the work of deciding which database to attach to. This has
no immediate use but it might allow future improvements, such as
inspecting the free space map while deciding which database to look at.

But other than that, this is kind of ugly :-(. Any opinions whether to
apply it, or leave things as they are?

regards, tom lane

Attachment Content-Type Size
shmemindexlock.patch.gz application/octet-stream 11.6 KB

Browse pgsql-patches by date

  From Date Subject
Next Message Jan Wieck 2006-01-03 04:06:57 Re: Stats collector performance improvement
Previous Message Joe Conway 2006-01-03 02:34:23 Re: [BUGS] BUG #2129: dblink problem