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 1w9Smh-001SHw-2s for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 19:05:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9Smg-004Vgj-0a for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 19:05:22 +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 1w9Smf-004VgZ-2h for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 19:05:22 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9Smd-00000000lsj-0HW9 for pgsql-hackers@postgresql.org; Sun, 05 Apr 2026 19:05:21 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-38cbe79dddcso29902311fa.2 for ; Sun, 05 Apr 2026 12:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775415918; cv=none; d=google.com; s=arc-20240605; b=X3FPZKvoz1WGBz8PqPmBO/vOw0C/zoii4l3oKMHPrapPq2kfRyGVzy5RP3c3oJhjIP 3+nYDgHmN6xMLEQLOD8KYSvaPW2oNH7ZyTxYJ94nxHbvi/R5ebCXOegQ2KL9vnsa2OET MnTbpCVsIoWId//KXzge6EoOIanrswxIhXRRLUI9HgraBRehCwz4gI9O5kThC8c6vVon rnYiYEc88zqpKWnlVEAhDAt9bGUVPFiwEi6XIYYvTCXE8ja5xK2wcs7DV7/tc3Y7lT+4 YNsFMLpsp4aLALWFBuYnLydBLvGPP8YE02dcQL8HlmMotsu5JBM359SmA/v/QMOIaq+h NWrA== 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=Jqb3RzsbvBI7JqyqLY+WgvjgJJv1WnNvz/R7I0yWrTI=; fh=R7n14v4PzDg/WlS8fIWz4WBTB4I1V4iAJTHcoJRbT90=; b=aZUHGMCB7b2NM0DKIfq+KoC6Mc6qhhUECRCSkn7S0DUaoqTKSX9OyJGvoCjCqJP1jS m2gMy2uK5+VeQXMkqrAVAW6qlvDTlV+oKcLtnZdD9ybVuOJktaZmAxkLRVddtoOGLe9v 3S/WNbg2luhC02lOPqaskMGRSULdIzhmRN3Ro+VEgsC9snngaiCSjLWyt/2h/vRRxQ/L m/jFbZY0UNvIkxxmkhNuVSiJqFso+0gosd+nvWg2bMPMnAKZh5FBtxchUT67UsI6k0Dx rv7kfKWYbo7P55pwn79bun1nJVBs5ROgDs0EUQNcAwPYWKvxyny+vwVnIfBA97jHtvL5 JJng==; 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=1775415918; x=1776020718; 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=Jqb3RzsbvBI7JqyqLY+WgvjgJJv1WnNvz/R7I0yWrTI=; b=Y5oxrrYybrZiKKlolUbIbp8VckXAM9qz0u4erk1jPQG1lNIYzEJmbbmGXfERPJkCcx Y6UEDi7wnwOpFpSbnLrzqKesmK2fZrO8rBmZCqua3uxewGbmKEbbZ4wNX0v0MEMxxYxM fJyiLvrPAOnfcjp7POKswmBxq2F2oZWdSYxVBqUiRMc9L71vMvt+f1oc8S6R8t2rIKP4 u4lR8eUNP8y4Rcm2UkjayLzWjL5dPG+OUsydJSIMtPkEnfq1fOHGn//2X7IeVyqe+RBl JW2Jv8aWr2GYea9Pd4taC1TRTGrTxaLgItuHjWEVUERFbUgRXXSGZBW5hXi8KLlca3tS CizQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775415918; x=1776020718; 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=Jqb3RzsbvBI7JqyqLY+WgvjgJJv1WnNvz/R7I0yWrTI=; b=ZH8XL8vlgbM7fUscqgUz4z2mcJpZObisOhKBlgn9Nr08tqJMUpjYeuczgfGOlhyhen GGwhmzKR4cB0Im3g6AqCuioe8qXmGtBO72GZbT6t3Sop0uX3uEi/zGYTt/bK8QvbsgSK uoIT/FTGh0sheI4DIsT+OnQmZSyQshzwJfKPZe/vTK9kXoGcOvmpS0GzKoIsoN2N6yLk YI1kJJrMPcVApK+9isKs2SwObX70f2ctjgzoCo19xz7RC+YtYETz8MlxV8EXR9Xf14+j 5OuMxCJYfw4nbdeLo+hdPftAGZ51t/nHqeEa1ujtHXLmxPnkENaVNdnNag1VAgAR9ywP iCaA== X-Forwarded-Encrypted: i=1; AJvYcCXhgjhDU+2aIyI7Jv5FpFhEmlzv2w4XazcdIzQnUe026JDJZRCryhF9GWz17hwP8yTeZ3fngqsoWnQ/oTLB@postgresql.org X-Gm-Message-State: AOJu0YwYU5X+JtgJdROw4qEkr88xY0nsSxg8LSX/W7I2GkLFmBiOyO2D 01OZ4LsGzkmYhW0hzp0RHnG+YKJI6mgy8hKf8zptjC6ne5mf8I74vqq6WPlGvZTVwbMo/WzQI8o y4IcZrtkgcERozy3JBXjAAbJxrsc5ocI= X-Gm-Gg: AeBDievd9GZsuJWI1RZ8xpNQFwZNxQ+d9R+KVtAKVWH4ser+Huvcq7gPVeru2fNNShd fSGfSi/npL7afIhKFH/6wgmhEnUBOufS9QSWNqgRLEHVP4UZZqZQ5WjbPKTq0YKbyYPuGifwhqk WdnDPx9VJErYgn2CldjMaWpUDe7so02DvfsVbxkMouqiv/4YGCE7MuOM8gbGfrOOTOhqrEEg3X1 9CQFWADnsheEz4+WNNYdOb8A0lFWJY76EQ4mbpwK+h+rK+iLpgfL6SGwx82TIlhyyTBnNrLXMo5 zt4kho02WEsxOstrjZGGiWd7szAh/fkGvzJy1bw2GlWlwtQ9bADI2taD7exHYAWeKThCqD/QRHp feHF0rolCNiukRS4= X-Received: by 2002:a05:651c:1447:b0:38a:8602:71aa with SMTP id 38308e7fff4ca-38d91d6d4b5mr32242381fa.16.1775415917564; Sun, 05 Apr 2026 12:05:17 -0700 (PDT) MIME-Version: 1.0 References: <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> <1c3a07a7-158d-4800-927c-2641c73277d8@iki.fi> In-Reply-To: From: Matthias van de Meent Date: Sun, 5 Apr 2026 21:05:04 +0200 X-Gm-Features: AQROBzCom6T8sk8xnmU4tulHb07gAf9VGbUspnQiYkeT24jc9TJOESSq9kqFuIY Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Ashutosh Bapat Cc: Heikki Linnakangas , 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 Sun, 5 Apr 2026 at 13:20, Ashutosh Bapat wrote: > > On Sun, Apr 5, 2026 at 2:36=E2=80=AFPM Matthias van de Meent > wrote: > > > > On Sun, 5 Apr 2026, 07:59 Ashutosh Bapat, wrote: > > > > > > On Sun, Apr 5, 2026 at 11:18=E2=80=AFAM Ashutosh Bapat > > > wrote: > > > > > > > > I'm not opposed to HAVE_RESIZABLE_SHMEM, but is it universal enough on > > its platforms to make it part of the exposed ABI for Shmem? I think > > that we should expose the same functions and structs, and just have > > the shmem internals throw an error if the configuration used by the > > user implies the user wants to update shmem sizing when the system > > doesn't support it. That would avoid extensions having to recompile > > between have/have not systems that have an otherwise compatible ABI; > > especially when those extensions don't actually need the resizeable > > part of the shmem system. > > > > I don't think I understand this fully. An extension may want to > support a structure in both modes - fixed as well as resizable > depending upon whether the latter is supported. If the structure has > maximum_size always the extension code needs to set it to 0 when the > resizable shared structure is not supported and set to actual > maximum_size when the resizable structure is supported. Without a > macro or some flag they can not do that. The flag/macro then becomes > part ABI for shmem. Am I correct? That's not quite what I meant. With your patch, the size and field offsets in `struct ShmemStructOpts` changes depending only on HAVE_RESIZABLE_SHMEM, as does function's availability. This means that an extension that's built without HAVE_RESIZABLE_SHMEM (an otherwise identical system) can't correctly be loaded into a server that does have HAVE_RESIZABLE_SHMEM defined - or at least it'll misbehave when it tries to use the new shmem system without trying out resizeable areas. If instead the fields used for definining resizable shmem areas (and the relevant functions) are always defined, but with runtime checks to make sure that in !HAVE_RESIZEABLE_SHMEM nobody tries to use the resizing functionality, then that'd reduce the unchecked hidden incompatibility; assuming that no extension manually does memory management syscall operations on those shmem areas. > Since extension binaries need to be > built on different platforms anyway, that would automatically take > care of building with or without HAVE_RESIZABLE_SHMEM. I feel it makes > testing simpler since run time behaviour is fixed. Maybe I am missing > something. Maybe a code diff or some example platform might make it > more clear for me. I'm not entirely sure it would be automatic. Is it guaranteed that HAVE_RESIZABLE_SHMEM won't change over the lifetime of any distribution's platform? Because it's definitely not apparent to me that rebuilding the new server version against an upgraded platform (now possibly with HAVE_RESIZABLE_SHMEM) should also mean rebuilding the extensions that have been built against a previous minor version (without HAVE_RESIZABLE_SHMEM). > > > For now, it > > > seems only for the sanity checks, but it could be seen as a useful > > > safety feature. A difference in maximum_size and minimum_size would > > > indicate that the structure is resizable. > > > > I think that's the right approach. > > > I also think that introducing minimum_size is useful. Let's hear from > Heikki before implementing it, in case he has a different opinion. I > am not sure about min_allocated_space though - what use do you see for > it. reserved_space is useful in pg_shmem_allocations() C function > itself and gives impact to the fully grown structure. What would > min_allocated_space give us? If at all it would be min_allocated_size > not space since reserved space will never change. But even that I am > not sure about. I'd say it's mostly interesting for people looking at or debugging shmem allocations. Which isn't a huge group of developers or DBAs, but if we're exposing data like this, and are going to allow resizing, then someone could see some benefits from this. E.g., it may be useful to have the information to see how low the currently running server can scale down its memory usage, so that the admin can see whether a reboot is required if they want to allow it to scale it down further (assuming there's a lower limit for allocations - some shmem structs may have a lower scaling limit defined at startup, while others may be able to scale linearly from 0 to 100) Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)