Consultor Eletrônico



Kbase P18482: How to configure shared memory on UNIX
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

How to configure shared memory on UNIX

FIX:


How do I configure shared memory?
Shared memory uses a set of parameters similar to the ones for message queues. The Squid DISKD implementation uses one shared memory area for each cache_dir. Each shared memory area is about 800 kilobytes in size. You may need to modify your system's shared memory parameters:
SHMSEG
Maximum number of shared memory segments per process.
SHMMNI
Maximum number of shared memory segments for the whole system.
SHMMAX
Largest shared memory segment size allowed.
SHMALL
Total amount of shared memory that can be used.
FreeBSD
Your kernel must have
options SYSVSHM
You can set the parameters in the kernel as follows. This is just an example. Make sure the values are appropriate for your system:
options SHMSEG=16 # max shared mem id's per process
options SHMMNI=32 # max shared mem id's per system
options SHMMAX=2097152 # max shared memory segment size (bytes)
options SHMALL=4096 # max amount of shared memory (pages)


Name

Description

Reasonable values


SHMMAX

Maximum size of shared memory segment (bytes)

250kB + 8.2 kB * shared_buffers + 14.2 kB * max_connections or infinity


SHMMIN

Minimum size of shared memory segment (bytes)

1


SHMALL

Total amount of shared memory available (bytes or pages)

if bytes, same as SHMMAX; if pages, ceil(SHMMAX/PAGE_SIZE)


SHMSEG

Maximum number of shared memory segments per process

only 1 segment is needed, but the default is much higher


SHMMNI

Maximum number of shared memory segments system-wide

like SHMSEG plus room for other applications


SEMMNI

Maximum number of semaphore identifiers (i.e., sets)

>= ceil(max_connections / 16)


SEMMNS

Maximum number of semaphores system-wide

ceil(max_connections / 16) * 17 + room for other applications


SEMMSL

Maximum number of semaphores per set

>= 17


SEMMAP

Number of entries in semaphore. map

see text


SEMVMX

Maximum value of semaphore

>= 255 (The default is often 32767, don't change unless asked to.)
HP-UX
The default settings tend to suffice for normal installations. On HP-UX 10, the factory default for SEMMNS is 128, which might be too low for larger database sites.
IPC parameters can be set in the System Administration Manager (SAM) under Kernel Configuration->Configurable Parameters. Hit Create A New Kernel when you're done.
Linux
The default shared memory limit (both SHMMAX and SHMALL) is 32 MB in 2.2 kernels, but it can be changed in the proc file system (without reboot). For example, to allow 128 MB:
$ echo 134217728 >/proc/sys/kernel/shmall
$ echo 134217728 >/proc/sys/kernel/shmmax
You could put these commands into a script run at boot-time.
Alternatively, you can use sysctl, if available, to control these parameters. Look for a file called /etc/sysctl.conf and add lines like the following to it:
kernel.shmall = 134217728
kernel.shmmax = 134217728
This file is usually processed at boot time, but sysctl can also be called explicitly later.
Other parameters are sufficiently sized for any application. If you want to see for yourself look in /usr/src/linux/include/asm-xxx/shmpara m.h and /usr/src/linux/include/linux/sem.h.
MacOS X
Edit the file /System/Library/StartupItems/SystemTuning/SystemTuning and change the following values:
sysctl -w kern.sysv.shmmax
sysctl -w kern.sysv.shmmin
sysctl -w kern.sysv.shmmni
sysctl -w kern.sysv.shmseg
sysctl -w kern.sysv.shmall
These values have the same meanings on MacOS X as those listed for previous operating systems.
SCO OpenServer
In the default configuration, only 512 kB of shared memory per segment is allowed, which is about enough for -B 24 -N 12. To increase the setting, first change directory to /etc/conf/cf.d. To display the current value of SHMMAX, in bytes, run
./configure -y SHMMAX
To set a new value for SHMMAX, run:
./configure SHMMAX=value
where value is the new value you want to use (in bytes). After setting SHMMAX, rebuild the kernel
./link_unix
and reboot.
Solaris
At least in version 2.6, the default maximum size of a shared memory segments is too low for PostgreSQL. The relevant settings can be changed in /etc/system, for example:
set shmsys:shminfo_shmmax=0x2000000
set shmsys:shminfo_shmmin=1
set shmsys:shminfo_shmmni=256
set shmsys:shminfo_shmseg=256
set semsys:seminfo_semmap=256
set semsys:seminfo_semmni=512
set semsys:seminfo_semmns=512
set semsys:seminfo_semmsl=32
You need to reboot for the changes to take effect.
UnixWare
On UnixWare 7, the maximum size for shared memory segments is 512 kB in the default configuration. This is enough for about -B 24 -N 12. To display the current value of SHMMAX, run
/etc/conf/bin/idtune -g SHMMAX
which displays the current, default, minimum, and maximum values, in bytes. To set a new value for SHMMAX, run:
/etc/conf/bin/idtune SHMMAX value
where value is the new value you want to use (in bytes). After setting SHMMAX, rebuild the kernel
/etc/conf/bin/idbuild -B
and reboot. .