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 1w8zfy-00164i-2A for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Apr 2026 12:00:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8zfw-00G9bn-2U for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Apr 2026 12:00:29 +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 1w8zfw-00G9bf-1C for pgsql-hackers@lists.postgresql.org; Sat, 04 Apr 2026 12:00:28 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w8zfu-00000000YIU-0aQy for pgsql-hackers@postgresql.org; Sat, 04 Apr 2026 12:00:28 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-38dd9c6840aso9165531fa.0 for ; Sat, 04 Apr 2026 05:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775304025; cv=none; d=google.com; s=arc-20240605; b=OHzug6sHAfW89jihMO8QC1X8mGPr/RFdxV9ixTS2ueZGLyvP9q5M3ilF8/3CLhZlwL xXG0CJ4bUGdkP/U6TNPhJeTyVJfDCt9e1lKyYyGH8ygOE4KSEkyqRweq7QyRKXRLMvc9 oaR86EYgJROyMmv76C6gCy0ocducoZc24kxZ+yrTOjFIjuC07YAvvm1Pi3zmmQofpsWB BRgtgICx98Pd14cDUdZg4/WheBmBqODoiB4qRSabJjo58pleoKl0MAvZc3bmgVPSjPnu mD17AlihM+pHPAbAL0Q2lJsciPE0ik2dUFkSbmf9EjdAcM4MTUlzjLmsQdMfgFYU1iv4 j0hQ== 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=NJyRKJwHxRACsa9bqNBXldkIwL1sR7zPsuFEYcmSW3Y=; fh=y3twwLxEzwlD+Uh+aiPUEPKrfWHGLYF8XzxQkTHafhE=; b=VoL1gJmwYP/oG3hfsLfXG04HDzFaLiHcNBy4xFPeEDUsTBORXhpiy7ux793gaAVuW8 18/gRa614SRhbTd8sJm1dOgKVyLi1pvnQaWGr+3UitRBKxzx70TtrWxPYb+0wlVfGwqT mEhz/EQq0zitThro3Q6Y40Gu2iq6WvjkDX8OtnqqSObBlU+nntPbUFniJ0Uq+5sNiLAs dJI3uLi8zQ+J97xdsnhFnUluwnaSmERilJU6Y6JoDBt7oAxiWE3H5BOauN38sEGWBFBD NNz3H6s7sZXnRzh6M9Q5RJOgxNHZzc7x3/ESMkyVg8jJ4DOxDAEN+WMTzfo4G6T0a4wc e6GA==; 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=1775304025; x=1775908825; 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=NJyRKJwHxRACsa9bqNBXldkIwL1sR7zPsuFEYcmSW3Y=; b=h8D+BkyzgRq5W4g5xPTu92OpugXMGVXERYfrTee3JJPAYn12Li9l5PA1jqhwgYtrpZ DORH37vkJrjna47p2qEHbR4GihSqhkx8kHS2z9tgwmRUVXVHIG/95o0HR0Ae27k4ZVIG kIu0kbobaYZAy3kNxfNagnHDPHXK7zsl/i25PPu0c/xtV8KapnFAd0xLqQ+sKoCeymin idREuybWoPL7A8b577n0oxjuhyvIF4iydNG0lH6uRc0qkGZy5SR1q48NI1e1SahWEzP9 LEGcrBua0Q2m4UQit5dceEQmYYE1PgLC87SesV7HMLrjyAKmRpM36n5TXxgMJCNYZ07a 6wDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775304025; x=1775908825; 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=NJyRKJwHxRACsa9bqNBXldkIwL1sR7zPsuFEYcmSW3Y=; b=gW1faW86CX86BXCJb4V/276jfOcYGnLjG7FAA04zxvJ3Xy6saZoZ2ski0ZUsCKgNe7 cSudCI2VwJt7oumFqh6aLnsynWzNjeILyiT6UKGow0NMsVR/DGSiTekos0jAv7dMBIca 7m+nZrKJgL14ul8ZtcmVPMZaFN5Xq6UgtsgFcK5v4RzFP1+0VYxG5cQyWWZjXT/PsXcO BwcQFDDadGvWU/y5EYf56U9On/VZildsfUtIHE+xwffp1Nsk4REqXWzUjZSbo86AYoPh 36kw7VD68Hhvilur726asE77b9AbtqRSvROEZcJGh3wRMOeGRGMB1oRCLWo2lqXm5K1S 3WvQ== X-Forwarded-Encrypted: i=1; AJvYcCXrvbkR9OKEYfXhN04gmsOamJ8Vph0CgGgW+XlR2TmJf5OV6QHGia9+tIY8b6l3iCthK5VHA1d4SW1gkMsn@postgresql.org X-Gm-Message-State: AOJu0YwHNt2Yurjxt1Y1WZB7RW8WSllm/thCUavOfXfdjtYae2Z88URm N7lKoWG44RgQkA9FT7nesj9miobguDX/69Dllo9d8atBmViWFsJIb7oQEEpXIZ4MaGRm4zCLGL2 4rRRcAxhm//Eo5s0qD0VrpJQTjfR2NcE= X-Gm-Gg: AeBDiet2h+8Su0T9NLZ/NzG3hX+HbUDsvQ3LSHWWPUjJZcvSPgp0TcRMT7KkDazpoMC SPSm1iY3rVhuUCYfaRhcpEjdcAmAnn7extpgARIzRhAYf81cEbJ+268R3KsruB6cmp1OXuonW1E vE2Rn5idR9yp3j9ZzyVN1TvjzB6uXu8i3J4U7Jj4NwoSzUxqNgPXsD45A2Ny+keiQ7mWK96RKVi wX5DJ0wePPDnqfxe3JAZM3cKbEQBqRItCDnC+Y/YWN1DKi+b/HHrZZP6wW68xPBE6u45gQiAszk n+/ac04CKvNYbs9UD8YcW2PxmeW5pi3EBsU90Yr98E3rsjTNM/BE2vYEEZXyITABGBuP/naE2wT LKTXi X-Received: by 2002:a2e:bc11:0:b0:38c:5b99:a32 with SMTP id 38308e7fff4ca-38d8d3811cdmr18956271fa.10.1775304024432; Sat, 04 Apr 2026 05:00:24 -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> <7d3ba240-9350-4dfc-bbe1-be6584aee236@iki.fi> In-Reply-To: <7d3ba240-9350-4dfc-bbe1-be6584aee236@iki.fi> From: Matthias van de Meent Date: Sat, 4 Apr 2026 14:00:11 +0200 X-Gm-Features: AQROBzB24wjtij6l0U0gkjF4Fu9DLTMFZUJNSgp6_Lo4FLbcRYybxBXqXaRP6I4 Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Heikki Linnakangas Cc: Ashutosh Bapat , Robert Haas , 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 Sat, 4 Apr 2026 at 02:45, Heikki Linnakangas wrote: > > On 03/04/2026 16:12, Ashutosh Bapat wrote: > > On Fri, Apr 3, 2026 at 3:40=E2=80=AFAM Matthias van de Meent > > wrote: > >> While I do think it's an improvement over the current APIs, the > >> improvement seems to be mostly concentrated in the RequestStruct/Hash > >> department, with only marginal improvements in RegisterShmemCallbacks. > >> I feel like it's missing the important part: I'd like > >> direct-from-_PG_init() ShmemRequestStruct/Hash calls. If > >> ShmemRequestStruct/Hash had a size callback as alternative to the size > >> field (which would then be called after preload_libraries finishes) > >> then that would be sufficient for most shmem allocations, and it'd > >> simplify shmem management for most subsystems. > >> We'd still need the shmem lifecycle hooks/RegisterShmemCallbacks to > >> allow conditionally allocated shmem areas (e.g. those used in aio), > >> but I think that, in general, we shouldn't need a separate callback > >> function just to get started registering shmem structures. > >> > >> I also noticed that ShmemCallbacks.%_arg are generally undocumented, > >> and I couldn't find any users in core (at the end of the patchset) > >> that actually use the argument. Could it be I missed something? > > None of the current code currently uses it, that's correct. I felt it > might become very handy in the future or in extensions, if you wanted to > reuse the same function for initializing different shmem areas, for > example. That's cool, but if that common initialization path is common enough to need special coding, then how come that this patch make PG use it? I can think of many systems that "just" initialize a hash table or "just" allocate a shmem area. > It's a pretty common pattern to have an opaque pointer like > that in any callbacks. I agree that it's a rather common pattern, but from an OOP perspective, shouldn't the argument be the ShmemCallbacks*? Users can embed the struct to extend the data carried if they need it to. > >> I don't understand the use of ShmemStructDesc. They generally/always > >> are private to request_fn(), and their fields are used exclusively > >> inside the shmem mechanisms, with no reads of its fields that can't > >> already be deduced from context. Why do we need that struct > >> everywhere? > > > > My resizable shared memory structure patches use it as a handle to the > > structure to be resized. > > Right. And hash tables and SLRUs use a desc-like object already, so for > symmetry it feels natural to have it for plain structs too. > I wonder if we should make it optional though, for the common case that > you have no intention of doing anything more with the shmem region that > you'd need a desc for. I'm thinking you could just pass NULL for the > desc pointer: > > ShmemRequestStruct(NULL, > .name =3D "pg_stat_statements", > .size =3D sizeof(pgssSharedState), > .ptr =3D (void **) &pgss, > }; That would help, though I'd still wonder why we'd have separate Opts and Desc structs. IIUC, they generally carry (exactly) the same data. Maybe moving it into a `.handle` or `.desc` field in Shmem*Opts could make that part of the code a bit cleaner; as it'd further clarify that it's very much an optional field. I'll check out your latest version in a bit. Kind regards, Matthias van de Meent