Re: [PATCHES] S_LOCK reduced contention through backoff patch - Mailing list pgsql-hackers

From dg@illustra.com (David Gould)
Subject Re: [PATCHES] S_LOCK reduced contention through backoff patch
Date
Msg-id 9804300206.AA24089@hawk.illustra.com
Whole thread Raw
Responses Re: [HACKERS] Re: [PATCHES] S_LOCK reduced contention through backoff patch
List pgsql-hackers
> On Tue, 28 Apr 1998, David Gould wrote:
> > After a long wait (as I was busy with other things), here is the Spinlock
> > back off patch I promised. This does semi-random backoff using select() to
> > lessen throughput degradation due to spinlock contention with large numbers
> > of runnable backends.
> >
> > This patch is meant to work on all current platforms, but I have only tested
> > it on Linux 2.0.32 i386 glibc (Redhat 5.0).
>
> Hi David...
>
>     Just tried to apply this to the current source tree, and pretty
> much failed miserably :(  can you check it and let me know?
>


"Hey Rocky, watch me submit a patch to pgsql. This time for sure".

Actually, I took the opportunity to think about it overnight and add a
few frills.

I just sent the patch (in diff -c format this time)
the patches list. I am reproducing the blurb here.

It should apply cleanly to 6.3.2 and the current snapshot.

Here is the Spinlock back off patch I promised. This does semi-random
backoff using select() to lessen throughput degradation due to spinlock
contention with large numbers of runnable backends.

This patch is meant to work on all current platforms, but I have only tested
it on Linux 2.0.32 i386 glibc (Redhat 5.0).

I restructured the files s_lock.c and s_lock.h to better separate the portable
parts from the machine dependant parts. Probably the best way to see what
happened is to apply the patch and then look at the changed files rather than
to try to read the patch directly.

I have also added a timeout feature to the attempt to grab a spinlock. If after
a suitably long time (currently a few minutes) a lock still cannot be locked,
we printf() a message and abort() the backend.

I hope that I have preserved the correctness of the tas() assembly code, but
this needs to be tested on each platform to make sure I have the sense of
the tests right. Remember, tas() is test_and_set and returns the PRIOR STATE
of the lock. If the prior state was FREE, the caller of TAS is now the lock
owner. Otherwise, the lock was already locked by someone else.

To make it easier to test on each platform, I have added a test routine and
makefile target to verify the S_LOCK() functionality. To run this:

If not done already
   cd pgsql
   apply patch
   run configure
and then
   cd src/backend/buffer
   make s_lock_test

If the test appears to hang (or you end up after a few minutes with the
"Stuck Spinlock" message), then S_LOCK() is working. Otherwise, please have
a look at what TAS() is returning and either fix it for the platform, or let
me know and I will give it a whack.

Let me know if there are any problems or questions.
-dg


David Gould            dg@illustra.com           510.628.3783 or 510.305.9468
Informix Software  (No, really)         300 Lakeside Drive  Oakland, CA 94612
"(Windows NT) version 5.0 will build on a proven system architecture
 and incorporate tens of thousands of bug fixes from version 4.0."
                 -- <http://www.microsoft.com/y2k.asp?A=7&B=5>

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] removing the exec() from doexec()
Next
From: The Hermit Hacker
Date:
Subject: Re: [HACKERS] removing the exec() from doexec()