From 725b3654f831fbe0388cc09f46269903c9eef1d7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 16 Feb 2010 12:22:08 +0100 Subject: [PATCH] s3: Avoid a thundering herd in g_lock_unlock Only notify the first 5 pending lock waiters. This avoids a thundering herd problem that is really nasty in a cluster. It also makes acquiring a lock a bit more FIFO, lock waiters are added to the end of the array. --- source3/lib/g_lock.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index e2620255d9c..512c0680d9f 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -530,13 +530,23 @@ static NTSTATUS g_lock_force_unlock(struct g_lock_ctx *ctx, const char *name, } if ((lock_type & G_LOCK_PENDING) == 0) { + int num_wakeups = 0; + /* - * We've been the lock holder. Tell all others to retry. + * We've been the lock holder. Others to retry. Don't + * tell all others to avoid a thundering herd. In case + * this leads to a complete stall because we miss some + * processes, the loop in g_lock_lock tries at least + * once a minute. */ + for (i=0; i 5) { + break; } } } -- 2.34.1