pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
The right SHMMAX and FILE_MAX
8+ messages / 6 participants
[nested] [flat]

* The right SHMMAX and FILE_MAX
@ 2011-05-01 06:48 Phoenix Kiula <phoenix.kiula@gmail.com>
  2011-05-01 17:18 ` Re: The right SHMMAX and FILE_MAX Kevin Grittner <Kevin.Grittner@wicourts.gov>
  2011-05-01 19:38 ` Re: The right SHMMAX and FILE_MAX Greg Smith <greg@2ndQuadrant.com>
  2011-05-02 04:53 ` Re: The right SHMMAX and FILE_MAX Adarsh Sharma <adarsh.sharma@orkash.com>
  2011-05-02 09:06 ` Re: The right SHMMAX and FILE_MAX Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  0 siblings, 4 replies; 8+ messages in thread

From: Phoenix Kiula @ 2011-05-01 06:48 UTC (permalink / raw)
  To: pgsql-performance

Hi. I'm on a 64 Bit CentOS 5 system, quadcore processor, 8GB RAM and
tons of data storage (1 TB SATAII disks).

The current SHMMAX and SHMMIN are (commas added for legibility) --

kernel.shmmax = 68,719,476,736
kernel.shmall = 4,294,967,296

Now, according to my reading in the PG manual and this list, a good
recommended value for SHMMAX is

   (shared_buffers * 8192)

My postgresql.conf settings at the moment are:

    max_connections = 300
    shared_buffers = 300MB
    effective_cache_size = 2000MB

By this calculation, shared_b * 8192 will be:

     2,457,600,000,000

That's a humongous number. So either the principle for SHMMAX is
amiss, or I am reading this wrongly?

Similarly with "fs.file_max". There are articles like this one:
http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec72.html

Is this relevant for PostgreSQL performance at all, or should I skip that?

Thanks for any pointers!



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
@ 2011-05-01 17:18 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
  3 siblings, 0 replies; 8+ messages in thread

From: Kevin Grittner @ 2011-05-01 17:18 UTC (permalink / raw)
  To: Phoenix Kiula <phoenix.kiula@gmail.com>; pgsql-performance

Phoenix Kiula <phoenix.kiula@gmail.com> wrote:
 
> Now, according to my reading in the PG manual and this list, a
> good recommended value for SHMMAX is
> 
>    (shared_buffers * 8192)
 
Where did you see that?  The amount of data buffered is the number
of shared buffers * 8KB.  Taking shared_buffers as a number of bytes
and multiplying by 8K makes no sense at all.  Any documentation
which can be read to indicate that should be fixed.
 
Besides that, there is shared memory space needed besides the actual
buffered disk pages, so you're not looking at the whole picture once
you stop dealing with "bytes squared".
 
-Kevin



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
@ 2011-05-01 19:38 ` Greg Smith <greg@2ndQuadrant.com>
  3 siblings, 0 replies; 8+ messages in thread

From: Greg Smith @ 2011-05-01 19:38 UTC (permalink / raw)
  To: pgsql-performance

On 05/01/2011 02:48 AM, Phoenix Kiula wrote:
> Hi. I'm on a 64 Bit CentOS 5 system, quadcore processor, 8GB RAM and
> tons of data storage (1 TB SATAII disks).
>
> The current SHMMAX and SHMMIN are (commas added for legibility) --
>
> kernel.shmmax = 68,719,476,736
> kernel.shmall = 4,294,967,296
>    

That's set higher than the amount of RAM in the server.  Run the 
attached script; it will produce reasonable values for your server, 
presuming you'll never want to allocate >50% of the RAM in the server 
for shared memory.  Given standard tuning for shared_buffers is <40%, 
I've never run into a situation where this was a terrible choice if you 
want to just set and forget about it.  Only reason to fine-tine is if 
another major user of shared memory is running on the server

> Now, according to my reading in the PG manual and this list, a good
> recommended value for SHMMAX is
>
>     (shared_buffers * 8192)
>    

The value for shared_buffers stored internally is in 8192 byte pages:

select setting,unit,current_setting(name) from pg_settings where 
name='shared_buffers';
  setting | unit | current_setting
---------+------+-----------------
  4096    | 8kB  | 32MB

So any formula you found that does this sort of thing is just converting 
it back to bytes again, and is probably from an earlier PostgreSQL 
version where you couldn't set this parameter in memory units.  SHMMAX 
needs to be a bit bigger than shared_buffers in bytes.

> Similarly with "fs.file_max". There are articles like this one:
> http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec72.html
> Is this relevant for PostgreSQL performance at all, or should I skip that?
>    

That's ancient history.  This is how big the default is on the two Linux 
distributions I have handy:

[RHEL5]
$ cat /proc/sys/fs/file-max
745312

[Debian Squeeze]
$ cat /proc/sys/fs/file-max
1645719

It was a tiny number circa the RedHat 6 that manual was written for, now 
it's very unlikely you'll exceed the kernel setting here.

-- 
Greg Smith   2ndQuadrant US    greg@2ndQuadrant.com   Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support  www.2ndQuadrant.us
"PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books

Attachments:

shmsetup (text/plain, 914B) download #!/bin/bash # Output lines suitable for sysctl configuration based # on total amount of RAM on the system. The output # will allow up to 50% of physical memory to be allocated # into shared memory. # On Linux, you can use it as follows (as root): # # ./shmsetup >> /etc/sysctl.conf # sysctl -p # Early FreeBSD versions do not support the sysconf interface # used here. The exact version where this works hasn't # been confirmed yet. page_size=`getconf PAGE_SIZE` phys_pages=`getconf _PHYS_PAGES` if [ -z "$page_size" ]; then echo Error: cannot determine page size exit 1 fi if [ -z "$phys_pages" ]; then echo Error: cannot determine number of memory pages exit 2 fi shmall=`expr $phys_pages / 2` shmmax=`expr $shmall \* $page_size` echo \# Maximum shared segment size in bytes echo kernel.shmmax = $shmmax echo \# Maximum number of shared memory segments in pages echo kernel.shmall = $shmall
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
@ 2011-05-02 04:53 ` Adarsh Sharma <adarsh.sharma@orkash.com>
  2011-05-02 10:50   ` Re: The right SHMMAX and FILE_MAX Tomas Vondra <tv@fuzzy.cz>
  2011-05-02 15:18   ` Re: The right SHMMAX and FILE_MAX Greg Smith <greg@2ndQuadrant.com>
  3 siblings, 2 replies; 8+ messages in thread

From: Adarsh Sharma @ 2011-05-02 04:53 UTC (permalink / raw)
  To: pgsql-performance

I am also in need of a proper documentation that explains how to set  
SHMAX and SHMALL variables in Postgres.

What things need to be taken in consideration before doing that ?
What is the value of SHMAX & SHMALL if u have 16 GB RAM for Postgres 
Server ?



Thanks

Phoenix Kiula wrote:
> Hi. I'm on a 64 Bit CentOS 5 system, quadcore processor, 8GB RAM and
> tons of data storage (1 TB SATAII disks).
>
> The current SHMMAX and SHMMIN are (commas added for legibility) --
>
> kernel.shmmax = 68,719,476,736
> kernel.shmall = 4,294,967,296
>
> Now, according to my reading in the PG manual and this list, a good
> recommended value for SHMMAX is
>
>    (shared_buffers * 8192)
>
> My postgresql.conf settings at the moment are:
>
>     max_connections = 300
>     shared_buffers = 300MB
>     effective_cache_size = 2000MB
>
> By this calculation, shared_b * 8192 will be:
>
>      2,457,600,000,000
>
> That's a humongous number. So either the principle for SHMMAX is
> amiss, or I am reading this wrongly?
>
> Similarly with "fs.file_max". There are articles like this one:
> http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec72.html
>
> Is this relevant for PostgreSQL performance at all, or should I skip that?
>
> Thanks for any pointers!
>
>   




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
  2011-05-02 04:53 ` Re: The right SHMMAX and FILE_MAX Adarsh Sharma <adarsh.sharma@orkash.com>
@ 2011-05-02 10:50   ` Tomas Vondra <tv@fuzzy.cz>
  2011-05-02 11:01     ` Re: The right SHMMAX and FILE_MAX Adarsh Sharma <adarsh.sharma@orkash.com>
  1 sibling, 1 reply; 8+ messages in thread

From: Tomas Vondra @ 2011-05-02 10:50 UTC (permalink / raw)
  To: pgsql-performance

Dne 2.5.2011 06:53, Adarsh Sharma napsal(a):
> I am also in need of a proper documentation that explains how to set 
> SHMAX and SHMALL variables in Postgres.
> 
> What things need to be taken in consideration before doing that ?
> What is the value of SHMAX & SHMALL if u have 16 GB RAM for Postgres
> Server ?

Well, those two values actually define kernel limits for shared memory
segments (i.e. memory shared by multiple processes, in this case the
postmaster proces and backends). So it's rather a question of tuning
shared_buffers (because that's the shared memory segment) and then
setting those two values.

SHMMAX - max. size of a single shared segment (in bytes)
SHMALL - total size of shared segments (in pages, page is usually 4kB)

So if you decide you want 1GB shared buffers, you'll need at least this

SHMMAX = 1024 * 1024 * 1024 (i.e. 1GB)
SHMALL = 1024 * 256 (1GB in 4kB pages)

(althouth the SHMALL should be higher, as there will be other processes
that need shared memory).

There's a lot of docs about this, e.g. this one (it's mostly for Oracle,
but it describes the shared memory quite nicely):

http://www.puschitz.com/TuningLinuxForOracle.shtml#SettingSharedMemory

regards
Tomas



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
  2011-05-02 04:53 ` Re: The right SHMMAX and FILE_MAX Adarsh Sharma <adarsh.sharma@orkash.com>
  2011-05-02 10:50   ` Re: The right SHMMAX and FILE_MAX Tomas Vondra <tv@fuzzy.cz>
@ 2011-05-02 11:01     ` Adarsh Sharma <adarsh.sharma@orkash.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Adarsh Sharma @ 2011-05-02 11:01 UTC (permalink / raw)
  To: Tomas Vondra <tv@fuzzy.cz>; +Cc: pgsql-performance

Tomas Vondra wrote:
> Dne 2.5.2011 06:53, Adarsh Sharma napsal(a):
>   
>> I am also in need of a proper documentation that explains how to set 
>> SHMAX and SHMALL variables in Postgres.
>>
>> What things need to be taken in consideration before doing that ?
>> What is the value of SHMAX & SHMALL if u have 16 GB RAM for Postgres
>> Server ?
>>     
>
> Well, those two values actually define kernel limits for shared memory
> segments (i.e. memory shared by multiple processes, in this case the
> postmaster proces and backends). So it's rather a question of tuning
> shared_buffers (because that's the shared memory segment) and then
> setting those two values.
>   

When I was tuning Postgresql for best Performance, I set my 
shared_buffers= 4096 MB as I set 25% of RAM ( 1/4 )

So Do I need to set my SHMMAX =4096 MB.

What is the SHMALL size now ?

> SHMMAX - max. size of a single shared segment (in bytes)
> SHMALL - total size of shared segments (in pages, page is usually 4kB)
>
> So if you decide you want 1GB shared buffers, you'll need at least this
>
> SHMMAX = 1024 * 1024 * 1024 (i.e. 1GB)
> SHMALL = 1024 * 256 (1GB in 4kB pages)
>
> (althouth the SHMALL should be higher, as there will be other processes
> that need shared memory).
>
> There's a lot of docs about this, e.g. this one (it's mostly for Oracle,
> but it describes the shared memory quite nicely):
>
> http://www.puschitz.com/TuningLinuxForOracle.shtml#SettingSharedMemory
>
> regards
> Tomas
>
>   

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
  2011-05-02 04:53 ` Re: The right SHMMAX and FILE_MAX Adarsh Sharma <adarsh.sharma@orkash.com>
@ 2011-05-02 15:18   ` Greg Smith <greg@2ndQuadrant.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Greg Smith @ 2011-05-02 15:18 UTC (permalink / raw)
  To: pgsql-performance

On 05/02/2011 12:53 AM, Adarsh Sharma wrote:
> I am also in need of a proper documentation that explains how to set  
> SHMAX and SHMALL variables in Postgres.
>
> What things need to be taken in consideration before doing that ?
> What is the value of SHMAX & SHMALL if u have 16 GB RAM for Postgres 
> Server ?

Running the script I provided on a Linux server with 16GB of RAM:

$ cat /proc/meminfo | grep MemTotal
MemTotal:       16467464 kB

$ getconf PAGE_SIZE
4096

$ ./shmsetup
# Maximum shared segment size in bytes
kernel.shmmax = 8431341568
# Maximum number of shared memory segments in pages
kernel.shmall = 2058433

That sets SHMMAX to 50% of total RAM, which should be sufficient for any 
reasonable installation of PostgreSQL.  shmmall is a similar limit 
expressed in system pages instead, so as seen here you have to divide by 
the system page size of 4096 to figure it out.

-- 
Greg Smith   2ndQuadrant US    greg@2ndQuadrant.com   Baltimore, MD
PostgreSQL Training, Services, and 24x7 Support  www.2ndQuadrant.us
"PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: The right SHMMAX and FILE_MAX
  2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
@ 2011-05-02 09:06 ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
  3 siblings, 0 replies; 8+ messages in thread

From: Mark Kirkwood @ 2011-05-02 09:06 UTC (permalink / raw)
  To: pgsql-performance

On 01/05/11 18:48, Phoenix Kiula wrote:
> Now, according to my reading in the PG manual and this list, a good
> recommended value for SHMMAX is
>
>     (shared_buffers * 8192)
>
> My postgresql.conf settings at the moment are:
>
>      max_connections = 300
>      shared_buffers = 300MB
>      effective_cache_size = 2000MB
>
> By this calculation, shared_b * 8192 will be:
>
>       2,457,600,000,000
>
> That's a humongous number. So either the principle for SHMMAX is
> amiss, or I am reading this wrongly?

You are confusing shared_buffers expressed as "number of pages" with 
shared_buffers expressed as "MB". The docs are assuming you are working 
with the former (and would appear to be assuming your pagesize is 8K - 
which is teh default but not required to be the case). If you are 
showing shared_buffers as "MB" then obviously you cane set SHMMAX using 
the value multiplied by (1024*1024), so in your case:

300 * (1024*1024) = 314572800


However note that there are things other than shared_buffers require 
shared memory, so you'll need more than this. Use Greg's script.

Cheers

Mark



^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2011-05-02 15:18 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-05-01 06:48 The right SHMMAX and FILE_MAX Phoenix Kiula <phoenix.kiula@gmail.com>
2011-05-01 17:18 ` Kevin Grittner <Kevin.Grittner@wicourts.gov>
2011-05-01 19:38 ` Greg Smith <greg@2ndQuadrant.com>
2011-05-02 04:53 ` Adarsh Sharma <adarsh.sharma@orkash.com>
2011-05-02 10:50   ` Tomas Vondra <tv@fuzzy.cz>
2011-05-02 11:01     ` Adarsh Sharma <adarsh.sharma@orkash.com>
2011-05-02 15:18   ` Greg Smith <greg@2ndQuadrant.com>
2011-05-02 09:06 ` Mark Kirkwood <mark.kirkwood@catalyst.net.nz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox