pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Curt Sampson <cjs@cynic.net>
Cc: Gregor Mosheh <stigmata@blackangel.net>
Cc: pgsql-admin@postgresql.org
Subject: Re: memory strangeness (fwd)
Date: Thu, 04 Jul 2002 23:18:22 -0400
Message-ID: <7780.1025839102@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.NEB.4.44.0207051104460.478-100000@angelic.cynic.net>
References: <Pine.NEB.4.44.0207051104460.478-100000@angelic.cynic.net>

Curt Sampson <cjs@cynic.net> writes:
>> I still cannot set PG's shared_buffers higher than 20000 (160 MB):

> Shared memory pages, IIRC, are locked, meaning that they cannot be
> swapped.

Is that really how it works on *BSD?  That's great if so --- it's
exactly what Postgres wants --- but you'll pardon my paranoia about
assuming that any part of the universe works the way I want it to...

There are Unixen that will happily swap shared-memory segments just
like anything else.  You don't have to think hard to see that this
would be a dead loss for Postgres' shared disk buffers.  For a clean
buffer page, if we don't have room for it we can:
  (a) drop it from shared mem, and re-read it from the database file
      next time we need it.  Cost: one disk read.
  (b) swap it out to swap area, and swap it in next time we need it.
      Cost: one disk write and one read.
For a dirty page that we no longer have room for, we can:
  (a) write it out to the database file and then drop it from shmem.
      Cost: one disk write, and possibly a disk read if we need
      the page again later.
  (b) swap it out to swap area, then sometime later swap it in so
      we can write it out to the database file.  Cost: two writes
      and a read.
So a swappable shared buffer always comes out behind.

The prospect of this effect is one of the reasons that I discourage
people from setting shared_buffers really high.  If their kernel
will let them set shared_buffers to a very large fraction of RAM,
it probably means that the kernel is willing to swap shared memory,
and so they are going to end up behind not ahead.

What's more, exactly the same analysis applies to other chunks of
memory that the kernel might choose to swap out, if it's forced to
because it's under memory pressure due to PG shared_buffers chewing
too much of system RAM.  Unless your swap disk is way faster than
your database disk, it's never a win to swap instead of sending
pages to their final resting place on the database disk.

Bottom line: you don't ever want to have PG shmem large enough that
it pushes the kernel into swapping.  Even if the kernel will lock
shmem into RAM, you can still lose due to swapping other stuff.
So I'm pretty conservative about how much of physical RAM to assign
to shared buffers.

			regards, tom lane





view thread (13+ messages)  latest in thread

Message-ID: <7780.1025839102@sss.pgh.pa.us>
Permalink:  ../7780.1025839102@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/7780.1025839102@sss.pgh.pa.us

 · 

reply

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-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cjs@cynic.net, stigmata@blackangel.net
  Subject: Re: memory strangeness (fwd)
  In-Reply-To: <7780.1025839102@sss.pgh.pa.us>
  References: <Pine.NEB.4.44.0207051104460.478-100000@angelic.cynic.net> <7780.1025839102@sss.pgh.pa.us>

* 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