Subject: Re: [vserver] Shared Memory
From: Herbert Poetzl <herbert@13thfloor.at>
Date: Thu, 29 Oct 2009 01:53:05 +0100

On Thu, Oct 29, 2009 at 01:20:12AM +0100, Holger Amann wrote:
> 
> Am 29.10.2009 um 01:00 schrieb Lukasz Czarnowski:
> 
> >I had the same experience with kernel 2.6.22.x-vs2.2.x and pgsql 8.1  
> >- shmem is counted several times.
> 
> I played with the shared memory example shown at [1] and it seems,  
> that in general everything is working fine, except Postgres.
> So, until someone is able to fix this, Linux vServer and Postgres ->  
> Don't do it! :(

> guest1:/# /etc/init.d/postgresql-8.4 start
> Starting PostgreSQL 8.4 database server: main.
> guest1:/# ipcs
> 
> ------ Shared Memory Segments --------
> key        shmid      owner      perms      bytes      nattch     status
> 
> ------ Semaphore Arrays --------
> key        semid      owner      perms      nsems
> 
> ------ Message Queues --------
> key        msqid      owner      perms      used-bytes   messages

okay, after rereading the entire thread twice, all
I can figure from the provided data is that postgresql
inside a guest does not (seem to?) create any shared
memory segments, while it happily creates a bunch of
them on the host, correct?

> guest1:/# ./shmserver
> 
> (from another console)
> guest1:~# ipcs
> 
> ------ Shared Memory Segments --------
> key        shmid      owner      perms      bytes      nattch     status
> 0x0000162e 65537      root      666        27         1
> 
> ------ Semaphore Arrays --------
> key        semid      owner      perms      nsems
> 
> ------ Message Queues --------
> key        msqid      owner      perms      used-bytes   messages
> 
> guest1:~# ./shmclient
> abcdefghijklmnopqrstuvwxyz

I also see (from your tests here) that creating and
using shared memory segments does work as expected
(at least it looks like to me) ... 

> q.e.d.

what was demonstrated here is beyond my imagination :)

the original posting was about some kind of memory
leakage related to shmem, but, judging from the output,
postgresql doesn't use shmem (inside a guest) at all?!

now, possible interpretations are:

 - shmem is allocated, but not shown for postgresql
   (sounds strange, but possible, but the shmserver
   test should face the very same issues, no?)

 - shmem is not allocated (because it fails for some
   reason) but accounted (that should show up in
   /proc/virtual/<xid>/limits under SHM)

 - postgresql does something differently inside a
   guest than on the host (for whatever reason) and
   thus, we end up with a different result
   (comparing strace -fF for similar, well known
   configurations should shed some light on that)

in any case, a test code/tool which actually shows
some 'wrong' behaviour would really help identifying
the problem (if there is any :) at hand ...

TIA,
Herbert

> [1] http://www.cs.cf.ac.uk/Dave/C/node27.html