From nobody@FreeBSD.org  Thu Mar  6 09:32:16 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 431B31065670
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Mar 2008 09:32:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 325CA8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Mar 2008 09:32:16 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m269TCEI081166
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 6 Mar 2008 09:29:12 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m269TC2T081165;
	Thu, 6 Mar 2008 09:29:12 GMT
	(envelope-from nobody)
Message-Id: <200803060929.m269TC2T081165@www.freebsd.org>
Date: Thu, 6 Mar 2008 09:29:12 GMT
From: Dmitry Rybin <dimanenator@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Cann't allocate more 2  Gb shared memory
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         121423
>Category:       kern
>Synopsis:       [sysvshm] Can't allocate more 2  Gb shared memory
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    csjp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 06 09:40:00 UTC 2008
>Closed-Date:    Thu Mar 19 23:52:57 UTC 2009
>Last-Modified:  Thu Mar 19 23:52:57 UTC 2009
>Originator:     Dmitry Rybin
>Release:        7.0-RELEASE
>Organization:
Kirgudu Co
>Environment:
FreeBSD cayman.asd.net 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 10:35:36 UTC 2008     root@driscoll.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
Any program which use SHARED MEMORY can't allocate more 2 Gb of Shared memory.

as example starting postgres with 2GB shmem:
Mar  6 10:46:42 cayman postgres[1486]: [1-1] FATAL:  could not create shared memory segment: Invalid argument
Mar  6 10:46:42 cayman postgres[1486]: [1-2] DETAIL:  Failed system call was shmget(key=5432001, size=2157543424, 03600).
Mar  6 10:46:42 cayman postgres[1486]: [1-3] HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter. 
Mar  6 10:46:42 cayman postgres[1486]: [1-4]  You can either reduce the request size or reconfigure the kernel with larger SHMMAX.  To reduce the request size (currently
Mar  6 10:46:42 cayman postgres[1486]: [1-5]  2157543424 bytes), reduce PostgreSQL's shared_buffers parameter (currently 256000) and/or its max_connections parameter
Mar  6 10:46:42 cayman postgres[1486]: [1-6]  (currently 83).
Mar  6 10:46:42 cayman postgres[1486]: [1-7]    If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising
Mar  6 10:46:42 cayman postgres[1486]: [1-8]  the request size or reconfiguring SHMMIN is called for.
Mar  6 10:46:42 cayman postgres[1486]: [1-9]    The PostgreSQL documentation contains more information about shared memory configuration.

# sysctl -a|grep ipc.sem
kern.ipc.semaem: 16384
kern.ipc.semvmx: 32767
kern.ipc.semusz: 104
kern.ipc.semume: 10
kern.ipc.semopm: 100
kern.ipc.semmsl: 60
kern.ipc.semmnu: 256
kern.ipc.semmns: 512
kern.ipc.semmni: 256
kern.ipc.semmap: 512

sysctl -a|grep shm
kern.ipc.shm_allow_removed: 0
kern.ipc.shm_use_phys: 1
kern.ipc.shmall: 65536000
kern.ipc.shmseg: 128
kern.ipc.shmmni: 192
kern.ipc.shmmin: 1
kern.ipc.shmmax: 268435456010

Hardware:
HP360R05 2 Quad Core Xeon, 8Gb mem, HP p800i raid
>How-To-Repeat:
1. Install FreeBSD 7
2. Install Posgress 8.3

3 . postgresql.conf
    shared_buffers = 2200MB

4. edit sysctl
# sysctl -a|grep ipc.sem
kern.ipc.semaem: 16384
kern.ipc.semvmx: 32767
kern.ipc.semusz: 104
kern.ipc.semume: 10
kern.ipc.semopm: 100
kern.ipc.semmsl: 60
kern.ipc.semmnu: 256
kern.ipc.semmns: 512
kern.ipc.semmni: 256
kern.ipc.semmap: 512

sysctl -a|grep shm
kern.ipc.shm_allow_removed: 0
kern.ipc.shm_use_phys: 1
kern.ipc.shmall: 65536000
kern.ipc.shmseg: 128
kern.ipc.shmmni: 192
kern.ipc.shmmin: 1
kern.ipc.shmmax: 268435456010

5. start postgress
>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->csjp 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Sat Mar 8 13:07:35 UTC 2008 
Responsible-Changed-Why:  

this one is looking like a signed int limitation. 
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121423 
State-Changed-From-To: open->feedback 
State-Changed-By: csjp 
State-Changed-When: Sat Mar 8 16:29:40 UTC 2008 
State-Changed-Why:  
The issue here is that our shmid_ds structure uses a signed integer 
to represent the segment size. 

struct shmid_ds { 
struct ipc_perm shm_perm;   /* operation permission structure */ 
int             shm_segsz;  /* size of segment in bytes */ 
pid_t           shm_lpid;   /* process ID of last shared memory op */ 
pid_t           shm_cpid;   /* process ID of creator */ 
short           shm_nattch; /* number of current attaches */ 
time_t          shm_atime;  /* time of last shmat() */ 
time_t          shm_dtime;  /* time of last shmdt() */ 
time_t          shm_ctime;  /* time of last change by shmctl() */ 
void           *shm_internal; /* sysv stupidity */ 
}; 

This really should be size_t, so that systems can use the amount of memory 
their architecture supports.  The problem is, this change breaks the ABI, 
and unfortunately there are a couple of compat layers that need to be 
analyzed to make sure nothing breaks with the change. 

We have been discussing this problem for a while, and we have decided that 
we are going to fix some other limitations in ipc_perm at the same time 
we switch shmsegsz to a size_t and add all the compat shims at the same 
time. I am currently analyzing the impact of doing this since ipc_perm 
is used by all system V IPC mechanisms, not just shared memory. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121423 
State-Changed-From-To: feedback->patched 
State-Changed-By: csjp 
State-Changed-When: Tue Mar 3 14:21:05 UTC 2009 
State-Changed-Why:  
This has been fixed in -CURRENT and will be MFCed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121423 
State-Changed-From-To: patched->closed 
State-Changed-By: csjp 
State-Changed-When: Thu Mar 19 23:52:25 UTC 2009 
State-Changed-Why:  
Fix has been MFCed into -STABLE by kib. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121423 
>Unformatted:
