From rmh@khazad.dyndns.org  Thu Feb 10 17:49:06 2005
Return-Path: <rmh@khazad.dyndns.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0364816A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Feb 2005 17:49:06 +0000 (GMT)
Received: from khazad.dyndns.org (137.red-62-57-138.user.auna.net [62.57.138.137])
	by mx1.FreeBSD.org (Postfix) with ESMTP id A145E43D1F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Feb 2005 17:49:05 +0000 (GMT)
	(envelope-from rmh@khazad.dyndns.org)
Received: from rmh by khazad.dyndns.org with local (Exim 4.34)
	id 1CzILG-0007uH-MH
	for FreeBSD-gnats-submit@freebsd.org; Thu, 10 Feb 2005 18:43:02 +0100
Message-Id: <E1CzILG-0007uH-MH@khazad.dyndns.org>
Date: Thu, 10 Feb 2005 18:43:02 +0100
From: Robert Millan <rmh@debian.org>
Reply-To: Robert Millan <rmh@debian.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: grow SysV IPC kernel limits
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         77353
>Category:       kern
>Synopsis:       [patch] grow SysV IPC kernel limits
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 10 17:50:14 GMT 2005
>Closed-Date:    Tue Oct 25 04:58:22 GMT 2005
>Last-Modified:  Sat Oct 11 16:00:06 UTC 2008
>Originator:     Robert Millan
>Release:        GNU/kFreeBSD 5.3-3 i686
>Organization:
Debian
>Environment:
System: GNU/kFreeBSD aragorn 5.3-3 #0: Thu Feb 10 15:39:57 CET 2005 i686 GNU/KFreeBSD

postgresql documentation encourages to grow SysV IPC limits on *BSD systems.

I have verified that the GENERIC limits on SysV IPC are too low to be able to
run postgresql.  Please adjust them as the documentation recommends:

<quote>
    The options SYSVSHM and SYSVSEM need to be enabled when the kernel is compil
ed. (They are by default.) The maximum size of shared memory is determined by th
e option SHMMAXPGS (in pages). The following shows an example of how to set the
various parameters:

options         SYSVSHM
options         SHMMAXPGS=4096
options         SHMSEG=256

options         SYSVSEM
options         SEMMNI=256
options         SEMMNS=512
options         SEMMNU=256
options         SEMMAP=256

    (On NetBSD and OpenBSD the key word is actually option singular.)

    You might also want to configure your kernel to lock shared memory into RAM
and prevent it from being paged out to swap. Use the sysctl setting kern.ipc.shm
_use_phys. 
</quote>

	
>Description:
	
>How-To-Repeat:
	
>Fix:

--- src/sys/i386/conf/GENERIC~  2005-02-01 21:44:25.000000000 +0100
+++ src/sys/i386/conf/GENERIC   2005-02-01 21:47:12.000000000 +0100
@@ -49,8 +49,14 @@
 options        SCSI_DELAY=15000        # Delay (in ms) before probing SCSI
 options        KTRACE                  # ktrace(1) support
 options        SYSVSHM                 # SYSV-style shared memory
+options         SHMMAXPGS=4096
+options         SHMSEG=256
 options        SYSVMSG                 # SYSV-style message queues
 options        SYSVSEM                 # SYSV-style semaphores
+options         SEMMNI=256
+options         SEMMNS=512
+options         SEMMNU=256
+options         SEMMAP=256
 options        _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extension
s
 options        KBD_INSTALL_CDEV        # install a CDEV entry in /dev
 options        AHC_REG_PRETTY_PRINT    # Print register bitfields in debug
>Release-Note:
>Audit-Trail:

From: "Devon H. O'Dell" <dodell@sitetronics.com>
To: Robert Millan <rmh@debian.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/77353: grow SysV IPC kernel limits
Date: Fri, 11 Feb 2005 11:21:54 +0100

 If I'm not mistaken, these can be set as sysctls. Take a look at the
 kern.ipc MIB.
 
 --Devon
 

From: Robert Millan <rmh@debian.org>
To: "Devon H. O'Dell" <dodell@sitetronics.com>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/77353: grow SysV IPC kernel limits
Date: Fri, 11 Feb 2005 13:23:43 +0100

 > If I'm not mistaken, these can be set as sysctls. Take a look at the
 > kern.ipc MIB.
 
 You mean in runtime?  IIRC, some of the kern.ipc sysctl variables are not
 writable.  Am I missing something?
 
 -- 
  .''`.   Proudly running Debian GNU/kFreeBSD unstable/unreleased (on UFS2+S)
 : :' :
 `. `'    http://www.debian.org/ports/kfreebsd-gnu
   `-

From: "Devon H. O'Dell" <dodell@sitetronics.com>
To: Robert Millan <rmh@debian.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/77353: grow SysV IPC kernel limits
Date: Fri, 11 Feb 2005 13:36:20 +0100

 > You mean in runtime?  IIRC, some of the kern.ipc sysctl variables are not
 > writable.  Am I missing something?
 > 
 
 Correct, but I believe they can still be set in /etc/boot.conf simply by
 specifying:
 
 MIB_NAME="VALUE"
 
 --Devon
 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Tue Oct 25 02:59:14 GMT 2005 
State-Changed-Why:  
To submitter: is the advice given in the Audit-Trail sufficient to solve 
your problem? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=77353 
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Tue Oct 25 04:58:05 GMT 2005 
State-Changed-Why:  
Submitter agrees that this can be closed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=77353 

From: Gunther Schadow <gunther@aurora.regenstrief.org>
To: bug-followup@FreeBSD.org, rmh@debian.org
Cc:  
Subject: Re: kern/77353: [patch] grow SysV IPC kernel limits
Date: Sat, 11 Oct 2008 11:43:45 -0400

 I have tried the patch on uname = 7.0-RELEASE-p5.
 
 It allows me to start PostgreSQL with 16 GB shared_buffer on a 32 GB system.
 There is no longer an error nor a segmentation violation.
 
 However, I cannot get ipcs to work it fails with this error when tryting
 to generate the shm list:
 
      ipcs: sysctlbyname: kern.ipc.shmsegs: Cannot allocate memory
 
 yet, I can still do:
 
      sysctl -a kern.ipc.shmsegs
 
 it just never shows anything (but neither does so in unpatched 6.2 or 
 7.0 release, so I assume that's normal). Had no time to check, but 
 would think that perhaps sysctlbyname also needs to be recompiled and
 for that one would have to redo all of libc.
 
 On the good side, PostgreSQL does not seem to rely on this ipcs type
 listing feature.
 
 Here is an easy program that tests the shm allocation *and* use:
 
 #include <machine/param.h>
 #include <sys/types.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <stdio.h>
 #include <stdlib.h>
 int main(int argc, char *argv[]) {
      size_t size = strtoul(argv[1],NULL,10);
      key_t key = atol(argv[2]);
      int shm;
      char *mem;
      int i;
      printf("Start: %lu, %lu\n", size, key);
      shm = shmget(key, size, IPC_CREAT|SHM_R|SHM_W);
      printf("Result: %d\n", shm);
      mem = shmat(shm, 0, 0);
      printf("Attached: %p\n", mem);
      for(i=0; i<size; i++)
         mem[i] = 0;
      printf("Done!\n");
      shmdt(mem);
      shmctl(shm, IPC_RMID, NULL);
      return 0;
 }
>Unformatted:
