From owner-freebsd-hackers@FreeBSD.ORG Wed Dec 20 04:48:56 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 62DBD16A407 for ; Wed, 20 Dec 2006 04:48:56 +0000 (UTC) (envelope-from duane@dwpc.dwlabs.ca) Received: from smtpout.eastlink.ca (smtpout.eastlink.ca [24.222.0.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id F087743C9F for ; Wed, 20 Dec 2006 04:48:55 +0000 (GMT) (envelope-from duane@dwpc.dwlabs.ca) Received: from ip04.eastlink.ca ([24.222.10.20]) by mta01.eastlink.ca (Sun Java System Messaging Server 6.2-4.03 (built Sep 22 2005)) with ESMTP id <0JAK00BBU1AAI980@mta01.eastlink.ca> for freebsd-hackers@freebsd.org; Wed, 20 Dec 2006 00:18:10 -0400 (AST) Received: from blk-224-199-230.eastlink.ca (HELO dwpc.dwlabs.ca) ([24.224.199.230]) by ip04.eastlink.ca with ESMTP; Wed, 20 Dec 2006 00:18:52 -0400 Received: from dwpc.dwlabs.ca (localhost [127.0.0.1]) by dwpc.dwlabs.ca (8.13.8/8.13.8) with ESMTP id kBK4IhvH010801 for ; Wed, 20 Dec 2006 00:18:43 -0400 (AST envelope-from duane@dwpc.dwlabs.ca) Received: (from duane@localhost) by dwpc.dwlabs.ca (8.13.8/8.13.8/Submit) id kBK4IhZY010800 for freebsd-hackers@freebsd.org; Wed, 20 Dec 2006 00:18:43 -0400 (AST envelope-from duane) Date: Wed, 20 Dec 2006 00:18:43 -0400 From: Duane Whitty To: freebsd-hackers@freebsd.org Message-id: <20061220041843.GA10511@dwpc.dwlabs.ca> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAM9HiEUY4MfmdGdsb2JhbACNcA X-IronPort-AV: i="4.12,191,1165204800"; d="scan'208"; a="52033119:sNHT103919679" User-Agent: Mutt/1.4.2.2i Subject: Locking fundamentals X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Dec 2006 04:48:56 -0000 Hello again, It seems to me that understanding locking holds the key to understanding fbsd internals. Could someone review my understanding of fbsd locking fundamentals. (No assertions here, just questions) lock_mgr -------------------- mutexes|sx_lock ------------------- ^ atomic | mem barriers | Don't lock if you don't need to. Lock only what you need to. Use the simplest lock that gets the job done. Don't drop locks prematurely because acquiring locks is expensive. When possible sleep rather than spin. ?????? Memory barriers order operations Atomic operations complete without being interrupted Atomic operations and memory barriers are the primitives. Mutexes are implemented by atomic operations and memory barriers. Mutexes are relatively simple and inexpensive but may not recurse. Shared/exclusive locks are more versatile than mutexes in that they may be upgraded or downgraded from or to shared/exclusive and they may be acquired recursively. More expensive than mutexes. lock_mgr locks are used when reference counting is needed ????? Would there be any particular sections of kernel code that you believe might be enlightening with respects to locking? I have read the man pages describing each family of locks, John Baldwin's BSDCon 2002 paper, Jeffrey Hsu's paper, the Arch handbook, and the source. I don't understand it all yet and it feels like I am missing some fundamental point, especially concerning the lock_mgr family. Does anyone have some pointers they feel like sharing? Does anyone have any good references they can point me to that is relevant to fbsd given all the recent changes as a result of SMP? Is The Design and Implementation of the FreeBSD Operating System still current enough? Best Regards, Duane Whitty