Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8atu-003S88-IP for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 09:00:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v8ats-00BsqG-1w for pgsql-hackers@arkaria.postgresql.org; Tue, 14 Oct 2025 09:00:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8atr-00Bsq7-O6 for pgsql-hackers@lists.postgresql.org; Tue, 14 Oct 2025 09:00:56 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v8atp-0025WR-0p for pgsql-hackers@postgresql.org; Tue, 14 Oct 2025 09:00:56 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 8FF5761BF3; Tue, 14 Oct 2025 18:00:46 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 14 Oct 2025 18:00:45 +0900 From: torikoshia To: Rahila Syed Cc: PostgreSQL Hackers , Daniel Gustafsson Subject: Re: Enhancing Memory Context Statistics Reporting In-Reply-To: References: <54FAE93D-E156-4684-9352-1CEDE6BD4A1C@yesql.se> <5bxhxniyvjyfldi7yjxcnxkl3i2ghci2grjyeclrbkfqnyhowk@dfkqzbvtbpml> <3eb40b3e-45c7-426a-b7f8-81f7d05a9b53@oss.nttdata.com> <74105887-E4EF-4CA2-9F0A-3C0CE05BF632@yesql.se> <437100f2-dd86-42e6-830c-5ff413a25e8e@oss.nttdata.com> <2a796830-de2d-4030-b480-d673f6cc5d94@eisentraut.org> <02E42650-0C66-4B49-93CA-1B0A5B73E7FD@yesql.se> User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: torikoshia@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2025-10-09 17:43, Rahila Syed wrote: > Hi Torikoshia, > > Thank you for testing and reviewing the patch. > >> This issue occurs on my M1 Mac, but I couldn’t reproduce it on >> Ubuntu, >> so it might be environment-dependent. > >> Looking at the logs, Assert() is failing: >> >> 2025-10-07 08:48:26.766 JST [local] psql [23626] WARNING: 01000: >> >> server process 23646 is processing previous request >> 2025-10-07 08:48:26.766 JST [local] psql [23626] LOCATION: >> pg_get_process_memory_contexts, mcxtfuncs.c:476 >> TRAP: failed Assert("victim->magic == >> FREE_PAGE_SPAN_LEADER_MAGIC"), >> File: "freepage.c", Line: 1379, PID: 23626 >> 0 postgres 0x000000010357fdf4 >> ExceptionalCondition + 216 >> 1 postgres 0x00000001035cbe18 >> FreePageManagerGetInternal + 684 >> 2 postgres 0x00000001035cbb18 >> FreePageManagerGet + 40 >> 3 postgres 0x00000001035c84cc >> dsa_allocate_extended + 788 >> 4 postgres 0x0000000103453af0 >> pg_get_process_memory_contexts + 992 >> 5 postgres 0x0000000103007e94 >> ExecMakeFunctionResultSet + 616 >> 6 postgres 0x00000001030506b8 >> ExecProjectSRF + 304 >> 7 postgres 0x0000000103050434 >> ExecProjectSet + 268 >> 8 postgres 0x0000000103003270 >> ExecProcNodeFirst + 92 >> 9 postgres 0x0000000102ffa398 >> ExecProcNode + 60 >> 10 postgres 0x0000000102ff5050 >> ExecutePlan >> + 244 >> 11 postgres 0x0000000102ff4ee0 >> standard_ExecutorRun + 456 >> 12 postgres 0x0000000102ff4d08 >> ExecutorRun >> + 84 >> 13 postgres 0x0000000103341c84 >> PortalRunSelect + 296 >> 14 postgres 0x0000000103341694 >> PortalRun + >> 656 >> 15 postgres 0x000000010333c4bc >> exec_simple_query + 1388 >> 16 postgres 0x000000010333b5d0 >> PostgresMain + 3252 >> 17 postgres 0x0000000103332750 >> BackendInitialize + 0 >> 18 postgres 0x0000000103209e48 >> postmaster_child_launch + 456 >> 19 postgres 0x00000001032118c8 >> BackendStartup + 304 >> 20 postgres 0x000000010320f72c >> ServerLoop >> + 372 >> 21 postgres 0x000000010320e1e4 >> PostmasterMain + 6448 >> 22 postgres 0x0000000103094b0c main + >> 924 >> 23 dyld 0x0000000199dc2b98 start >> + >> 6076 >> >> Could you please check if you can reproduce this crash on your >> environment? > > I haven't been able to reproduce this issue on Ubuntu. A colleague > also tested it on their Mac > and didn't encounter the problem. I do have a fix in this area that I > believe should address an edge > case where data might be written to freed DSA memory. > > Kindly test using the v35 patch and let me know if you still see the > issue. Thanks for the update. v35 works fine on my environment. I ran the same test and haven’t encountered the crash anymore. The addition of the following code appears to have resolved the issue: +memstats_dsa_cleanup(char *key) +{ + MemoryStatsDSHashEntry *entry; + + entry = dshash_find(MemoryStatsDsHash, key, true); Since you seem to make a next version patch, I understand v35 is an interim patch, so this isn’t a major concern, but I encountered trailing whitespace warnings when applying the patches: $ git apply 0001-v35-0001-Add-pg_get_process_memory_context-function.patch 0001-v35-0001-Add-pg_get_process_memory_context-function.patch:705: trailing whitespace. 0001-v35-0001-Add-pg_get_process_memory_context-function.patch:1066: trailing whitespace. -- Regards, -- Atsushi Torikoshi Seconded from NTT DATA Japan Corporation to SRA OSS K.K.