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 1w0mI1-002CTp-08 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 20:05:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0mHz-00HOF8-1G for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 20:05:47 +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 1w0mHz-00HOEz-0K for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2026 20:05:47 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0mHx-00000002LtH-0Y72 for pgsql-hackers@postgresql.org; Thu, 12 Mar 2026 20:05:47 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-b9734adc503so236132366b.1 for ; Thu, 12 Mar 2026 13:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773345944; cv=none; d=google.com; s=arc-20240605; b=ZV54ZteEUhAffwkCsvdkUSDoZfn3/1sSmmzW0z8OEZX+eC+yQG+pqr9iaRx7sd7QWg gIk11x2CdkfiJTmxQ22PMPgqu69Wsie/r7Lu2L2rKU24vmybHFLey0Cw5z2JsgoVgL52 xWLSffPn81cp3JDztn/3W7dXUVgclqqfzp6FvnHEtZZWX/YSo67lfL28xbSKYXjMUnXp FqRcHgjJQB3F5ojGiac0+TaP5JlW/sb6dYiEn8NcdQX3YGHEe8wDSuGp8COOpnxOD9MG qzj03suazsMbMGAGHbliC3TG0WBsIDU7kndpRgUgi7PVy1iHwj6sLw7tdumQ3Uyx9p8o zlOQ== 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=eOyxVGA8nUk6xLVOHq7gUFqJMJYg+x9db/w1Vr+5MC0=; fh=ChzRF3c7fji5nhopewauNp5KZ+rvt7br/Y/oHyWn9MY=; b=B5aDnaYxJq0lBYwBfYjkZbkzjgn2ioZuBv6eRj3sKwd5r0OAqLjai6pKzO7Rx/hC8L WRc//pVLtWimj/HBEcAPa3xMeKd9rA+y/Ilo61sA+X3L2DSW8Edbr1KUyoHwov5ZYXk+ F+OTTM6cxKIGtHWi/W2IYoO8NDmhQcpBdbkspcGYcKVOtvE2613ZVHSFZeQjy6Eyf29f 22vyYY1TTpaaTw6XncwUo2MPrs8ze68eXqUPeTq+sUY8KXLju8JkVFtMvwdWYDyH+3sf zcElYsOjku9ZBCO8GV/v75+bBWIxL1bvITAymzSvj+6AKrJMwyrDW7Yo1VbsGk/aZ3+n unYw==; 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=1773345944; x=1773950744; 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=eOyxVGA8nUk6xLVOHq7gUFqJMJYg+x9db/w1Vr+5MC0=; b=MjuUH+ZbJTYKDlcL9yHsQDrDNxm/AJpJx3a9YC/XjgJvI3G047kZjmre0JozIZ7NRY uHgwhb9AHoOr/OE9TqdRaM9lBNizUcsBN+vWJDMYIoOvBhbuQtHTrtdXTo61WkLFXMTA xpoQtivuNtXyF4dvGUZXsFZpYXh96oqI3AuvvmzEU5L/HP7z3cRhKR58WBXow2+WHypo 8l5Ma+zzL4OhhBl56ObZW3cNZ5GqNlMrROBlSHrkCcvHeSlIDcRdW5T0ZxAnmosValmY /8ri+bv+Fz0f70PAhOydksDzFm+lIkni1tBUd8uJ4mFY+ty8aRuU6O6uZ1s/Yhb4OQZR VSwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773345944; x=1773950744; 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=eOyxVGA8nUk6xLVOHq7gUFqJMJYg+x9db/w1Vr+5MC0=; b=bUUlkz2liEClttmAtkVb7kpA2/4TvyGGx7q3JxhN4CNYMfjoZDj+wAtoEgItMQV0Xu u5rUM72qr07b4o0PXbOMFr+7vBbSUp6ZridRMM/MTYJ11g6HOsIIctYOv8I7ASrzvhHa HQBpAi7inDO6iGlvQZ0sMm8ndRj1Wx2PfTn6WLe/4304YAKLUL/gkZHQiy5A+PkO352g b5830uII998iZJERw6FE9MvYc+2nyJRxjf7vdKqQPJzwS31UcqUx0lIorY3+KZBUqK5c mskBm9wgEMhAl5+vcApUElM5Hu3dcyySPR6ToU1TC3oYqHF0pqn+4L/TxiAkioGusm/j 379g== X-Forwarded-Encrypted: i=1; AJvYcCURrimW9EYyYLR2whFiJ0TNnCHTBBnuN1wQplctLVqXO7mp73LgRvBMy/Eaj63MDMe8vLglvaAcfPPAXJ8v@postgresql.org X-Gm-Message-State: AOJu0YyH9qA08ltER5OmpeA+4wsHgXYN2GEYe+BXbdzMYnev/XEnvTR4 yOZavktLXHc0IueKEf8yqZZ38H+1pnkc0CCXXtbG7mOhrCZf5iclV+Sn1R2GAZ26rmsS7y8wvcS HKDzp5l0b7w9RMXCL73b1mdr/71SbBBYsovcL X-Gm-Gg: ATEYQzydMvMeWEYxQTOjJ/IqXmTR73HXZjRp97AHwG3tQZMkv7KRk0WWLZNAuZrv0GA hgs0+oERcUGQNr2K70hrSYEZpAV44kN3vTwZHGFfkTWxSqAdg43EmXPhL1pJaRDpG2PCV7Tl0hf V83R7xFZnfCi0CWxTldofA7pjaSpDu1doXmL1u2aYnaGcnI2OTP/UX2CebiaABAx0NTOALRbQ1v coCDL/h6XX/kqFgWkbeph/fP7jJGDeaAz73QELIUJYifNZSKtIfZaapuGEb9Lz0PFvnkfAjxzUC 1Ma+s+QIq5o4VidFM13fY6JoLNhLJV3uFpETe8aS X-Received: by 2002:a17:906:f1d5:b0:b93:51df:dd23 with SMTP id a640c23a62f3a-b9764fd88a9mr38873366b.16.1773345944107; Thu, 12 Mar 2026 13:05:44 -0700 (PDT) MIME-Version: 1.0 References: <5a37c2e3-619d-4816-84d7-0b27e3e6797f@iki.fi> <26c766d6-db0f-43d3-a618-44f8d40a3121@iki.fi> <62b8dc23-8f6a-4cac-91ff-f74bb5bc159a@iki.fi> In-Reply-To: From: Robert Haas Date: Thu, 12 Mar 2026 16:05:32 -0400 X-Gm-Features: AaiRm53si8jFjVp7xr0pXIX1Wut9UAC8JTNHn2k5Bvnw8Stfr3ieFFBfloDQMa4 Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Heikki Linnakangas Cc: Ashutosh Bapat , 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 Thu, Mar 12, 2026 at 3:21=E2=80=AFPM Heikki Linnakangas wrote: > >> I'm currently leaning towards _PG_init(), except for allocations that > >> depend on MaxBackends. For those, you can install a shmem_request_hook > >> that sets the size in the descriptor. In other words, you can leave th= e > >> 'size' as empty in _PG_init(), but set it later in the shmem_request_h= ook. > > > > Why can't you just do the whole thing later? > > shmem_request_hook won't work in EXEC_BACKEND mode, because in > EXEC_BACKEND mode, ShmemRegisterStruct() also needs to be called at > backend startup. > > One of my design goals is to avoid EXEC_BACKEND specific steps so that > if you write your extension oblivious to EXEC_BACKEND mode, it will > still usually work with EXEC_BACKEND. For example, if it was necessary > to call a separate AttachShmem() function for every shmem struct in > EXEC_BACKEND mode, but which was not needed on Unix, that would be bad. That's *definitely* a good goal. A less important but still valuable goal is to maximize the notational simplicity of the mechanism. Your callback idea is elegant in theory but in practice it seems like it might make it harder for people to get started quickly on a new module, and having to create the object in one place and then fill in the size in another sort of has the same problem. I don't really know what to do about that, but it's something to think about. The complexity of getting the details right is annoyingly high in this area. > > Yeah, I think RequestNamedLWLockTranche() might be fine if you just > > need LWLocks, but if you need a bunch of resources, putting them all > > into the same chunk of memory seems cleaner. > > Agreed. Then again, how often do you need just a LWLock (or multiple > LWLocks)? Surely you have a struct you want to protect with the lock. I > guess having shmem hash table but no struct would be pretty common, thoug= h. Yeah, we've developed an annoying number of different ways to do this stuff. I don't entirely know how to fix that. --=20 Robert Haas EDB: http://www.enterprisedb.com