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 1w8QFL-000W4c-14 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 22:10:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8QFK-008J3N-0F for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 22:10:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w8QFJ-008J3F-26 for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 22:10:38 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w8QFI-00000000Fo3-10yS for pgsql-hackers@postgresql.org; Thu, 02 Apr 2026 22:10:37 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-386b553c70eso12411441fa.0 for ; Thu, 02 Apr 2026 15:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775167833; cv=none; d=google.com; s=arc-20240605; b=eQlsp24E77HunKNzKTS4a8ps01BnKQtXNca+QcG2CGLc7loRimz6iL6czFLYYP17aV qoSIO0+zD42IX/XsVlOotYAq9XxzUWxZxfyueIq0F36BrYGbGEEGuK9dzcrdvbOmmMi4 dPD2NrZY/t6xis6U6VTazFvmsLR/IaNN4dfPvZK3tpdpI6RYRDpGLS8OwTIaLhPeFbBB +Rv8TNNN8SpPa/Ts6Jimwp+TOWKwLKOJw9xkWkQGSDKzpASJPi6nuyOQtrW77dWc9iVw +DTLpBJrCqIoR0cyPzrf1AKyclQGzBK6mkGcp3gwQazyCSi5Hr1KuZnH7BAzq+JKhZO+ AtWg== 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=r3KnD0Sr/GY14qHlk17r1ijx+Ktqt8ouRj1CGqPyETE=; fh=lsbNQh5NSZqOH4Q/apUZQpamAz+CqjatDsTZGcsA4Ls=; b=h51mNFEOFr8+blm8h5Uy98txs5KJBjC+8LI0FZzA0Yz6o4CmaIyN8PGhJ4sL4K69do c1Zr7rVD0o9PiG0diRo9Lo25dRWE1I1q4u8N5gnlIPEenGbtZvExpMooF60tMq3w6D5b HCBcnlQW9ldeOEHtGYTjBFOCMYpNEqfodfr4F+NSvWg/5Ka9p6UxOSDdrCVgoJuAP2Zj xAmov9XX7e1PK1XjWdLLiQkkJnqgBYwfSAiajJjwqqM5hLsfdXt9vljlmXu3xUGaq2UV kSxpcZZL9QE+BYLeAv/W8R1vxp8KnQTG0ZYqrvV63V3BhEG/woFLyPT91Ou9WWWdiihU aIRQ==; 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=1775167833; x=1775772633; 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=r3KnD0Sr/GY14qHlk17r1ijx+Ktqt8ouRj1CGqPyETE=; b=LEwr+Hx1UACQm2YfZAQjTXCwjBJg4NNkK7qKBBcuLkSGqznJ+rJiQfpG6MsgLgNTPB pFRnc1s0f73JZwtAJavflNkTJBizbunaC7aDWLxzCx/GPShE8jLwNQstZ1yBQWvyl3ZA KQpohvScZ9nqGm8I2Y3RqXp5p+G0bRoSnO0LyK9KXHyMEhIv0FcDgQNWZl6dJPRtm+z5 4TEtP5LHB0xV+EfHASb3X46KeAvqlbgRJv2QUOcdCsSOxxANbLfT7Or98VXiwb9rnJLy LLrM/4zolmAnTeC8xUhSHntSZfAKwp8YZZ7IM8LZHWKiyLKXgpzHzgecMMXVFyGmLp1w PXXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775167833; x=1775772633; 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=r3KnD0Sr/GY14qHlk17r1ijx+Ktqt8ouRj1CGqPyETE=; b=EauMovGDteu8/mCLPkJRozxkd2H4uXOXIh2b1ODDJf/C/V2+nUeI3GwVKNJ0WSvJFN tyIetDqcIbQo7P2F3uw3c8gxOoNxEhwLVsoHuFkAW9B9m+XMgN4NTFoYA4sxFIVo3dwm WAgX0Pbx7ijfWeRPfs308io6Jq02hvbVeey1pP+0GMsCX2BtqgEreLKfmLq/NyLH4Dft jQmO6fW1EjbfU3siObaelQULOIBEc+82bmsQOxl9rO8zO9kAO0EpvAffNBP+RtHbMcVu fO05o7soGDAabYqjfZi/YYmgI+uNkPLhpuZbFGw5TY1BYchzwm5EgGVxkdIhwD6eQ4EO 1Q1g== X-Forwarded-Encrypted: i=1; AJvYcCV3qcuo7SJw0/NsvaxK2aNfSdDLPBcT2C5SLtT9Eqah03H0DSWCKvhDVwYXqA22LN+hK6TR4JxLgPcZ2VQ+@postgresql.org X-Gm-Message-State: AOJu0YzlN1y2kR4QKvcWezCTydkcsKUNJVPyeKS6gZLmbx+6PgPlMtbb NDPS8Io7b/a1PBlD1PzVVugFkEkzZ6AK8Ha7dPyE8Hq0Wo4yUBxzyC7B7QnyT1BfbbzHuOCYBeQ cioEa+zo1wMQ2RvhvqLd6CdoMbazFWHo= X-Gm-Gg: AeBDiesLbrKqUOg+R4jfFVOtrr4Gmi+tmP1laGPolfZDcB1wxqwyfu0H31jTO+Tg5yV AVgmF5QR5MvldGN2TAhnSPls4vYSVPwK1RdNEJ1vvY7Cpf9R0WmdtUvEKUzDdA1WLpYGWS7aioK e8OzVRJWn4CwX7l6KRGvLbUMxzTh2ufD51CsVwUOz2ek6g+QODIdueL6Z5ZXbyhmUJGx/j0l/Fw rUVuFw1n65rkbHxlB33CykjYc92i11iljGltERidFXQ6nVyt1tioudD//4+HpSmVdTWXYk82uTC 23Mbd6uBx08g8XPiitVCwDJk7sx3uzyKIMYX3DgdC/hbO4pfkJASrgnWMUFVcPQUDqgjYpXXqm7 6ea6kUAncFzfQYDc= X-Received: by 2002:a2e:be0f:0:b0:38a:3374:f908 with SMTP id 38308e7fff4ca-38d91c187b5mr1571891fa.16.1775167833206; Thu, 02 Apr 2026 15:10:33 -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> In-Reply-To: <9d919bd9-94dd-4bda-8ccf-ebced4178c53@iki.fi> From: Matthias van de Meent Date: Fri, 3 Apr 2026 00:10:21 +0200 X-Gm-Features: AQROBzD6aW9mrKfqaN1l8lMg2THc6zm8EvVkj11TXHJB5_2iCMuaJ_S25JHMz7c 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" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 1 Apr 2026 at 20:17, Heikki Linnakangas wrote: > > Yet another version attached (also available at: > https://github.com/hlinnaka/postgres/tree/shmem-init-refactor-9). The > main change is the shape of the ShmemRequest*() calls: I didn't read the whole thread, as it's quite long, but did look at the patchset for a while to figure out where it's going. 0005: A few assorted comments: 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? 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? > +++ b/src/backend/storage/ipc/shmem.c [...] > + /* Check that it's not already registered in this process */ > + foreach_ptr(ShmemStructDesc, existing, pending_shmem_requests) > + { > + if (strcmp(existing->name, options->name) == 0) > + ereport(ERROR, > + (errmsg("shared memory struct \"%s\" is already registered", > + options->name))); > + } > + > + request = palloc(sizeof(ShmemRequest)); > + request->options = options; > + request->desc = desc; > + request->kind = kind; > + pending_shmem_requests = lappend(pending_shmem_requests, request); Apparently, pending_shmem_requests is a list of ShmemRequest, but the iteration just above on the same list assumes ShmemStructDesc, which seems wrong to me. 00017: I like this idea, but I think it missed its chance to make good on an opportunity to reduce waste in alignments: We know which structs we're going to allocate at which alignments, so we could save space by packing the structs. I don't expect it to save much, but it could be a few 100 of kbs with a few BLCKSZ-aligned allocations. Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)