Shared memory leak on DSM slot exhaustion

Started by Thomas Munroover 6 years ago3 messageshackers
Jump to latest
#1Thomas Munro
thomas.munro@gmail.com

Hello,

As reported over on pgsql-general[1]/messages/by-id/CA+hUKG+zw87b70yJp+Ozz6LqS6s9QvdO4+hQuZc=DWLMi6Od6A@mail.gmail.com, we leak shared memory when we
run out of DSM slots. To see this, add the random-run-out-of-slots
hack I showed in that thread, create and analyze a table t(i) with a
million integers, run with dynamic_shared_memory_type=mmap, and try
SELECT COUNT(*) FROM t t1 JOIN t t2 USING (i) a few times and you'll
see that pgbase/pg_dynshmem fills up with leaked memory segments each
time an out-of-slots errors is raised. (It happens with all DSM
types, but then the way to list the segments varies or there isn't
one, depending on type and OS.) Here's a draft patch to fix that.

[1]: /messages/by-id/CA+hUKG+zw87b70yJp+Ozz6LqS6s9QvdO4+hQuZc=DWLMi6Od6A@mail.gmail.com

Attachments:

0001-Fix-memory-leak-on-DSM-slot-exhaustion.patchapplication/octet-stream; name=0001-Fix-memory-leak-on-DSM-slot-exhaustion.patchDownload+8-10
#2Robert Haas
robertmhaas@gmail.com
In reply to: Thomas Munro (#1)
Re: Shared memory leak on DSM slot exhaustion

On Thu, Jan 30, 2020 at 4:54 AM Thomas Munro <thomas.munro@gmail.com> wrote:

As reported over on pgsql-general[1], we leak shared memory when we
run out of DSM slots. To see this, add the random-run-out-of-slots
hack I showed in that thread, create and analyze a table t(i) with a
million integers, run with dynamic_shared_memory_type=mmap, and try
SELECT COUNT(*) FROM t t1 JOIN t t2 USING (i) a few times and you'll
see that pgbase/pg_dynshmem fills up with leaked memory segments each
time an out-of-slots errors is raised. (It happens with all DSM
types, but then the way to list the segments varies or there isn't
one, depending on type and OS.) Here's a draft patch to fix that.

Whoops. The patch looks OK to me.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#3Thomas Munro
thomas.munro@gmail.com
In reply to: Robert Haas (#2)
Re: Shared memory leak on DSM slot exhaustion

On Sat, Feb 1, 2020 at 7:37 AM Robert Haas <robertmhaas@gmail.com> wrote:

Whoops. The patch looks OK to me.

Pushed.