Change the maximum value of shared memory under Linux __linux

Source: Internet
Author: User
Tags joins postgresql semaphore

System V IPC parameters

name Description Reasonable Value
SHMMAX Maximum shared memory segment size (bytes) At least a few megabytes (see text)
Shmmin Minimum shared memory segment size (bytes) 1
Shmall Total amount of available shared memory (bytes or pages) If it's a byte, it's the same as SHMMAX; if it's a page, Ceil (shmmax/page_size)
Shmseg Maximum number of shared memory segments per process Only 1 segments are required, but the default is much higher.
Shmmni System-wide maximum number of shared memory segments Similar to SHMSEG plus space for other applications
Semmni Minimum number of semaphore identifiers (i.e., sets) At least ceil (MAX_CONNECTIONS/16)
Semmns System-wide maximum number of semaphores Ceil (MAX_CONNECTIONS/16) * 17 plus space for other applications
Semmsl Minimum number of signal lights per set At least 17
Semmap Number of records in the signal map See text
Semvmx Maximum value of the semaphore At least 1000 (the default is usually 32767 unless forced, do not modify)

The most important shared memory parameter is SHMMAX, the maximum size that the shared memory segment can have in bytes. If you receive an error message such as invalid argument from Shmget, it is likely that you have exceeded the limit.

Some systems have limits on the total number of shared memory (Shmall) in the system. Please note that this value must be large enough. (Note: Shmall is computed on many systems on a number of pages, not in bytes.) )

The maximum number of semaphores in the system is set by Semmns, so this value should be at least as large as the max_connections setting, and one for each 16 joins. The parameter Semmni determines the number of semaphore sets that can exist at one time in the system. Therefore, this parameter should be at least ceil (max_connections% 16). Reducing the allowable number of joins is a temporary way to circumvent the failure, which is often confused by the error response from the function Semget No space left on device.

Sometimes it may be necessary to increase semmap to at least semmns configuration. This parameter defines the dimensions of the semaphore resource mapping, and each successive semaphore block available holds a record in this map. Whenever a set of Semaphores is released, it is either added to the entry of a connected, freed block in the map, or is registered as a new entry. If the map fills up with fragments, the emitted semaphore is lost (unless it is reset). As a result, the fragmentation of the time-long semaphore space can result in fewer semaphores than should be available.

SEMMSL parameters, determine how many lights can be in a set of lights,

Change Method Linux

The default setting is only for small installations (the default maximum shared memory is MB). However, other defaults are quite large and usually do not need to be changed. The maximum shared memory segment settings can be set with the Sysctl interface. For example, to allow 128 MB, and the maximum total shared memory is 2097152 pages (default):

$
 sysctl-w kernel.shmmax=134217728

$ sysctl-w kernel.shmall=2097152

You can put these settings in the/etc/sysctl.conf and remain in effect after reboot.

The old version may not have a sysctl program, but the same change can be done by manipulating the/proc file system:

$
 echo 134217728 >/proc/sys/kernel/shmmax

$ echo 2097152 >/proc/sys/kernel/shmall
Another feasible method:
The modification method is as follows: Modify the/etc/rc.d/rc.local file.

Add the following line after the previous comment in the file:

#修改内核共享内存大小;

echo134217728>/proc/sys/kernel/shmmax;

#说明: The value here is half of the memory;

#如果系统内存是256M, the value is 134217728;

#如果系统内存是512M, the value is 268435456;

After the modification is done, the machine will be finished.

Other system modification Methods MacOS X

In OS X 10.2 and later, edit the file/system/library/startupitems/systemtuning/systemtuning and modify the values with the following commands:

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

In OS X 10.3 and beyond, these commands are moved to/ETC/RC and must be edited there. You need to reboot for the settings to take effect. Note that/ETC/RC is typically overwritten by OS X updates (such as 10.3.6 to 10.3.7), so you may need to edit them after each update.

On this platform, the shmall is measured in 4KB pages. Also note that some versions of OS X will reject the SHMMAX numeric value of a multiple of not 4096. SCO OpenServer

The default configuration allows only 512KB of shared memory per segment. To increase the settings, first enter the/ETC/CONF/CF.D directory. To display the current byte-SHMMAX, run

./configure-y SHMMAX

To set a new value for SHMMAX:

./configure Shmmax=value

Here value is the new value you want to set in bytes. After Setup, shmmax the kernel again.

./link_unix

And then back up. Aix

At least for version 5.1, we need to make a special configuration for parameters like SHMMAX, because this parameter can be configured to use all content as shared memory. This is the common configuration for databases like DB/2.

However, it may be necessary to modify the global Ulimit Ulimit information in/etc/security/limits because the default hard limit (fsize) of file size and the number of files (nofiles) may be too low. Solaris

The default maximum setting for shared memory segments is too low for PostgreSQL, at least until version 2.6. The relevant settings can be modified 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 have to reboot the system to make the changes take effect.

See also http://sunsite.uakom.sk/sunworldonline/swol-09-1997/swol-09-insidesolaris.html for information about shared memory inside Solaris. UnixWare

On UnixWare 7, the largest shared memory segment in the default configuration is KB. To display the current value of the Shmmax, run

/etc/conf/bin/idtune-g SHMMAX

The current default minimum and maximum values in bytes are displayed. To set a new value for Shmmax, run:

/etc/conf/bin/idtune SHMMAX Value

Here value is the new value you want to set in bytes. After Shmmax is set up, rebuild the kernel

/etc/conf/bin/idbuild-b

And then back up.

Bsd/os

shared memory. By default, only 4 MB of shared memory is supported. Remember that shared memory is not paged; it's locked in RAM. To increase the number of shared buffers supported by your system, add the following lines to your kernel configuration file:

Options "shmall=8192"
Options "shmmax=/(shmall*page_size/)"

Shmall is calculated as a 4KB page, so 1024 pages represent 4 M shared memory. So the above thing adds the shared memory area to MB. for people running 4.3 or later, you may need to increase the KERNEL_VIRTUAL_MB by more than the default of 248. After you have done the above modifications, then compile the kernel and start again.

For versions running 4.0 or earlier, use Bpatch to find the sysptsize value of the current kernel. It is dynamically computed at startup.

$ bpatch-r Sysptsize

0x9 = 9

Then, change the sysptsize to a hard code value in the kernel configuration file. Use Bpatch to calculate the value and add 1 to each additional 4 MB of shared memory you need.

Options "Sysptsize=16"

Sysptsize cannot be modified with sysctl.

Traffic lights. You may also need to increase the number of traffic lights; The total system defaults 60 can only allow about 50 PostgreSQL connections. Set the values you want in the kernel configuration file, such as:

Options "Semmni=40"
Options "semmns=240"

Freebsd

The default setting is suitable for very small installations (for example, the default SHMMAX is MB). We can use SYSCTL or loader interface to modify. The following parameters can be set with Sysctl:

$
 sysctl-w kern.ipc.shmall=32768

$ sysctl-w kern.ipc.shmmax=134217728
$ sysctl-w kern.ipc.semmap=256

To make these settings restart, modify the/etc/sysctl.conf.

If you use Sysctl, the remaining semaphore settings are read-only, but the semaphore can be set at the loader prompt at boot time:

(loader)
 Set kern.ipc.semmni=256

(loader) Set kern.ipc.semmns=512
(loader) Set kern.ipc.semmnu=256

Similarly, these things can be saved in/boot/loader.conf so that they are still valid after reboot.

You might also want to configure the kernel so that you can load shared memory into RAM to avoid swapping them into swap partitions. These can be implemented by using the SYSCTL setting Kern.ipc.shm_use_phys.

The FreeBSD version prior to 4.0 resembles NetBSD and OpenBSD (see below). NetBSD
Openbsd

You need to open the options Sysvshm and Sysvsem when compiling the kernel. (The default is open.) The maximum size of shared memory is the option Shmmaxpgs (in pages). An example of how to set these parameters is shown below (OpenBSD uses option):

Options         SYSVSHM
Options shmmaxpgs=4096
Options shmseg=256

Options Sysvsem
Options semmni=256
Options semmns=512
Options semmnu=256
Options semmap=256

You might want to use the SYSCTL setting to lock shared memory in RAM to prevent them from being swapped out, and we can use SYSCTL to set Kern.ipc.shm_use_phys to do this. HP-UX

The default setting appears to be sufficient for a normal installation. The factory default for HP-UX 10,semmns is 128, which may be too small for large database nodes.

IPC can be in System Administration Manager (System Manager) (sam ) The following Kernel Configuration->configurable Parameters configuration. After you configure, knock Create A New Kernel option.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.