shm

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

shm

Scott Ribe-2
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
[hidden email]
https://www.linkedin.com/in/scottribe/





Reply | Threaded
Open this post in threaded view
|

Re: shm

Tom Lane-2
Scott Ribe <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: shm

Imre Samu
In reply to this post by Scott Ribe-2
> 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 <[hidden email]> 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
[hidden email]
https://www.linkedin.com/in/scottribe/





Reply | Threaded
Open this post in threaded view
|

Re: shm

Scott Ribe-2
In reply to this post by Tom Lane-2
> On Mar 5, 2020, at 7:51 AM, Tom Lane <[hidden email]> wrote:
>
> Scott Ribe <[hidden email]> 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 on device

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



Reply | Threaded
Open this post in threaded view
|

Re: shm

Scott Ribe-2
In reply to this post by Tom Lane-2
> On Mar 5, 2020, at 7:51 AM, Tom Lane <[hidden email]> 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 on device

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

This is on PG 11.7



Reply | Threaded
Open this post in threaded view
|

Re: shm

Tom Lane-2
Scott Ribe <[hidden email]> writes:
>> On Mar 5, 2020, at 7:51 AM, Tom Lane <[hidden email]> 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 on 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


Reply | Threaded
Open this post in threaded view
|

Re: shm

Scott Ribe-2
> On Mar 6, 2020, at 8:34 AM, Tom Lane <[hidden email]> 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 option to 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 caused by something dumb/worthless that we should just not do. (For instance, for historical reasons, we are temporarily running with max_connections way higher than is good practice...)