From owner-freebsd-stable@FreeBSD.ORG Thu May 8 08:26:03 2008 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 326F61065678 for ; Thu, 8 May 2008 08:26:03 +0000 (UTC) (envelope-from paul.koch@statseeker.com) Received: from wally.statseeker.com (wally.statseeker.com [203.39.101.146]) by mx1.freebsd.org (Postfix) with ESMTP id B3CAD8FC20 for ; Thu, 8 May 2008 08:26:02 +0000 (UTC) (envelope-from paul.koch@statseeker.com) Received: from localhost (localhost [127.0.0.1]) by wally.statseeker.com (8.14.2/8.14.2) with ESMTP id m488CRxJ058080 for ; Thu, 8 May 2008 18:12:27 +1000 (EST) (envelope-from paul.koch@statseeker.com) X-Virus-Scanned: amavisd-new at statseeker.com Received: from wally.statseeker.com ([127.0.0.1]) by localhost (wally.statseeker.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8WR4bn1Y6eJP for ; Thu, 8 May 2008 18:12:22 +1000 (EST) Received: from speedy.statseeker.com (speedy.statseeker.com [10.1.1.100]) (authenticated bits=0) by wally.statseeker.com (8.14.2/8.14.2) with ESMTP id m488CLYF058075 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 8 May 2008 18:12:21 +1000 (EST) (envelope-from paul.koch@statseeker.com) From: Paul Koch To: freebsd-stable@freebsd.org Date: Thu, 8 May 2008 18:12:24 +1000 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_oXrIIONLCDwd8Mw" Message-Id: <200805081812.24692.paul.koch@statseeker.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: flock incorrectly detects deadlock on 7-stable and current X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: paul.koch@statseeker.com List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 May 2008 08:26:03 -0000 --Boundary-00=_oXrIIONLCDwd8Mw Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, We have been trying to track down a problem with one of our apps which does a lot of flock(2) calls. flock returns errno 11 (Resource deadlock avoided) under certain scenarios. Our app works fine on 7-Release, but fails on 7-stable and -current. The problem appears to be when we have at least three processes doing flock() on a file, and one is trying to upgrade a shared lock to an exclusive lock but fails with a deadlock avoided. Attached is a simple flock() test program. a. Process 1 requests and gets a shared lock b. Process 2 requests and blocks for an exclusive lock c. Process 3 requests and gets a shared lock d. Process 3 requests an upgrade to an exclusive lock but fails (errno 11) If we change 'd' to Process 3 requests unlock, then requests exclusive lock, it works. The manual page says: "A shared lock may be upgraded to an exclusive lock, and vice versa, simply by specifying the appropriate lock type; this results in the previous lock being released and the new lock applied (possibly after other processes have gained and released the lock)." The manual page doesn't mention that flock() can fail with a deadlock. Our test environment is: - 8 core Intel machine running i386 stable - 4 core Intel machine running amd64 current (20080508) - 4 core Intel machine running amd64 stable (20080508) - 2 core AMD machine running i386 stable (20080418) - 2 core AMD machine running i386 stable (20080418) - single core (no hyperthreading) i386 stable (20080418) There appears to have been changes to kern_lockf.c and other stuff around the 10th April to do with deadlock detection. We don't see the problem on 6.2-stable, 7-Release, or 7-stable pre ~10th April. Paul. --Boundary-00=_oXrIIONLCDwd8Mw--