From owner-freebsd-stable@FreeBSD.ORG Mon Apr 3 00:56:32 2006 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0D32916A41F for ; Mon, 3 Apr 2006 00:56:32 +0000 (UTC) (envelope-from scrappy@postgresql.org) Received: from hub.org (hub.org [200.46.204.220]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8078E43D48 for ; Mon, 3 Apr 2006 00:56:31 +0000 (GMT) (envelope-from scrappy@postgresql.org) Received: from localhost (av.hub.org [200.46.204.144]) by hub.org (Postfix) with ESMTP id 745B4823CB2; Sun, 2 Apr 2006 21:56:25 -0300 (ADT) Received: from hub.org ([200.46.204.220]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90425-06; Sun, 2 Apr 2006 21:56:29 -0300 (ADT) Received: from ganymede.hub.org (blk-222-82-85.eastlink.ca [24.222.82.85]) by hub.org (Postfix) with ESMTP id 163FA823CAE; Sun, 2 Apr 2006 21:56:23 -0300 (ADT) Received: by ganymede.hub.org (Postfix, from userid 1000) id 684014AA7E; Sun, 2 Apr 2006 21:56:32 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ganymede.hub.org (Postfix) with ESMTP id 6740D4AA2D; Sun, 2 Apr 2006 21:56:32 -0300 (ADT) Date: Sun, 2 Apr 2006 21:56:32 -0300 (ADT) From: "Marc G. Fournier" X-X-Sender: scrappy@ganymede.hub.org To: Tom Lane In-Reply-To: <25526.1144017388@sss.pgh.pa.us> Message-ID: <20060402213921.V947@ganymede.hub.org> References: <20060402163504.T947@ganymede.hub.org> <25422.1144016604@sss.pgh.pa.us> <25526.1144017388@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new at hub.org Cc: pgsql-hackers@postgresql.org, freebsd-stable@freebsd.org, Kris Kennaway Subject: Re: [HACKERS] semaphore usage "port based"? X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Apr 2006 00:56:32 -0000 On Sun, 2 Apr 2006, Tom Lane wrote: > I wrote: >> Look at IpcSemaphoreCreate and InternalIpcSemaphoreCreate in >> src/backend/port/sysv_sema.c. It may be worth stepping through them >> with gdb to see what the semget calls are returning. > > BTW, even before doing that, you should look at "ipcs -s" output to try > to get a clue what's going on. The EINVAL failures may be because the > second postmaster to start deletes the semaphores created by the first > one. You could easily see this happening in before-and-after ipcs data > if so. You are right ... Before: Semaphores: T ID KEY MODE OWNER GROUP CREATOR CGROUP NSEMS OTIME CTIME s 524288 5432001 --rw------- 70 70 70 70 17 14:44:19 14:44:19 s 524289 5432002 --rw------- 70 70 70 70 17 14:44:19 14:44:19 s 524290 5432003 --rw------- 70 70 70 70 17 14:44:19 14:44:19 s 524291 5432004 --rw------- 70 70 70 70 17 14:44:19 14:44:19 s 524292 5432005 --rw------- 70 70 70 70 17 14:44:19 14:44:19 s 524293 5432006 --rw------- 70 70 70 70 17 20:23:56 14:44:19 s 524294 5432007 --rw------- 70 70 70 70 17 20:23:58 14:44:19 After: Semaphores: T ID KEY MODE OWNER GROUP CREATOR CGROUP NSEMS OTIME CTIME s 589824 5432001 --rw------- 70 70 70 70 17 21:38:03 21:38:03 s 589825 5432002 --rw------- 70 70 70 70 17 21:38:03 21:38:03 s 589826 5432003 --rw------- 70 70 70 70 17 21:38:03 21:38:03 s 589827 5432004 --rw------- 70 70 70 70 17 21:38:03 21:38:03 s 589828 5432005 --rw------- 70 70 70 70 17 21:38:03 21:38:03 s 589829 5432006 --rw------- 70 70 70 70 17 21:38:03 21:38:03 s 589830 5432007 --rw------- 70 70 70 70 17 21:38:03 21:38:03 So, our semget() is trying to acquire 5432001, FreeBSD's semget is reporting back that its not in use, so the second instance if basically 'punting' the original one off of it ... Kris, from the PostgreSQL sources, here is where we try and set the semId to use ... is there something we are doing wrong with our code as far as FreeBSD 6.x is concerned, such that semget is not returning a negative value when the key is already in use? Or is there a problem with semget() in a jail such that it is allowing for the KEY to be reused, instead of returning a negative value? ======== static IpcSemaphoreId InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems) { int semId; semId = semget(semKey, numSems, IPC_CREAT | IPC_EXCL | IPCProtection); if (semId < 0) { /* * Fail quietly if error indicates a collision with existing set. * One would expect EEXIST, given that we said IPC_EXCL, but * perhaps we could get a permission violation instead? Also, * EIDRM might occur if an old set is slated for destruction but * not gone yet. */ if (errno == EEXIST || errno == EACCES #ifdef EIDRM || errno == EIDRM #endif ) return -1; /* * Else complain and abort */ ereport(FATAL, (errmsg("could not create semaphores: %m"), errdetail("Failed system call was semget(%d, %d, 0%o).", (int) semKey, numSems, IPC_CREAT | IPC_EXCL | IPCProtection), (errno == ENOSPC) ? errhint("This error does *not* mean that you have run out of disk space.\n" "It occurs when either the system limit for the maximum number of " "semaphore sets (SEMMNI), or the system wide maximum number of " "semaphores (SEMMNS), would be exceeded. You need to raise the " "respective kernel parameter. Alternatively, reduce PostgreSQL's " "consumption of semaphores by reducing its max_connections parameter " "(currently %d).\n" "The PostgreSQL documentation contains more information about " "configuring your system for PostgreSQL.", MaxBackends) : 0)); } return semId; } ======== ---- Marc G. Fournier Hub.Org Networking Services (http://www.hub.org) Email: scrappy@hub.org Yahoo!: yscrappy ICQ: 7615664