]> git.ozlabs.org Git - ccan/commit - ccan/tdb2/free.c
tdb2: relax locking to allow two free list locks at once
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 22 Nov 2010 02:13:00 +0000 (12:43 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 22 Nov 2010 02:13:00 +0000 (12:43 +1030)
commita5b66d7072af7dd5c17c1f4b1ede85f5cd4b7ca3
treefe11016cce4a5a15ffed28a2e5511763c49a2ebd
parent20defbbcfa088a7574d9897b533d1bc600b2df53
tdb2: relax locking to allow two free list locks at once

As long as they are in descending order.  This prevents the common case of:

1) Grab lock for bucket.
2) Remove entry from bucket.
3) Drop lock for bucket.
4) Grab lock for bucket for leftover.
5) Add leftover entry to bucket.
6) Drop lock for leftover bucket.

In particular it's quite common for the leftover bucket to be the same
as the entry bucket (when it's the largest bucket); if it's not, we are
no worse than before.

Current results of speed test:
$ ./speed 1000000
Adding 1000000 records:  13194 ns (60083192 bytes)
Finding 1000000 records:  2438 ns (60083192 bytes)
Traversing 1000000 records:  2167 ns (60083192 bytes)
Deleting 1000000 records:  9265 ns (60083192 bytes)
Re-adding 1000000 records:  10241 ns (60083192 bytes)
Appending 1000000 records:  17692 ns (93879992 bytes)
Churning 1000000 records:  26077 ns (93879992 bytes)

Previous:
$ ./speed 1000000
Adding 1000000 records:  23210 ns (59193360 bytes)
Finding 1000000 records:  2387 ns (59193360 bytes)
Traversing 1000000 records:  2150 ns (59193360 bytes)
Deleting 1000000 records:  13392 ns (59193360 bytes)
Re-adding 1000000 records:  11546 ns (59193360 bytes)
Appending 1000000 records:  29327 ns (91193360 bytes)
Churning 1000000 records:  33026 ns (91193360 bytes)
ccan/tdb2/free.c