Thread: shm

shm

From
Scott Ribe
Date:
What is POSIX shared memory used for anymore? Shared buffers now defaults to mmap, right? So when I run out of shm in
Kubernetesbecause of the 64MB limit, what is actually causing it to run out? 

(I know about creating the memory-based volume and mounting it at /dev/shm, and have implemented that workaround. Still
wantto know what is causing this memory use.) 

--
Scott Ribe
scott_ribe@elevated-dev.com
https://www.linkedin.com/in/scottribe/






Re: shm

From
Tom Lane
Date:
Scott Ribe <scott_ribe@elevated-dev.com> writes:
> What is POSIX shared memory used for anymore?

We still allocate a small shm block as a means of counting live backends
(since the SysV spec includes an "nattch" count but mmap'd segments do
not provide that info).  Should only be ~50 bytes though.

            regards, tom lane



Re: shm

From
Imre Samu
Date:
> So when I run out of shm in Kubernetes because of the 64MB limit, what is actually causing it to run out?

on (postgres) docker it is a frequent problem and documented .. and the result is a simple ERROR ...  :( 
"Also note that the default /dev/shm size for containers is 64MB. If the shared memory is exhausted you will encounter ERROR: could not resize shared memory segment . . . : No space left on device. You will want to pass --shm-size=256MB for example to docker run, or alternatively in docker-compose"

best,
 Imre

Scott Ribe <scott_ribe@elevated-dev.com> ezt írta (időpont: 2020. márc. 5., Cs, 15:43):
What is POSIX shared memory used for anymore? Shared buffers now defaults to mmap, right? So when I run out of shm in Kubernetes because of the 64MB limit, what is actually causing it to run out?

(I know about creating the memory-based volume and mounting it at /dev/shm, and have implemented that workaround. Still want to know what is causing this memory use.)

--
Scott Ribe
scott_ribe@elevated-dev.com
https://www.linkedin.com/in/scottribe/





Re: shm

From
Scott Ribe
Date:
> On Mar 5, 2020, at 7:51 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Scott Ribe <scott_ribe@elevated-dev.com> writes:
>> What is POSIX shared memory used for anymore?
>
> We still allocate a small shm block as a means of counting live backends
> (since the SysV spec includes an "nattch" count but mmap'd segments do
> not provide that info).  Should only be ~50 bytes though.
>
>             regards, tom lane

I recreated the error so I could post it here:

ERROR 53100 (disk_full) could not resize shared memory segment "/PostgreSQL.935653392" to 1048576 bytes: No space left
ondevice 

So something is using shared memory, and wants 1MB chunks. What could that be?




Re: shm

From
Scott Ribe
Date:
> On Mar 5, 2020, at 7:51 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> We still allocate a small shm block as a means of counting live backends
> (since the SysV spec includes an "nattch" count but mmap'd segments do
> not provide that info).  Should only be ~50 bytes though.

I recreated the error so I could post it here:

ERROR 53100 (disk_full) could not resize shared memory segment "/PostgreSQL.935653392" to 1048576 bytes: No space left
ondevice 

So something is using shared memory, and wants 1MB chunks. What could that be?

This is on PG 11.7




Re: shm

From
Tom Lane
Date:
Scott Ribe <scott_ribe@elevated-dev.com> writes:
>> On Mar 5, 2020, at 7:51 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> We still allocate a small shm block as a means of counting live backends
>> (since the SysV spec includes an "nattch" count but mmap'd segments do
>> not provide that info).  Should only be ~50 bytes though.

> I recreated the error so I could post it here:
> ERROR 53100 (disk_full) could not resize shared memory segment "/PostgreSQL.935653392" to 1048576 bytes: No space
lefton device 

Oh, if it's trying to resize then this is dynamic shared memory, not
the small static block.  On most platforms we use POSIX shm_open() for
that purpose, not SysV-style shm ... what have you got
dynamic_shared_memory_type set to?

It could be that the space limit applies to both APIs anyway, in which
case your choices are to raise the limit or disable parallel query.

            regards, tom lane



Re: shm

From
Scott Ribe
Date:
> On Mar 6, 2020, at 8:34 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Oh, if it's trying to resize then this is dynamic shared memory, not
> the small static block.  On most platforms we use POSIX shm_open() for
> that purpose, not SysV-style shm ... what have you got
> dynamic_shared_memory_type set to?

I just confirmed that it is POSIX. (I'm pretty sure we've never even considered changing the default.) So it would seem
that,in this context at least, the limit applies to it. And the context is containerized, Kubernetes, where there is no
optionto set the container's shm limit so we just have to use the shm mount trick. 

> It could be that the space limit applies to both APIs anyway, in which
> case your choices are to raise the limit or disable parallel query.

Well if it's coming from parallel query then I'm OK with the workaround. Primarily I wanted to make sure it wasn't
causedby something dumb/worthless that we should just not do. (For instance, for historical reasons, we are temporarily
runningwith max_connections way higher than is good practice...)