Thread: overcommit_ratio setting

overcommit_ratio setting

From
Yi Sun
Date:
Hello,

After checking doc, only mentioned vm.overcommit_memory=2, but didn't mentioned vm.overcommit_ratio recommended value

https://www.postgresql.org/docs/11/kernel-resources.html#LINUX-MEMORY-OVERCOMMIT

some articles mentioned that 80 or 90 configuration in their env

So is it OK just to configure  vm.overcommit_ratio to 90 please?

Thank you

Re: overcommit_ratio setting

From
Julien Rouhaud
Date:
On Mon, Jun 14, 2021 at 06:16:35PM +0800, Yi Sun wrote:
> 
> So is it OK just to configure  vm.overcommit_ratio to 90 please?

This parameter entirely depends on the amount of RAM and swap you have on your
server, and how much memory you want to be allocable.

See https://www.kernel.org/doc/Documentation/vm/overcommit-accounting.

It's usually a good practice to not allow more than your RAM to be alloced, and
let a at least a bit of memory non allocable to make sure that you keep at
least some OS cache, but that's up to you.



Re: overcommit_ratio setting

From
Laurenz Albe
Date:
On Mon, 2021-06-14 at 18:16 +0800, Yi Sun wrote:
> After checking doc, only mentioned vm.overcommit_memory=2, but didn't mentioned vm.overcommit_ratio recommended
value
> https://www.postgresql.org/docs/11/kernel-resources.html#LINUX-MEMORY-OVERCOMMIT
> some articles mentioned that 80 or 90 configuration in their env
> So is it OK just to configure  vm.overcommit_ratio to 90 please?

It depends on the size of RAM and swap space:

overcommit_ratio < (RAM - swap) / RAM * 100

Here, RAM is the RAM available to PostgreSQL.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




Re: overcommit_ratio setting

From
Yi Sun
Date:

On Mon, 2021-06-14 at 18:16 +0800, Yi Sun wrote:
> After checking doc, only mentioned vm.overcommit_memory=2, but didn't mentioned vm.overcommit_ratio recommended value
> https://www.postgresql.org/docs/11/kernel-resources.html#LINUX-MEMORY-OVERCOMMIT
> some articles mentioned that 80 or 90 configuration in their env
> So is it OK just to configure  vm.overcommit_ratio to 90 please?

It depends on the size of RAM and swap space:

overcommit_ratio < (RAM - swap) / RAM * 100

Here, RAM is the RAM available to PostgreSQL.
 
Thank you for your reply

1. Our env RAM are 4GB, 8 GB, 16 GB... as below url suggestion, could we configure swap as below?

RAM                 swap

2GB – 8GB       = RAM
>8GB                8GB

2. If the RAM is 4GB and 8GB, the formula  (RAM - swap) / RAM * 100 result will become to 0, how could we configure overcommit_ratio please?

Thank you

Re: overcommit_ratio setting

From
Laurenz Albe
Date:
On Tue, 2021-06-15 at 08:34 +0800, Yi Sun wrote:
> > overcommit_ratio < (RAM - swap) / RAM * 100
> > 
> > Here, RAM is the RAM available to PostgreSQL.
> 
> Thank you for your reply
> 
> 1. Our env RAM are 4GB, 8 GB, 16 GB... as below url suggestion, could we configure swap as below?
> https://opensource.com/article/18/9/swap-space-linux-systems
> 
> RAM                 swap
> 
> 2GB – 8GB       = RAM
> >8GB                8GB

I wouldn't change the swap space to fit overcommit_ratio, but
the other way around.
With a properly configured PostgreSQL, you won't need a lot of swap space.

> 2. If the RAM is 4GB and 8GB, the formula  (RAM - swap) / RAM * 100 result will become to 0,
>    how could we configure overcommit_ratio please?

You have to use floating point arithmetic.

The result will only be 0 if RAM = swap.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




Re: overcommit_ratio setting

From
Yi Sun
Date:


Laurenz Albe <laurenz.albe@cybertec.at> 于2021年6月15日周二 下午3:07写道:
On Tue, 2021-06-15 at 08:34 +0800, Yi Sun wrote:
> > overcommit_ratio < (RAM - swap) / RAM * 100
> >
> > Here, RAM is the RAM available to PostgreSQL.
>
> Thank you for your reply
>
> 1. Our env RAM are 4GB, 8 GB, 16 GB... as below url suggestion, could we configure swap as below?
> https://opensource.com/article/18/9/swap-space-linux-systems
>
> RAM                 swap
>
> 2GB – 8GB       = RAM
> >8GB                8GB

I wouldn't change the swap space to fit overcommit_ratio, but
the other way around.
With a properly configured PostgreSQL, you won't need a lot of swap space.

> 2. If the RAM is 4GB and 8GB, the formula  (RAM - swap) / RAM * 100 result will become to 0,
>    how could we configure overcommit_ratio please?

You have to use floating point arithmetic.

The result will only be 0 if RAM = swap.

Got it, so should always use formula overcommit_ratio < (RAM - swap) / RAM * 100  regardless of the value

Our prd env RAM are 4GB, 8 GB, 16 GB..., some env configured swap, some env didn't configure swap
1. Is it OK if prd env didn't configure swap?
2. The linux OS is CentOS 7, what's the recommended value for swap setting based on different RAM please?

 Thank you