From owner-freebsd-arch@FreeBSD.ORG Wed Dec 22 03:41:48 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1F54416A4CE for ; Wed, 22 Dec 2004 03:41:48 +0000 (GMT) Received: from khavrinen.lcs.mit.edu (khavrinen.lcs.mit.edu [128.30.28.20]) by mx1.FreeBSD.org (Postfix) with ESMTP id BB6B443D54 for ; Wed, 22 Dec 2004 03:41:47 +0000 (GMT) (envelope-from wollman@khavrinen.lcs.mit.edu) Received: from khavrinen.lcs.mit.edu (localhost [IPv6:::1]) by khavrinen.lcs.mit.edu (8.12.9/8.12.9) with ESMTP id iBM3fkaa043953 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK CN=khavrinen.lcs.mit.edu issuer=SSL+20Client+20CA); Tue, 21 Dec 2004 22:41:46 -0500 (EST) (envelope-from wollman@khavrinen.lcs.mit.edu) Received: (from wollman@localhost) by khavrinen.lcs.mit.edu (8.12.9/8.12.9/Submit) id iBM3fj5j043952; Tue, 21 Dec 2004 22:41:45 -0500 (EST) (envelope-from wollman) Date: Tue, 21 Dec 2004 22:41:45 -0500 (EST) From: Garrett Wollman Message-Id: <200412220341.iBM3fj5j043952@khavrinen.lcs.mit.edu> To: joe@zircon.seattle.wa.us X-Newsgroups: mit.lcs.mail.freebsd-arch In-Reply-To: <1103681460.30309.799.camel@zircon.zircon.seattle.wa.us> References: <1102975803.30309.196.camel@zircon.zircon.seattle.wa.us> <20041222011506.GG801@straylight.m.ringlet.net> Organization: MIT Laboratory for Computer Science X-Spam-Score: -9.9 () IN_REP_TO,REFERENCES X-Scanned-By: MIMEDefang 2.37 cc: arch@FreeBSD.org Subject: Re: Fixing Posix semaphores X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Dec 2004 03:41:48 -0000 In article <1103681460.30309.799.camel@zircon.zircon.seattle.wa.us> you write: >So, there are words there that can be interpreted many different ways. >The most restricted way to view them is as 14-character names optionally >beginning with a slash. That also seems to me to be the stupidest way >to view them. Robert's idea of semfs seems brilliant, allowing multiple >name spaces for jailed processes. I plan to start thinking and working >on that idea shortly. Here is an even easier way that avoids creating a special file type... sem_open() can be implemented as: fd = shm_open(name, oflag, omode); if (oflag & O_CREAT) { ftruncate(fd, sizeof(struct sem_private)); } sem_private = mmap(fd, ...); sem_private->fd = fd; sem = malloc(sizeof *sem); _sem_init(sem, sem_private, value); return (sem); The underlying semaphore can then be implemented in the standard way with a mutex, a condition variable (or simulation thereof), and a counter in the shared-memory region -- no (additional) kernel code required. (This avoids the overhead of a system call if there is no need to wait.) Alternatively, given the current kernel implementation, you can very simply convert any vnode into a 20-byte flat name for the file using VFS_VPTOFH() -- this would require only minimal changes to the existing code. -GAWollman