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 1u00LB-009tqx-EJ for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Apr 2025 15:49:21 +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 1u00L9-00F6Cj-FK for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Apr 2025 15:49:19 +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.94.2) (envelope-from ) id 1u00L9-00F6C3-1E for pgsql-hackers@lists.postgresql.org; Wed, 02 Apr 2025 15:49:19 +0000 Received: from relay9-d.mail.gandi.net ([2001:4b98:dc4:8::229]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u00L6-002Zj6-2K for pgsql-hackers@postgresql.org; Wed, 02 Apr 2025 15:49:17 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 16ADD442BD; Wed, 2 Apr 2025 15:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vondra.me; s=gm1; t=1743608949; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5N24SLjfkoiFL7dDJkuzNDMvbVmYyjQp9WdI64AwWig=; b=m0zfexolJsxRzMhzuZZ3dKRwi0nSfSSqrlCZ+pD1OcqZfAtebJvu8856kl7Rm5KZC9i9C5 zX69hsR7UzFMyrNkcnD0pIPYaU7c1N1zrpxgKRpakAXSS2ujmWm7xVg7wiyxVupVb7nTog FfajrsYfuOTUdsMDxlVWapI/dvkYUlKIPSbtmGw8vgtGjzu8YqBsPoK3Uskes2ElgIcUDt x+O+7qhg4r1vAhoitngnORo1zedBNpIWnPsgxd/lMTlLSVc9UL9/mhO8++hOX1//K5fgCZ iaikLW4hNR+iphVyGU50f9AtC/sduiDjprqsxWebV4fomG+JIlklzU0oyYztXw== Message-ID: <4e9a124d-29cb-4fd5-99fb-a5016e508f20@vondra.me> Date: Wed, 2 Apr 2025 17:49:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Improve monitoring of shared memory allocations To: Rahila Syed Cc: Nazir Bilal Yavuz , Andres Freund , PostgreSQL-development References: <3e40eeec-d8bf-4496-854e-485dd901f6a2@vondra.me> <6bf7194e-4c34-4e6d-8215-f6acf8903974@vondra.me> <6705dbd2-060b-4f3c-9fcb-1c7f10880b26@vondra.me> <66283922-0448-44e7-bbdd-38aaf2be34b9@vondra.me> <7987a0b5-9933-457a-b5ba-d28e9cce883b@vondra.me> Content-Language: en-US From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeeitdeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomhepvfhomhgrshcugghonhgurhgruceothhomhgrshesvhhonhgurhgrrdhmvgeqnecuggftrfgrthhtvghrnhepledugeeikefglefhgfffuedvleetteevgefhvdeikeefudduuddvhfevudefhfevnecukfhppeekiedrgeelrddvvdelrdduleefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeeirdegledrvddvledrudelfedphhgvlhhopegluddtrddufeejrddtrddvngdpmhgrihhlfhhrohhmpehtohhmrghssehvohhnughrrgdrmhgvpdhnsggprhgtphhtthhopeegpdhrtghpthhtoheprhgrhhhilhgrshihvgguledtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepsgihrghvuhiikedusehgmhgrihhlrdgtohhmpdhrtghpthhtoheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-GND-Sasl: tomas@vondra.me List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks! I've pushed the first two parts, improving the shmem accounting. I've done a couple additional adjustments before commit, namely: 1) I've renamed hash_get_init_size() to just hash_get_size(). We've not indicated that it's "initial" allocation before, I don't think we need to indicate to do that now. So I've just removed the "shared" part, as that's no longer relevant. 2) I've removed one of the compute_buckets_and_segs() in hash_create, because AFAICS we don't need to recalculate the nsegs - we already have the correct value in the hctl, so I just used that. The fact that we call compute_buckets_and_segs() in multiple places, relying on getting the exact same result seemed a bit fragile to me. With this we now have just two callers (instead of 3), and I don't think we can do better - the first call is in hash_get_size(), and I don't see a convenient way to pass the info init_hash() where we do the 2nd call. 3) In 0002, I've reworked how ProcGlobalShmemSize() calculates the size of the required memory - the earlier patch added PGProcShmemSize(), but the ProcGlobalShmemSize() redid the calculation all over. I changed that to call the new function, and also added a new FastPathLockShmemSize() to do the same for the fast-path lock arrays (which I realized is now allocated as a separate area, so it'll be shown separately). 4) I realized PGProcShmemSize() did the calculation slightly differently from ProcGlobalShmemSize() - by directly multiplying the values, not using mul_size(). I don't recall why we use mul_size(), but it seems like the "usual" way. So I did it that way. I notice we still do the plain multiplication later when setting the ProcGlobal fields. Seems a bit weird, but we always did that - the patch does not really change that. I'll now mark this as committed. I haven't done about the alignment. My conclusion from the discussion was we don't quite need to do that, but if we do I think it's a matter for a separate patch - perhaps something like the 0003. Thanks for the patch, reviews, etc. -- Tomas Vondra