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.96) (envelope-from ) id 1w9XfB-001WXi-0H for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 00:17:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9Xe9-005eGi-2s for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 00:16:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w9Xe9-005eGa-1x for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 00:16:54 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w9Xe7-00000000lfw-37Ar for pgsql-hackers@postgresql.org; Mon, 06 Apr 2026 00:16:53 +0000 Received: from [10.0.2.15] (unknown [130.41.208.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4fpqdD3TL5zySb; Mon, 06 Apr 2026 03:16:48 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1775434609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=OfAhFycUyWmv+59+m48EUs5MMbNclQRiUOQ9i5Ee2e4=; b=UDLg1kgtEhV+hIlEVhqw4kkmpl8ZHwH0K3jAEjwCtViZL6MggSrBGGyNR4Yzv5RyovU7oo AEv8XzlhbBrsJMR4SVlFitY66X3cc8pQBLpwErbILx9FJqOnK7DOYhND7lVRdM5uR3fa6f ouaz/cAxslILSeeIGUXyFvwvJQbNz9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1775434609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=OfAhFycUyWmv+59+m48EUs5MMbNclQRiUOQ9i5Ee2e4=; b=iLATcuyXiEEeWKtqMJrk4vS2aF67lVoqRMn6/PBuM6eSa/GW3Nc89bPa1md3rYNfgcf1QX RYrL9hVoEYTMkcrfaAzitGdQr+i9CPzksm5DzZT3gXT/7ffFuBi/M3ihyrXqSRTwV35Uga PRgzjbm4vvAsEhJJ7+P6VEDAH8arKLU= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1775434609; b=QSEZU4zXq9675LJL6flPw1+Q0gUB1cS8tnQ3WuyY63NhcppkI03T7FiWh472ouXjLkt2gq 6aK86zDjUkGLXtJAS0OxgA/Pbu0x1rLnKBq52Q/3xmeAXkPYYf/Z9R/BrAAMiKmxTNjjOj L0Vv0h4H6RUoGg42/2VYZOtfi15YsA8= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Content-Type: multipart/mixed; boundary="------------rTMUnqaVxPwmOK9KowJHFH0z" Message-ID: <04b04387-92f5-476c-90b0-4064e71c5f37@iki.fi> Date: Mon, 6 Apr 2026 03:16:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Heikki Linnakangas Subject: Shmem allocated wrong for custom cumulative stats To: "pgsql-hackers@postgresql.org" Cc: Michael Paquier List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------rTMUnqaVxPwmOK9KowJHFH0z Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit There's only one call of ShmemAlloc() left in the tree outside shmem.c, in StatsShmemInit(), and that call doesn't look right: The StatsShmemSize() function takes those allocations into account when it calculates the size for the "Shared Memory Stats" shmem area, but ShmemAlloc() doesn't use that reservation, it uses the general-purpose unreserved shmem that then shows up as "" in pg_shmem_allocations. The space reserved with ShmemRequestStruct() / ShmemInitStruct() goes unused. We should use the memory that we've reserved, per the attached patch. One consequence of this fix though is that the allocations are now only MAXALIGNed, while ShmemAlloc() uses CACHELINEALIGN(). Not sure which we want. I noticed this while working on the new shmem allocation functions, but it's a pre-existing bug in stable branches too. - Heikki --------------rTMUnqaVxPwmOK9KowJHFH0z Content-Type: text/x-patch; charset=UTF-8; name="0001-Use-the-allocated-space-properly-for-custom-stats-ki.patch" Content-Disposition: attachment; filename*0="0001-Use-the-allocated-space-properly-for-custom-stats-ki.pa"; filename*1="tch" Content-Transfer-Encoding: base64 RnJvbSA2MmQ5YTJmYzhhNTY3NTFmY2Q4YThhYjc4MGRiNzc4MTM3NGRiNWYwIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBIZWlra2kgTGlubmFrYW5nYXMgPGhlaWtraS5saW5u YWthbmdhc0Bpa2kuZmk+CkRhdGU6IE1vbiwgNiBBcHIgMjAyNiAwMjo1NDoxOCArMDMwMApT dWJqZWN0OiBbUEFUQ0ggMS8xXSBVc2UgdGhlIGFsbG9jYXRlZCBzcGFjZSBwcm9wZXJseSBm b3IgY3VzdG9tIHN0YXRzIGtpbmQKCi0tLQogc3JjL2JhY2tlbmQvdXRpbHMvYWN0aXZpdHkv cGdzdGF0X3NobWVtLmMgfCA0ICsrKy0KIDEgZmlsZSBjaGFuZ2VkLCAzIGluc2VydGlvbnMo KyksIDEgZGVsZXRpb24oLSkKCmRpZmYgLS1naXQgYS9zcmMvYmFja2VuZC91dGlscy9hY3Rp dml0eS9wZ3N0YXRfc2htZW0uYyBiL3NyYy9i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