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 1w0lb3-002Bt9-2i for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 19:21:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0lb2-00GuxT-0p for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 19:21:24 +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 1w0lb1-00GuxK-37 for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2026 19:21:24 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w0lb0-00000001ohE-1ddu for pgsql-hackers@postgresql.org; Thu, 12 Mar 2026 19:21:23 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (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 lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4fWyCN1s1Hz49RGC; Thu, 12 Mar 2026 21:21:20 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1773343280; 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=JXtx7TZKGWdYmSooEk/4lTEt0sU8Prte6eKDFtvoTvA=; b=h6QZVToBa+FvRiNTNL2tHwXxpS3IqUs7eIliTOmQ0ksVf2/rjjwKQyvT+pi4Y0ZkWbdfCj 9RUg3ZM2W0i4ZHFvzjY4e1tpnKqgGjrzzih0wD4Q8ZSq7ZEA1ZWnozioI8T0WvP/+6G7YY phlMsS7GbESpGzdLNsGr/hyZzfw/bRAlZc54DPwYpE4V6ZJJzGlK56lIJByOn5vLslYexF rGevYSLgzT94LxWJafLQJDu5OZHeUuE1d+vJvvPovr4wyAiSDikJknmEdFXCWT5HDHRMDM qMtS2u1wyfUJ4IvfrdoR+v+e4Zb3SrubiY3VHLfSz+IRaYIBrSTraRT/W6ATJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1773343280; 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=JXtx7TZKGWdYmSooEk/4lTEt0sU8Prte6eKDFtvoTvA=; b=NGZSVVNmN7YYCc5gpnFgGetTAnsovw9ngUNN0+pxEXD8KVITyM4bEq5I1A/hGz+I7VS2pb /D2vEEc/OLSs4mrIj1ZCg+hMBF77MsyS63CHrjcMcMIfPXYrEXpm8ZNsT1MytzUyoioglO WQ9ZxXQaO6EOQ9N6UkY8hkS68ZriOMm6jcKbwXYEpJojhLHsMewoylwHji8U2WoA3vi2RU YdejQYPtVtjJzRr5Wd2SPmy8pwS/hOyo9gEKpdLBIMWSp0SgYGOCMqLsfqrj+LvUmYZTBV hQNWRP6fDP4An9opaudPU3Z/auXdy2BisSObmugfQ6wtjUf7io9XsyKTKG1HMA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1773343280; b=CcctEhpOeJx7ZrceGBpKDkH4cDd7NPRN4x5h4mrchVyLT8h994GeiFl8CyKvVfA7ZjTEI6 cN73k3Cw2tgioVrMof7XCEUFvU5WqOQh9yqtvPHCnopieDU6ZSubYKaUEgpIbosXBXG5yH PZTD5mMXEhii3VBQEEmdrvALaghOHKsdWTDe2oSLMzBUcmtwMGd6lxulv2hs9rti7e3uqE F2+XiHcSYYJuvgtRGn90/SsGYVow0/D5tZ64FQn/PaZquNuEQN8HJPBauvntytMy3R5nXh PCmLObW54Y+91esmDLpfd+UntO4oUJm5aNyamkTdIeKc0vfnt57SLoi+n9rlOA== Message-ID: Date: Thu, 12 Mar 2026 21:21:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Better shared data structure management and resizable shared data structures To: Robert Haas Cc: Ashutosh Bapat , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com References: <5a37c2e3-619d-4816-84d7-0b27e3e6797f@iki.fi> <26c766d6-db0f-43d3-a618-44f8d40a3121@iki.fi> <62b8dc23-8f6a-4cac-91ff-f74bb5bc159a@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/03/2026 20:56, Robert Haas wrote: > On Thu, Mar 12, 2026 at 2:41 PM Heikki Linnakangas wrote: >> shmem_startup_hook() is too late. The shmem structs need to be >> registered at postmaster startup before the shmem segment is allocated, >> so that we can calculate the total size needed. > > Sorry, I meant shmem_request_hook. Ah ok >> I'm currently leaning towards _PG_init(), except for allocations that >> depend on MaxBackends. For those, you can install a shmem_request_hook >> that sets the size in the descriptor. In other words, you can leave the >> 'size' as empty in _PG_init(), but set it later in the shmem_request_hook. > > Why can't you just do the whole thing later? shmem_request_hook won't work in EXEC_BACKEND mode, because in EXEC_BACKEND mode, ShmemRegisterStruct() also needs to be called at backend startup. One of my design goals is to avoid EXEC_BACKEND specific steps so that if you write your extension oblivious to EXEC_BACKEND mode, it will still usually work with EXEC_BACKEND. For example, if it was necessary to call a separate AttachShmem() function for every shmem struct in EXEC_BACKEND mode, but which was not needed on Unix, that would be bad. >> Except that you'd still need them for RequestNamedLWLockTranche(). I >> wonder if we should recommend extensions to embed the LWLock struct into >> their shared memory struct and use the LWLockInitialize() and >> LWLockNewTrancheId() functions instead. That fits the new >> ShmemRegisterStruct() API a little better than RequestNamedLWLockTranche(). > > Yeah, I think RequestNamedLWLockTranche() might be fine if you just > need LWLocks, but if you need a bunch of resources, putting them all > into the same chunk of memory seems cleaner. Agreed. Then again, how often do you need just a LWLock (or multiple LWLocks)? Surely you have a struct you want to protect with the lock. I guess having shmem hash table but no struct would be pretty common, though. - Heikki