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 1w6GQe-0047aE-3C for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2026 23:17: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 1w6GQd-00Crtw-1S for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2026 23:17:23 +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 1w6GQc-00CriO-1z for pgsql-hackers@lists.postgresql.org; Fri, 27 Mar 2026 23:17:23 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w6GQa-00000001ZBg-1I74 for pgsql-hackers@postgresql.org; Fri, 27 Mar 2026 23:17:22 +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 4fjGkf330nz49Px5; Sat, 28 Mar 2026 01:17:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1774653435; 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=8XBD3Q/R05G5pU6zJRCAvR2DnL6NDzmFmU/8f7ne4YY=; b=r9AsnRKq6lJ0Warf+dzusiYgwS0xaJXyGNhOihJiaO8nbul1MSi8tELrGjHQZdqjRAk096 aFVmbEifeuD6MjGIFfQpETaiQCJ6One+DsV41Kc9REXVwQjzjfDcyxbZzBor41QTbG4tPE NxxuocgiGq6yOExtw9VzcuQRd14nN0I+EVWq7bVjNc8oErHA0SK9z2lEpb5L75ufc84C/S 6rmU7Esx6Q3yLXfqPufQWsrfjpmZsuVabBWpHQUp03SPx1bmQ676ETsF2Jxvt36qlZLCXl TgoSQHJoUhz/T+mh69SiRhMHcye8wLOhv6Bn5o28r3i45VM5YAVQBWMCGHZBBw== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1774653435; b=cLh/dAWYmzmPZpv2hMMTeYDlIJzR4pKDEAIoqE+qmzRAq7jwSfdAoI/1ZdOflCj46uYZXW OhfXd8qcMjW5cdg6FW0UF/yt5SNwhvlSHduliEMq2JBXORTmNFw42dHK5eCk9tyzCjL/Up AgfaDBAyWNnCgoOTcnvTGi1T/9ynMfJYefhW/IxSngPyCFgBKRfw90btSGRgDB9q9nDXZk Ei0mbR/MD3TlcHHF7K0OQoP8Wzd0Bn0SZ2CKGJltbt4Z3QjFHsYHDk/5PA0Oaue/0EHAV1 ExuoQBp/DZo8h95MAPjsiaOOwfE4ORx+JpwGIZ4GKMUNdSEsfKXjy9ouwgsW4g== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1774653435; 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=8XBD3Q/R05G5pU6zJRCAvR2DnL6NDzmFmU/8f7ne4YY=; b=pjopBsIieyqZkNzvHv3g+D6JcFdWTYbTGtPVKK8i9Cs6Sk4mxnLfhTBFWAKQk/ysnG/80Z 66wosqgNmn6CTDz5Iy+UVlVzEQH47MFtEkM52MJxovIxnlBxT/0006FVfJd5ItIlfJ4kaN ORZTREFsX+tVXgj5AyDYy1sQeor7c+0CbJDUogMaspMShXGVC+li+4hyMHu4AAIPq+KOPG iz/K/re2n0+k0jWGrQbG7ihoJEpXmwQ2uDazoxGKFuIp5T+i+mA+qfDikHm8JX1hMJiyaO bo4I1ozyQQ4x9YX5guEzgeQSY1kohn1cPxc3SUgbfgGU+7WAp22KAH5Rs1EbMA== Message-ID: Date: Sat, 28 Mar 2026 01:17:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Better shared data structure management and resizable shared data structures To: Ashutosh Bapat Cc: Robert Haas , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com References: <62b8dc23-8f6a-4cac-91ff-f74bb5bc159a@iki.fi> <8a6799be-bd42-49fb-8914-856c97bb1977@iki.fi> <113724ab-0028-493f-9605-6e8570f0939f@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks, will incorporate your comments in next version. Replying to just a few of them here: On 27/03/2026 09:01, Ashutosh Bapat wrote: > /* Restore basic shared memory pointers */ > if (UsedShmemSegAddr != NULL) > + { > InitShmemAllocator(UsedShmemSegAddr); > + ShmemCallRequestCallbacks(); > > It's not clear how we keep the list of registered callbacks across the > backends and also after restart in-sync. How do we make sure that the > callbacks registered at this time are the same callbacks registered > before creating the shared memory? How do we make sure that the > callbacks registered after the startup are also registered after > restart? On Unix systems, the registered callbacks are inherited by fork(), and also survive over crash restart. With EXEC_BACKEND, the assumption is that calling a library's _PG_init() function will register the same callbacks every time. We make the same assumption today with the shmem_startup hook. > +void > +RegisterShmemCallbacks(const ShmemCallbacks *callbacks) > ... snip ... > + foreach(lc, requested_shmem_areas) > > Doesn't this list contain all the areas, not just registered in this > instance of the call. Does that mean that we need to have all the > attach functions idempotent? Why can't we deal with the newly > registered areas only? registered_shmem_areas is supposed to be empty when the function is entered. There's an assertion for that too before the foreach(). However, it's missing this, after processing the list: list_free_deep(requested_shmem_areas); requested_shmem_areas = NIL; Because of that, this will fail if you load multiple extensions that call RegisterShmemCallbacks() in the same session. Will fix that. > + /* > + * Extra space to reserve in the shared memory segment, but it's not part > + * of the struct itself. This is used for shared memory hash tables that > + * can grow beyond the initial size when more buckets are allocated. > + */ > + size_t extra_size; > > When we introduce resizable structures (where even the hash table > directly itself could be resizable), we will introduce a new field > max_size which is easy to get confused with extra_size. Maybe we can > rename extra_size to something like "auxilliary_size" to mean size of > the auxiliary parts of the structure which are not part of the main > struct itself. > > + /* > + * max_size is the estimated maximum number of hashtable entries. This is > + * not a hard limit, but the access efficiency will degrade if it is > + * exceeded substantially (since it's used to compute directory size and > + * the hash table buckets will get overfull). > + */ > + size_t max_size; > + > + /* > + * init_size is the number of hashtable entries to preallocate. For a > + * table whose maximum size is certain, this should be equal to max_size; > + * that ensures that no run-time out-of-shared-memory failures can occur. > + */ > + size_t init_size; > > Everytime I look at these two fields, I question whether those are the > number of entries (i.e. size of the hash table) or number of bytes > (size of the memory). I know it's the former, but it indicates that > something needs to be changed here, like changing the names to have > _entries instead of _size, or changing the type to int64 or some such. > Renaming to _entries would conflict with dynahash APIs since they use > _size, so maybe the latter? Agreed. - Heikki