Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux shmmax and shmall - how to set correct unit?

I have a server which has 16 GB memory.

Now I need to set my shmmax and shmall, because the server default is (checked with ipcs -l)

------ Messages Limits --------
max queues system wide = 32000
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 18014398509465599
max total shared memory (kbytes) = 18014398509465599
min seg size (bytes) = 1

------ Semaphore Limits --------
max number of arrays = 32000
max semaphores per array = 32000
max semaphores system wide = 1024000000
max ops per semop call = 500
semaphore max value = 32767

It seems terrible, shmall and shmmax is bigger than my 16 GB.

So I want to change the setting to

shmmax -> 16GB/4
shmall -> 16GB/2

But I can't be sure what unit I have set

shmmax --> 4420960256 
shmall --> 8620960256

But is the unit for my number? byte or KB? Because ipcs -l is showing KB....

echo "kernel.shmmax=4420960256" >> /etc/sysctl.conf
echo 4420960256> /proc/sys/kernel/shmmax
echo "kernel.shmall=8620960256" >> /etc/sysctl.conf
echo 8620960256> /proc/sys/kernel/shmall

thanks for help, but the postgresql just crash and get killed by yesterday, it shows :

This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 4420960256 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.

my setting =>

shared_buffers = 4GB
effective_cache_size = 12GB
like image 338
Frank Liao Avatar asked Sep 16 '25 22:09

Frank Liao


2 Answers

Just use:

lsipc

On my Ubuntu 16.04 LTS I get:

RESOURCE DESCRIPTION                                    LIMIT USED  USE%
MSGMNI   Number of message queues                       32000    0 0.00%
MSGMAX   Max size of message (bytes)                     8192    -     -
MSGMNB   Default max size of queue (bytes)              16384    -     -
SHMMNI   Shared memory segments                          4096   20 0.49%
SHMALL   Shared memory pages                          2097152 4915 0.23%
SHMMAX   Max size of shared memory segment (bytes) 4294967296    -     -
SHMMIN   Min size of shared memory segment (bytes)          1    -     -
SEMMNI   Number of semaphore identifiers                  128    0 0.00%
SEMMNS   Total number of semaphores                     32000    0 0.00%
SEMMSL   Max semaphores per semaphore set.                250    -     -
SEMOPM   Max number of operations per semop(2)            100    -     -
SEMVMX   Semaphore max value                            32767    -     -

which clearly states the measure unit for the values I have specified in /etc/sysctl.conf. So for me SHMMAX is in bytes while SHMALL in pages (see getconf PAGE_SIZE).

like image 52
adrhc Avatar answered Sep 18 '25 14:09

adrhc


Since PostgreSQL 9.3, PostgreSQL has been using anonymous shared memory rather than System V shared memory. So the rest of the answer only applies to older PostgreSQL releases.


Just leave the setting the way it is – essentially, that means “unlimited” in your case. One less limit you could bang your head against!

The amount of shared memory allocated by PostgreSQL is fixed and mostly determined by shared_buffers. Just make sure you don't set that to exceed your RAM (4GB would be perfect), and there is no danger whatsoever.

For the record: experimentation on my system shows that the unit of kernel.shmmax is bytes, while the unit of kernel.shmall is memory pages (check getconf PAGESIZE).

like image 29
Laurenz Albe Avatar answered Sep 18 '25 14:09

Laurenz Albe