From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Out of Memory
Date: Sat, 29 Sep 2018 12:25:18 +0200
Message-ID: <20180929102518.rhz5o7wo3ner4zv6@hjp.at> (raw)
In-Reply-To: <a76a969d353eacf584d2018b3a2272a1143053e9.camel@cybertec.at>
References: <1537971881585-0.post@n3.nabble.com>
<3321.1537972628@sss.pgh.pa.us>
<1537973357976-0.post@n3.nabble.com>
<1537979068444-0.post@n3.nabble.com>
<1537979569920-0.post@n3.nabble.com>
<824208787ca76bb05c1076b72629e394c6ed660b.camel@cybertec.at>
<20180927063039.n5ea4xuefxtrbusa@squirrel.exwg.net>
<3973cda30071755051a8b63a1aa64727a5a79998.camel@cybertec.at>
<704B7535-D731-47EA-9E1E-2055B42CAD7B@gmail.com>
<a76a969d353eacf584d2018b3a2272a1143053e9.camel@cybertec.at>
On 2018-09-28 07:23:59 +0200, Laurenz Albe wrote:
> Rob Sargent wrote:
> > > Christoph Moench-Tegeder wrote:
> > > > ## Laurenz Albe (laurenz.albe@cybertec.at):
> > > >
> > > > > vm.overcommit_memory = 2
> > > > > vm_overcommit_ratio = 100
> > > > >
> > > > > Linux commits (swap * overcommit_ratio * RAM / 100),
> > > >
> > > > ^
> > > > That should be a "+".
> > >
> > > Yes; shame on me for careless typing, and thank you for the
> > > correction.
> >
> > Are there any parentheses needed in that formula?
>
> No. It is swap space plus a certain percentage of RAM.
>
> I don't know how the Linux developers came up with that
> weird formula.
I suspect they copied it from some other Unix.
Traditionally, Unix allocated all memory in the swap space. You could
say that the swap space was the "real memory" and RAM was a cache for
that (Hence the rule that swap must be at least as large as RAM and
should preferrably be 2 or 4 times the size of RAM). So, when Unixes
started to allow allocating more virtual memory than swap space, they
were "overcommitting".
But for Linux that doesn't make much sense, since a page lived either in
RAM /or/ in swap right from the start, so the limit was always RAM+swap,
not swap alone, and you are only overcommitting if you exceeded the size
of the sum. The overcommitment in Linux is of a different kind: Linux
uses copy on write whereever it can (e.g. when forking processes, but
also when mallocing memory), and a CoW page may or may not be written in
the future. It only needs additional space when it's actually written,
so by counting the page only once (hoping that there will be enough
space if and when that page is written) the kernel is overcommitting
memory.
hp
--
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | hjp@hjp.at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;
Attachments:
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: hjp-pgsql@hjp.at
Subject: Re: Out of Memory
In-Reply-To: <20180929102518.rhz5o7wo3ner4zv6@hjp.at>
References: <1537971881585-0.post@n3.nabble.com> <3321.1537972628@sss.pgh.pa.us> <1537973357976-0.post@n3.nabble.com> <1537979068444-0.post@n3.nabble.com> <1537979569920-0.post@n3.nabble.com> <824208787ca76bb05c1076b72629e394c6ed660b.camel@cybertec.at> <20180927063039.n5ea4xuefxtrbusa@squirrel.exwg.net> <3973cda30071755051a8b63a1aa64727a5a79998.camel@cybertec.at> <704B7535-D731-47EA-9E1E-2055B42CAD7B@gmail.com> <a76a969d353eacf584d2018b3a2272a1143053e9.camel@cybertec.at> <20180929102518.rhz5o7wo3ner4zv6@hjp.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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