Re: can shared cache be swapped to disk? - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: can shared cache be swapped to disk?
Date
Msg-id 20101219141425.GA22685@svana.org
Whole thread Raw
In response to Re: can shared cache be swapped to disk?  (Jeff Janes <jeff.janes@gmail.com>)
Responses Re: can shared cache be swapped to disk?  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-hackers
On Sat, Dec 18, 2010 at 11:59:33PM -0800, Jeff Janes wrote:
> On Sat, Dec 18, 2010 at 10:11 PM, flyusa2010 fly <flyusa2010@gmail.com> wrote:
> > hi, folks!
> > I see that shared cache is implemented by system v shared memory. I wonder
> > whether data in this area can be swapped out to disk.
> > Isn't it bad that we read data from disk, put data in shared cache, and
> > finally data in shared cache is swapped to disk again!
> > Why not use shmctl(..SHM_LOCK..) to pin data in main memory?
> > Thanks!
>
> I've tried that on a recent linux kernel, to see if it would allow
> shared_buffers to usefully be a large fraction of total memory.  It
> didn't help.  So either swapping wasn't the problem in the first
> place, or the kernel ignores the order.

Correct. The kernel ignores locking requests because it's a great way
to DOS a machine. For example, mlock() of large blocks of memory is
also not permitted for similar reasons.

The way you make sure shared memory doesn't get swapped out is to make
sure it gets used. (i.e. don't give 2GB shared memory when your
database is 100MB). And don't make your shared memory so large that
you're creating significant memory pressure, otherwise the kernel might
choose to swap our your shared memory rather than say the webserver.

Your shared memory should be reasonably sized, but you should make sure
the kernel has enough "cache" memory it can throw away first.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patriotism is when love of your own people comes first; nationalism,
> when hate for people other than your own comes first.
>                                       - Charles de Gaulle

pgsql-hackers by date:

Previous
From: "Florian Pflug"
Date:
Subject: Re: serializable lock consistency
Next
From: Robert Haas
Date:
Subject: Re: Extensions and custom_variable_classes (was: Extensions, patch v20 (bitrot fixes))