S_LOCK contention reduction via backoff, patch posted to patches list.

From: dg(at)illustra(dot)com (David Gould)
To: pgsql-hackers(at)postgresql(dot)org
Subject: S_LOCK contention reduction via backoff, patch posted to patches list.
Date: 1998-04-28 07:31:45
Message-ID: 9804280731.AA17371@hawk.illustra.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

After a long wait (as I was busy with other things), I have posted the
the Spinlock back off patch I promised to the patches list. 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
apply patch
run configure
and then
cd src/backend/buffer
make tas_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.

Files affected:
src/backend/storage/buffer/s_lock.c
src/backend/storage/buffer/Makefile
src/include/port/linux.h
src/include/storage/s_lock.h

Let me know if there are any problems or questions.

-dg

David Gould dg(at)illustra(dot)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>

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 1998-04-28 07:43:03 Re: New Driver and Unique Indexes
Previous Message David Gould 1998-04-28 06:39:06 Re: [HACKERS] postgres init script things solved