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 1w93wr-0019vt-2r for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Apr 2026 16:34:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w93vo-00HI2c-2C for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Apr 2026 16:33:09 +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 1w93vo-00HI2U-1A for pgsql-hackers@lists.postgresql.org; Sat, 04 Apr 2026 16:33:08 +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 1w93vm-00000000aRz-0bYU for pgsql-hackers@postgresql.org; Sat, 04 Apr 2026 16:33:08 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-43d17bb1c1dso2609100f8f.2 for ; Sat, 04 Apr 2026 09:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775320380; cv=none; d=google.com; s=arc-20240605; b=PExHtIvSL+OZLt1qmNYSNXBrCjphU4OZq+dXaEsTvdJmGcjhX0/KbqjFZYox0km/MR P/z8VH5pm/hyKHuXDoLC4OX+Kv5bbW7nvEUzmopfTQ9aAQDphXG22t2g1MoNP5z1Ex2b K3iB2uASY4SYl1qIiYN9jOaE9WiRcKWovNSS433W9xPW7LqxTitpgQkx+0PG8Xi89Gak ZJDpqfJG7CGS86VZJS8jADjd953pYzI18dfIJP5d7dobALQtgzMki/W9NQpuNkGaPrrD HkyMFIOwkPDqTxhRxnQ/Ci11On5UIc5M+QhWhsyMuJFhXK7Pty5BngJVARgS42jwNl4d EsjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=s50tq/DV2MIdFSDdcrZugoUFZV7dfn5EeSoVN+cFsCg=; fh=IF4loZrvkjoVwIR3GfBHQWqAIXWaIg/EZFWfWp9RaHM=; b=CRFrEmrRGN8K26Mew61r9F8EMdiEv2TwVNjkpRd+M8ARvt+ukwWsAgMcdlpj1r3Ffr Vqqre4e7BZIs4GHiOPhMIG52wHrO6V1Volkj0FeH6wvtHwOgoKKslO6m5KxWYZdLsDVL phhMNwuLbxfied0Ul3LaqNfiv01vnhf+yAyH/hkSQzNqLL1IRiaBZ6sCenbRrbP+7RL1 Nlgl+ASunV3D6YoAKDAhXHqZzmdg0fXnjCETPzntuHZW30OBAI8B6M2w5V39J8TOyCTQ kdmepgtvlGVhqS1Tuw52L76bsCQsR1+KixuBAKQK1eiz/pzBjEf8Ab7gtKVbqsmXxOkU Fe3g==; 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=20251104; t=1775320380; x=1775925180; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=s50tq/DV2MIdFSDdcrZugoUFZV7dfn5EeSoVN+cFsCg=; b=N4kGoZBtbC2MEmkYMP33bRrklzxOJ/RFG1k9pewoc0JZ0u1ph9zTokjOuHsvMevfm9 hAyF8XGch6IkDENbc06pfXGXSGKCBMgyr59nShBO6t5ElFYAj5lk7IXA9pwZMptDBFCE TOH+iyxHc65UpsNd4e8Q35yzIO/Towti6sPLRBum/iLfN3joiGnkAvWwtIZ5Wp2JDgPV eoqnMXgHkPJ/6TcyEt9IQ9G7dZBdWuXgtwrs6xlzbCnWthiJiLlshlcWOT7omg+yVAe4 QYonlKyTt4PTKW2xPuo7QuyLEzs/qCTlnH543U2TxnVvIQb7vhRCGTeY/M5PjZL3I8NU 9OtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775320380; x=1775925180; h=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=s50tq/DV2MIdFSDdcrZugoUFZV7dfn5EeSoVN+cFsCg=; b=qmboLWRw8Z3NGkLV+yCsAGPG3okrRxxrLwBrHTq46aS0jbTkkdYSCLfHwrmEG2ok1Y iMHGSUZQwWNW8JetiFyR9GnI2ct4LBooof6vKx6WyZqvipj2/R0Hab4a9TTqBjdAwELr ZotcglwtAqTgrsxLrS6SWxpOvKFYRULU0njOK4pozR4DxrzKd8qI2w+qVntCa6dVV3x5 2xnbz3dDTVM5UKpil1iSRRwuoI+2U30u2e1wf6AIwdytLM7k2nbde5JZzSapHBv/hpB3 4z+MeM+HeWMlHZ1S8sqGsulc3vfkA7PiwLs26qdUJTyjoLEmfESdv2Odt85/m7pjHtn0 XrKQ== X-Forwarded-Encrypted: i=1; AJvYcCXTjBedA6qHfcz2WPxAYfud7RSoNFQ5WUQB2SoOhPNtVuxAIPTN9GBN9stIdBz5UArWBdtZBgwldjSa9WuN@postgresql.org X-Gm-Message-State: AOJu0Yx38C9KtwVzjAHrz+2hcsZJWYWK+0HLrDW/SjblK/sHMUaVHvlS Kr1eAz4TEAb7yK+WWiLeK5qPD1BXzNdzPZnOK4hMWeNf53PGdtDftWdQoTwH48aifVZVoyyO2zr wUYPPtyZPMRT87TfukcNoVn7sAzgh0z0= X-Gm-Gg: AeBDieuSuVPhQjfUXaL/palxtjnwh0VBVPGygZhteSWNjmSJAg3g+9pgrj7GdyN1Ieq xOXZHxV13NrZhp8XYwBmDm1jH2l4LXHEopC8OFx9QSCa+XF/LbeIb12m2plZwhlZIEVSu7qpQsA 9esgDBS8SAeFWj+CvVLG8hDj1zvuGV7cNdWvxB1B+bh3OfqvSadmqicqUlYNshuVnUdzi2dRn9Z pj6gz7+q16EWOkIgsBiToOaB95oVTOiQXh3Gj6VRC8d7NXeRzPA1d3oV5VcAwMeCI1D0Gzi9oDV jmLuZo1zgViYcbVEQyj9S+7Zk114tPM/qxuUe0V+Ky8jkLA7c8eddA== X-Received: by 2002:a5d:5d08:0:b0:439:b8b2:fabc with SMTP id ffacd0b85a97d-43d292a9581mr10500639f8f.21.1775320380127; Sat, 04 Apr 2026 09:33:00 -0700 (PDT) MIME-Version: 1.0 References: <8a6799be-bd42-49fb-8914-856c97bb1977@iki.fi> <113724ab-0028-493f-9605-6e8570f0939f@iki.fi> <791c3f18-f4de-4d84-ac6b-c7ccc074dd38@iki.fi> <9d919bd9-94dd-4bda-8ccf-ebced4178c53@iki.fi> <470e7ebe-0971-49f6-8e46-9b8f6395f88b@iki.fi> In-Reply-To: <470e7ebe-0971-49f6-8e46-9b8f6395f88b@iki.fi> From: Ashutosh Bapat Date: Sat, 4 Apr 2026 22:02:47 +0530 X-Gm-Features: AQROBzB2PBuJqO9MWxUCMfHeyfRCQ6p82ShEbRtCIsZ-QO0Gqc856F5fB5yneQ0 Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Heikki Linnakangas Cc: Robert Haas , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com Content-Type: multipart/mixed; boundary="0000000000009efbcc064ea4fc39" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009efbcc064ea4fc39 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Apr 4, 2026 at 6:19=E2=80=AFAM Heikki Linnakangas = wrote: > > On 02/04/2026 09:58, Ashutosh Bapat wrote: > > On Wed, Apr 1, 2026 at 11:47=E2=80=AFPM Heikki Linnakangas wrote: > >>> + /* > >>> + * 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. Th= is 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 o= ccur. > >>> + */ > >>> + size_t init_size; > >>> > >>> Everytime I look at these two fields, I question whether those are th= e > >>> 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? > >> > >> I hear you, but I didn't change these yet. If we go with the patches > >> from the "Shared hash table allocations" thread, max_size and init_siz= e > >> will be merged into one. I'll try to settle that thread before making > >> changes here. > > > > Will review those patches next. > > Those are now committed, and here's a new version rebased over those > changes. The hash options is now called 'nelems', and the 'extra_size' > in ShmemStructOpts is gone. > Thanks. Adjusted my resizable shared memory patch on top of this. The result looks better. > Plus a bunch of other fixes and cleanups. I also reordered and > re-grouped the patches a little, into more logical increments I hope. Some more comments test_shmem declares MODULE_big and OBJS which seems to be old fashioned, newer modules seem to be using MODULES. Also it should use NO_INSTALLCHECK. /* * Alignment of the starting address. If not set, defaults to cacheline * boundary. Must be a power of two. */ size_t alignment; We don't seem to enforce the "must be a power of two" rule anywhere. We should at least validate it. I like the way buffer manager related changes untangle sub-sub-systems of Buffer manager viz. StrategyControl and buffer look up table. Simplifies code very much. I also eyeballed some of the changes in 0014. If time permits, I will review those closely soon. But the changes look ok. Before this change, replication_states_ctl in origin.c was not initialized explicitly when max_active_replication_origins =3D 0. With this change, the structure is not registered and thus global static pointer is not initialized. However, given that it's implicit, I suggest adding Asserts as attached. --=20 Best Wishes, Ashutosh Bapat --0000000000009efbcc064ea4fc39 Content-Type: application/octet-stream; name="0014_edits.diff.nocibot" Content-Disposition: attachment; filename="0014_edits.diff.nocibot" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mnkjuf6d0 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3JlcGxpY2F0aW9uL2xvZ2ljYWwvb3JpZ2luLmMgYi9z cmMvYmFja2VuZC9yZXBsaWNhdGlvbi9sb2dpY2FsL29yaWdpbi5jCmluZGV4IGRhYTk4NDMzMGYx Li5iZDBiN2MzNGNkMCAxMDA2NDQKLS0tIGEvc3JjL2JhY2tlbmQvcmVwbGljYXRpb24vbG9naWNh bC9vcmlnaW4uYworKysgYi9zcmMvYmFja2VuZC9yZXBsaWNhdGlvbi9sb2dpY2FsL29yaWdpbi5j CkBAIC01NzMsNyArNTczLDEwIEBAIHN0YXRpYyB2b2lkCiBSZXBsaWNhdGlvbk9yaWdpblNobWVt SW5pdCh2b2lkICphcmcpCiB7CiAJaWYgKG1heF9hY3RpdmVfcmVwbGljYXRpb25fb3JpZ2lucyA9 PSAwKQorCXsKKwkJQXNzZXJ0KCFyZXBsaWNhdGlvbl9zdGF0ZXNfY3RsKTsKIAkJcmV0dXJuOwor CX0KIAogCXJlcGxpY2F0aW9uX3N0YXRlcyA9IHJlcGxpY2F0aW9uX3N0YXRlc19jdGwtPnN0YXRl czsKIApAQCAtNTkxLDcgKzU5NCwxMCBAQCBzdGF0aWMgdm9pZAogUmVwbGljYXRpb25PcmlnaW5T aG1lbUF0dGFjaCh2b2lkICphcmcpCiB7CiAJaWYgKG1heF9hY3RpdmVfcmVwbGljYXRpb25fb3Jp Z2lucyA9PSAwKQorCXsKKwkJQXNzZXJ0KCFyZXBsaWNhdGlvbl9zdGF0ZXNfY3RsKTsKIAkJcmV0 dXJuOworCX0KIAogCXJlcGxpY2F0aW9uX3N0YXRlcyA9IHJlcGxpY2F0aW9uX3N0YXRlc19jdGwt PnN0YXRlczsKIH0K --0000000000009efbcc064ea4fc39--