tdb: workaround starvation problem in locking entire database.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 16 Aug 2010 00:52:21 +0000 (10:22 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 16 Aug 2010 00:52:21 +0000 (10:22 +0930)
commit9ec0009443a0ac4187ce5212a5143689daa58a02
tree0041c82ff0518d0e797eb090f83d690fbe6c1246
parenta5db1122ec48d7e7384066848457c850c1a6cf3c
tdb: workaround starvation problem in locking entire database.

(Imported from SAMBA 11ab43084b10cf53b530cdc3a6036c898b79ca38)

We saw tdb_lockall() take 71 seconds under heavy load; this is because Linux
(at least) doesn't prevent new small locks being obtained while we're waiting
for a big log.

The workaround is to do divide and conquer using non-blocking chainlocks: if
we get down to a single chain we block.  Using a simple test program where
children did "hold lock for 100ms, sleep for 1 second" the time to do
tdb_lockall() dropped signifiantly.  There are ln(hashsize) locks taken in
the contended case, but that's slow anyway.

More analysis is given in my blog at http://rusty.ozlabs.org/?p=120

This may also help transactions, though in that case it's the initial
read lock which uses this gradual locking routine; the update-to-write-lock
code is separate and still tries to update in one go.

Even though ABI doesn't change, minor version bumped so behavior change
can be easily detected.

CQ:S1018154
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/tdb/common/lock.c
lib/tdb/configure.ac