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 1w2T48-000JdI-05 for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Mar 2026 11:58:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2T46-000r3J-34 for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Mar 2026 11:58:26 +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.96) (envelope-from ) id 1w2T46-000r3A-22 for pgsql-hackers@lists.postgresql.org; Tue, 17 Mar 2026 11:58:26 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w2T40-00000000b5L-2nMM for pgsql-hackers@postgresql.org; Tue, 17 Mar 2026 11:58:26 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-439b94a19fdso5151640f8f.0 for ; Tue, 17 Mar 2026 04:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773748699; cv=none; d=google.com; s=arc-20240605; b=JANFLW5fe2ogetjvn8rMqfBkEggr5VNNQaA/6+e+aVsOOyHneBC+34lzuQ4veRCAWo Rfg3vJzWV1DaFR/NSew5d2dCQ5vEuJC5cKhlqULACj5x2b3yDxPq9i+rWFGlgLfy5AaA XKx8vTJ4PL9ska49B5YW7cL5KUCelNC3+0JXfP3DMzPrBAW/wwKPEaJpUHMozlQR//FH o3mqK9Em+5zPuKS5Z7vxmvZUEsF2mJJCA3P/S5QUaZSv3m7ukC5ZLPxiu5wAFMTqRtd3 pDBQT/REI8vweANCgt87/B9r/eN3A59vEVWZIhurWOO3sizW+De6WJuhLpYJ80XOMquW ySgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=THWV8AkTQl5ICOeAjHO3xAofohI9LBMgOocyPIA+pq8=; fh=SzBqUXpxfjAvNhSNnkR3lIr+s41HlEjLSdnUy76GMIM=; b=O3GCveycRRWXsO35M317fQ3v9XsUCcK3vYnVmsHiQhuSoRiEUB1KmDgJ6qix/V8ngk EfbRdG83VUVhyMFSAOMQ5onShoSbbh4kVXiI1z4kHqfTF3KoeTMN6l0oLnHrFEloVojd feS11Gx2+sahJNxsooZ70azTMYnGFM5MJIkTJywiS4MJpRfTCFhLDhuaBXWRi6FTOuGq D1KvKFx46mlaVZwdWy29oOLBeTrDZwrOwm+Qe/vsrCiRzhffQSTWHbBlErZ5XOs12Phh L47zil0ySwIjhVfcWb7NSrNnVD9BBHla/FDoQ0CNIUC6ZHUmmquq3GEd6IMe2g6aRxLW jNkg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773748699; x=1774353499; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=THWV8AkTQl5ICOeAjHO3xAofohI9LBMgOocyPIA+pq8=; b=VvD0fIFRD+nc2+OCTwPIC5HLQRQWHegYST1GovR36f6xS4V7S6TM26OOzNcCXRhqvJ fzUwFg7P/UnGvo5ZLFFmhm0qa35Z6tlD+UqUwqGCNaFuFZUELlTwtcWsEPymNjzukGNb OwZp2arioRJqjBFQOJn6w1xwcTVy6dgH8SjakHl9lWDjHW1SLsp1l4/EGi9/TqmTjDT7 idpxWPnD/+br/jOm3T2og9B15/MCSnVRl5PB330yr0lP5OHAu6tx1wig8aSEAY/WS3AB BZozpKliTEqKncfFjdoXI7bszEDV2Xq0lBwTZwXSQnNoWvAg2IR4AywUjS733iFgj/ed R4PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773748699; x=1774353499; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=THWV8AkTQl5ICOeAjHO3xAofohI9LBMgOocyPIA+pq8=; b=rsohTgKGy/aWS10Ne5QY7NkGWWdXFGAytUibtr8k/t8iBPqKQ/TCxbZJLCCBBYtVEB xdsz0NfbAqgt68MQyfaXGK8IXMxJKQzDN9CcMryOqzFTjgn5PF7u3SypvV+S4IoLzTo3 bON0wVpLLKxMlI6G3givDGnFOpuzygkWsQgPN1WpBgwRI7cL6dsf4biQagNDDDkpdjrH I51IVF5x/7RSIaIyvVG1885YMl4gDgcjpZZhtJJ6pG3pTMAxzvQ5nIq7FbkSffMJYY+/ BGd0ircQDeC7mV+0W2H9GJIefv6kR2LErEhYSpfU1AefOQ9fMPV7CgtGOgv07bJivHK0 nqdA== X-Forwarded-Encrypted: i=1; AJvYcCXVYyBLJQ22yAomOC8Ij4RxnB8JWzJKtV8Ac1wqY3SJYK29+3V3/qMLRR3DZ2WW15LrdabAHr9ZXNBj1VBB@postgresql.org X-Gm-Message-State: AOJu0Yzz+GTMULN8eGA4YTLUkWwJFFnSpSSVchdAGcliju3z8DLnxizN 6ools0vbXwf7JYaMjfh+EM2KzqeGLPSOiqMjX7wuiLsmxJkE09OupIhThgQ+s/z4qsMe2P9XT4n xTGO+K0x0MQvDgiLuwW0Y7yWYVxSrZXexJw== X-Gm-Gg: ATEYQzwtXj64FwhuvVIwKPP/ZmgTH5dkSrV/sX28guxA5PGku3XfKNX7ZuMfSvk5qEr 1T+B8/ZwZjFrCG+o4lrSMlhWhmaQcGSUnTEu9ncjsiNSICxmHKHmI+o6Y6D7gBo3o/v3zNbU6M8 V9jXC610nlkdDhfM3JL56LSjOwwMKGZI6o2PzM5iu0dx7/BITFTSXx3wQ/6nhpWGWBgHZrBGPcP PiD97Hx2fkbJ5oW8RCcoQE/0wBajW4pJR9UH3BeG4RcOtCg+Gm+gMlssigdSNCF9z7VTxeSn3Jb BqjoVaIAWDWJFujhWUlS4TRi5KQufe9t6L/TXG4q7vN6qXmiTz7/ X-Received: by 2002:a05:6000:402c:b0:43b:3d02:7806 with SMTP id ffacd0b85a97d-43b3d027888mr18056414f8f.28.1773748697953; Tue, 17 Mar 2026 04:58:17 -0700 (PDT) MIME-Version: 1.0 References: <5a37c2e3-619d-4816-84d7-0b27e3e6797f@iki.fi> <26c766d6-db0f-43d3-a618-44f8d40a3121@iki.fi> <7de8e39c-d1c4-4783-91b9-129d90e91411@iki.fi> <41137f2a-0cb0-4cbe-9afc-2dc690f60a87@iki.fi> In-Reply-To: <41137f2a-0cb0-4cbe-9afc-2dc690f60a87@iki.fi> From: Ashutosh Bapat Date: Tue, 17 Mar 2026 17:28:05 +0530 X-Gm-Features: AaiRm53lrDMRGmO-Fkdw0hIcnb5zCv5YwgnpjWxswGokVAG6uliKy__m8y9ZQ1s Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Heikki Linnakangas Cc: Zsolt Parragi , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 17, 2026 at 3:26=E2=80=AFAM Heikki Linnakangas wrote: > > > I don't plan to get rid of the legacy API any time soon, I expect > existing extensions to continue using it for years to come. So I moved > them per your suggestion. Do you plan to get rid of the shmem_request_hook and shmem_startup_hook? What's the plan there? Wouldn't the old APIs and new APIs overwhelm extension writers - having two different ways and three different hooks to allocate a structure in the shared memory. > > > ShmemInitStruct() now calls ShmemRegisterStruct(). Earlier it could be > > called from any backend, in any state to fetch a pointer to a shared > > memory structure. It didn't add a new structure. Now it can add a new > > structure. I am wondering whether that can cause registry in different > > backends to get out of sync. Should we limit the window when it can be > > called just like how shmem_request_hook call is limited. In that sense > > ShmemRegisterStruct() looks something to be called from a > > shmem_register_hook which is also called from EXEC_BACKEND. Sorry to > > expand it here rather in my previous reply. In case we replace all the > > current calls to ShmemInitStruct() with ShmemRegisterStruct(), we may > > be able to get rid of the Shmem Index altogether; after all it's used > > only for fetching the pointers to the shared memory areas in > > EXEC_BACKEND mode. > > I think it's still useful to allow ShmemRegisterStruct() after > postmaster startup, so that you can use it with extensions that are not > listed in shared_preload_libraries, but need a little bit of shared > memory. Hmm, perhaps we should add an explicit flag for that case, > though. So that by default ShmemRegisterStruct() fails if you call it > after postmaster startup, but you could allow it by setting a flag in > the descriptor. > The hash tables do not allocate all their entries upfront but they request shared memory for their maximum size. Before they could grow to the maximum of their size, if somebody calls ShmemInitStruct with a huge memory size request that takes away all the reserved address space/memory, the hash table won't get its fair share of shared memory. I agree that it could still happen if a hash table grows beyond the contracted request ... but it's atleast registered. I think we should prevent such cases. We could keep track of the extra shared memory that we have allocated and refuse an unregistered request if that memory is exhausted. But I think we already have some unaccounted for structures e.g. ShmemAllocator and ShmemHeader already. So it might turn out to be more complex that required. I have feeling that we are providing flexibility that the current infrastructure can not support. I am not opposed to supporting ShmemRegisterStruct; I like the idea, but it seems premature. -- Best Wishes, Ashutosh Bapat