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 1w7uEP-0000tk-0X for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 11:59:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7uEN-00HKGf-1j for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 11:59:31 +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 1w7uEN-00HKGX-0S for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 11:59:31 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7uEL-000000000Ik-2Gy1 for pgsql-hackers@postgresql.org; Wed, 01 Apr 2026 11:59:30 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-43d02a71526so1730515f8f.3 for ; Wed, 01 Apr 2026 04:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775044767; cv=none; d=google.com; s=arc-20240605; b=HQsIbMpbsyyB541kZX2031zevn0ZokL1i8I9rhW0gMTGTHLfKfraJU8l4/TiqK7Nze XvxzJF+U2B4rAxb2nFud7XmiJGFFOwTylA/ymZz0b40YrRYR89Ytb2172xtBkYYs19aE z3Yeku6JYyRrX5GMiCh0QlzA2n+BVHBxHAFeklZBe8BuFBPjpedxuH0JRCzRN0mVxMa/ jvxrxXJ1Wy6poduMwPt6GQSS8vfMNK5zHePcHmD/vJYhkWXpA4xepE9gaIzI2njgdOs1 W7mg6EnzP1QZKVykD62ZZI/oq1Lwe0B+IC66HWcEzizYfqVGHdiJeu+O9WU5pW/U5ZZC sYLg== 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=x/YxLt7zTEXprmL8fIxKBfTL7BD5BoKWKsxsxflU90I=; fh=JlEP7acfdfsOH34qEXjxRUqSZbYxZwzgke47ws1SQm8=; b=LZhRS5a8jDcQ8LAcHExiTwwZFtwTFD/vmwTTuGyQcIzzdqw1rnR6a+o3/zkgNDR1Sb xGXYCPCgaBUXSYB4hZZTqm2AgVLlIxgj+3nbInSg6i0/u9ywHZivrHq2x2LeYP3jssvq UIryqpaF+jdc0XqdYx9eb5t4ZD88OovWMccXeQAQN+J0WlleJ2r5cMxy2U+tSYbahTfP jfDFnfpkYs+8IHLOHRfrf0N36mho62rVV3n+3tVCVDkUZddWTKFlb5nSfV6K3UT+bCGy He73+6FQNuAI/KKPWqjMV8GdpP1K8u+f4lYVeAMt90CiB2Ly0tfTxI5PP+KT6xynyV1f ZByQ==; 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=1775044767; x=1775649567; 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=x/YxLt7zTEXprmL8fIxKBfTL7BD5BoKWKsxsxflU90I=; b=oJt4dShcFq724zfVHEQC9zy36Y4ZDO7KVteqa9y/NHhIwHQlAj4XQwpyA+QGcw3WIb rExPX9szTv0iAQ4y6Ie4/nIX97zkGIsqwSCQRC+SRXMPMLqbBbiCGGWcsYxrRXIVQzzN yHCWosJ4lvmFBZrTln3cxEiGj4X0/XtAJY5kipmuV/fkF2SMcycLquAjmvmit3zm/XNa AvB4jvBNGnkqg4hG+oThHcl6NX828Znh6uUKixUO1+lkH2tSXX0EMzdazT2qGrWTNNYk kWDAYSIsDMbp9xsVA8tFHNrbt/wRC5N/VfgAjz/kIlz2Ncj1HoHYKyORn8tWHT2ZtBTq rXAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775044767; x=1775649567; 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=x/YxLt7zTEXprmL8fIxKBfTL7BD5BoKWKsxsxflU90I=; b=JvCTlL7S8f465QdfSOgoLs1Rm7JyBT/COLrTRWxwgas2GLt/gYZ73eUjgaPDPCErIE qGMNSxE0mtyM6ZBdqz8gg291VhZouFLowFCnih1GA+8NPkiWGpxom0n5GPQZlqPRn6ah 3u2jQJYiQimLawXORglcq7E/l4nolMmGqGrfvEJLXUxG33Xgrrpo1LZFdhVUJO7OWkP3 3a9+X57U6H/K53UT1X/2XpfH3V1eFfdCEUIpOYm6Oyf/0zsyOBB63Yfk/9VmrPiHpXZV 3ahbsDCBx+etyzc0VNBw03p/EjnmU6Aa7BDI2HMfpYbSu0tLXUB9wbCh+7Ar/ZP3h1wq FCUg== X-Forwarded-Encrypted: i=1; AJvYcCVmoVsj7QmrIikhIsLx53TrMyE4ceDwG67aYsceshPpU4Zt0j+tVVEWje7KgsUxtiJJ7rqhWwL8pH+Nw2JH@postgresql.org X-Gm-Message-State: AOJu0YyBqu19ng/+g8iXplkIOGZE0hqyYmZiqSeBISr6PMbz5Bc7KS7l IM3MlaUxyU26EpOJ4Ix8qb0vLLD0P9g03pQXlTW11vj+uUAD0GrTLObXD2Fb0KEQQuGLdrd7bvI JZrtLBukjE4gy2LzA5LE863htughrlGk= X-Gm-Gg: ATEYQzxN4CjVEZ8aWSdqiocXY3Jkx+OZcqzwoH/pCyIGSAXsbQjdahyla3M1CmqzaGV OTHzbn3tyZzFWCWiwlxmfoaRh3G+cHWJC8i2yGp0/ClZAgmRZ9cOp6DPQa3EVBtLm5d/eb2InGp WsnfJB5D2cP7+hRr1e8LsYVSOE3ZkHbdY+ny/LkSQuu0WveOnPOuSrzXu92fUmf7MBunNPDlyWf FY8WeawC9NSPwMcu2vzVydpXaYf7ZYp6rCInT8UrjjBM/zgr49lBn5sF8ZAHxbdqYZ/JfX8aD3Q BFJpZOLI5ud9IFu7qoIqxOv1fvFLlCPeUTZWQKrSuGN7nYZLDu8= X-Received: by 2002:a05:6000:240b:b0:43c:fed2:bb78 with SMTP id ffacd0b85a97d-43d150f7da8mr6125938f8f.44.1775044767091; Wed, 01 Apr 2026 04:59:27 -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> In-Reply-To: <791c3f18-f4de-4d84-ac6b-c7ccc074dd38@iki.fi> From: Ashutosh Bapat Date: Wed, 1 Apr 2026 17:29:13 +0530 X-Gm-Features: AQROBzCW55PDHnxwoVY5Lh1WQUMHRXtJadNLb9c7QgswTzcSqY_x9tpMrhrAF8k 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="000000000000ce45a6064e64d0ba" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ce45a6064e64d0ba Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 31, 2026 at 1:45=E2=80=AFAM Heikki Linnakangas wrote: > > On 30/03/2026 07:50, Ashutosh Bapat wrote: > > On Sat, Mar 28, 2026 at 4:47=E2=80=AFAM Heikki Linnakangas wrote: > >> On 27/03/2026 09:01, Ashutosh Bapat wrote: > >>> /* Restore basic shared memory pointers */ > >>> if (UsedShmemSegAddr !=3D NULL) > >>> + { > >>> InitShmemAllocator(UsedShmemSegAddr); > >>> + ShmemCallRequestCallbacks(); > >>> > >>> It's not clear how we keep the list of registered callbacks across th= e > >>> backends and also after restart in-sync. How do we make sure that the > >>> callbacks registered at this time are the same callbacks registered > >>> before creating the shared memory? How do we make sure that the > >>> callbacks registered after the startup are also registered after > >>> restart? > >> > >> On Unix systems, the registered callbacks are inherited by fork(), and > >> also survive over crash restart. With EXEC_BACKEND, the assumption is > >> that calling a library's _PG_init() function will register the same > >> callbacks every time. We make the same assumption today with the > >> shmem_startup hook. > > > > RegisterShmemCallbacks() may be called after the startup, and it will > > add new areas to the shared memory. How are those registries synced > > across the backends? From your answer below, those registries are not > > synced across backends. They will be wiped out by the restart and > > won't be registered again. Is that right? I think we need to document > > this fact and also the need to call RegisterShmemCallbacks() from all > > the backends where the new areas are required after the startup. > > Correct. Ok, I'll add a note to comment on RegisterShmemCallbacks() to > call that out more explicitly, hope it helps. > > - Heikki > Continuing review starting 0007 ------- Subject: [PATCH v8 07/16] Add test module to test after-startup shmem allocations I like the idea. + * + * XXX This module provides interface functions for C functionality to SQL= , to + * make it possible to test AIO related behavior in a targeted way from SQ= L. + * It'd not generally be safe to export these functions to SQL, but for a = test + * that's fine. This mentions test_aio - needs to be rewritten for test_shmem. + +#include "access/relation.h" +#include "fmgr.h" +#include "miscadmin.h" +#include "storage/shmem.h" I don't think we need access/relation.h. Others seem ok, but I haven't chec= ked. In order to better test the difference between EXEC_BACKEND and non-EXEC_BACKEND builds, please consider incorporating the attached patch v8-0009-edits.diff 0008 ------ - LWLockRelease(AddinShmemInitLock); + /* The hash table must be initialized already */ + Assert(pgss_hash !=3D NULL); Does it make sense to also Assert(pgss)? A broader question is do we want to make it a pattern that every user of ShmemRequest*() also Assert()s that the pointer is non-NULL in the init callback? It is a test that the ShmemRequest*(), which is far from, init_fn is working correctly. /* - * If we're in the postmaster (or a standalone backend...), set up a shmem - * exit hook to dump the statistics to disk. + * Set up a shmem exit hook to dump the statistics to disk on postmaster + * (or standalone backend) exit. */ - if (!IsUnderPostmaster) - on_shmem_exit(pgss_shmem_shutdown, (Datum) 0); - - /* - * Done if some other process already completed our initialization. - */ - if (found) - return; + on_shmem_exit(pgss_shmem_shutdown, (Datum) 0); Given that the structures are registered only at the startup, this function will be called only from Postmaster, but given that the structures can be registered and initialized after startup in any backend, it's better to at least Assert(!IsUnderPostmaster) at the beginning of this function. The code below is not expected to be called in any backend too. So Assert(IsUnderPostmaster) at the beginning of the function would be good safety catch too. /* + * Load any pre-existing statistics from file. + * * Note: we don't bother with locks here, because there should be no other * processes running when this code is reached. */ I was a bit worried that the code next to read stat files is being crammed in init_fn, but given that the contents of the files are used to initialize the shared hash table, I think this is fine. 0009 ------- +void +RegisterBuiltinShmemCallbacks(void) +{ + const ShmemCallbacks *builtin_subsystems[] =3D { +#define PG_SHMEM_SUBSYSTEM(subsystem_callbacks) &subsystem_callbacks, +#include "storage/subsystemlist.h" +#undef PG_SHMEM_SUBSYSTEM + }; + + for (int i =3D 0; i < lengthof(builtin_subsystems); i++) + RegisterShmemCallbacks(builtin_subsystems[i]); +} + I don't think we need to use a separate array here, we can just call RegisterShmemCallbacks() directly in the macro as attached. 0011 ------ + InjectionPointAttach("aio-process-completion-before-shared", + "test_aio", + "inj_io_short_read", + NULL, + 0); + InjectionPointLoad("aio-process-completion-before-shared"); + + InjectionPointAttach("aio-worker-after-reopen", + "test_aio", + "inj_io_reopen", + NULL, + 0); + InjectionPointLoad("aio-worker-after-reopen"); Attaching and loading an injection point shouldn't be part of the shared memory initialization. It doens't feel like it should be part of shmem_startup_hook as well. So not a fault of this patch. I am wondering why can't it be done in the tests themselves? 0012 ------ @@ -663,6 +663,8 @@ SubPostmasterMain(int argc, char *argv[]) */ LocalProcessControlFile(false); + RegisterBuiltinShmemCallbacks(); + Shouldn't this be part of the previous patch? -void -InitProcGlobal(void) +static void +ProcGlobalShmemInit(void *arg) { I have reviewed most of this patch in earlier versions of this patchset except this part, which is better than its last version. Will continue to review the rest of the patches tomorrow. --=20 Best Wishes, Ashutosh Bapat --000000000000ce45a6064e64d0ba Content-Type: application/octet-stream; name="v8-0007-edits.diff.nocibot" Content-Disposition: attachment; filename="v8-0007-edits.diff.nocibot" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mnfyu1p90 ZGlmZiAtLWdpdCBhL3NyYy90ZXN0L21vZHVsZXMvdGVzdF9zaG1lbS90LzAwMV9sYXRlX3NobWVt X2FsbG9jLnBsIGIvc3JjL3Rlc3QvbW9kdWxlcy90ZXN0X3NobWVtL3QvMDAxX2xhdGVfc2htZW1f YWxsb2MucGwKaW5kZXggODRlYzg0MWI1NDIuLmMxNTRmNTc2ODJhIDEwMDY0NAotLS0gYS9zcmMv dGVzdC9tb2R1bGVzL3Rlc3Rfc2htZW0vdC8wMDFfbGF0ZV9zaG1lbV9hbGxvYy5wbAorKysgYi9z cmMvdGVzdC9tb2R1bGVzL3Rlc3Rfc2htZW0vdC8wMDFfbGF0ZV9zaG1lbV9hbGxvYy5wbApAQCAt MzIsMTIgKzMyLDE4IEBAICRub2RlLT5zdGFydDsKIAogIyBXaGVuIGxvYWRlZCB2aWEgc2hhcmVk X3ByZWxvYWRfbGlicmFyaWVzLCB0aGUgYXR0YWNoIGNhbGxiYWNrIGlzCiAjIGNhbGxlZCBvciBu b3QsIGRlcGVuZGluZyBvbiB3aGV0aGVyIHRoaXMgaXMgYW4gRVhFQ19CQUNLRU5EIGJ1aWxkLgor bXkgJGV4ZWNfYmFja2VuZCA9ICRub2RlLT5zYWZlX3BzcWwoInBvc3RncmVzIiwgIlNIT1cgZGVi dWdfZXhlY19iYWNrZW5kOyIpIGVxICdvbic7CiAkYXR0YWNoX2NvdW50MSA9ICRub2RlLT5zYWZl X3BzcWwoInBvc3RncmVzIiwgIlNFTEVDVCBnZXRfdGVzdF9zaG1lbV9hdHRhY2hfY291bnQoKTsi KTsKICRhdHRhY2hfY291bnQyID0gJG5vZGUtPnNhZmVfcHNxbCgicG9zdGdyZXMiLCAiU0VMRUNU IGdldF90ZXN0X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AjaW5jbHVkZSAiZm1nci5oIgogI2luY2x1ZGUgIm1pc2NhZG1pbi5oIgogI2luY2x1 ZGUgInN0b3JhZ2Uvc2htZW0uaCIK --000000000000ce45a6064e64d0ba Content-Type: application/octet-stream; name="v8-0009-edits.diff.nocibot" Content-Disposition: attachment; filename="v8-0009-edits.diff.nocibot" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mnfyu1pf1 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3N0b3JhZ2UvaXBjL2lwY2kuYyBiL3NyYy9iYWNrZW5k L3N0b3JhZ2UvaXBjL2lwY2kuYwppbmRleCAyMTdmNTI5MTI3MC4uMmEzN2JiMTU5MzYgMTAwNjQ0 Ci0tLSBhL3NyYy9iYWNrZW5kL3N0b3JhZ2UvaXBjL2lwY2kuYworKysgYi9zcmMvYmFja2VuZC9z dG9yYWdlL2lwYy9pcGNpLmMKQEAgLTE4MywxNCArMTgzLDkgQEAgQ3JlYXRlU2hhcmVkTWVtb3J5 QW5kU2VtYXBob3Jlcyh2b2lkKQogdm9pZAogUmVnaXN0ZXJCdWlsdGluU2htZW1DYWxsYmFja3Mo dm9pZCkKIHsKLQljb25zdCBTaG1lbUNhbGxiYWNrcyAqYnVpbHRpbl9zdWJzeXN0ZW1zW10gPSB7 Ci0jZGVmaW5lIFBHX1NITUVNX1NVQlNZU1RFTShzdWJzeXN0ZW1fY2FsbGJhY2tzKSAmc3Vic3lz dGVtX2NhbGxiYWNrcywKKyNkZWZpbmUgUEdfU0hNRU1fU1VCU1lTVEVNKHN1YnN5c3RlbV9jYWxs YmFja3MpIFJlZ2lzdGVyU2htZW1DYWxsYmFja3MoJihzdWJzeXN0ZW1fY2FsbGJhY2tzKSk7CiAj aW5jbHVkZSAic3RvcmFnZS9zdWJzeXN0ZW1saXN0LmgiCiAjdW5kZWYgUEdfU0hNRU1fU1VCU1lT VEVNCi0JfTsKLQotCWZvciAoaW50IGkgPSAwOyBpIDwgbGVuZ3Rob2YoYnVpbHRpbl9zdWJzeXN0 ZW1zKTsgaSsrKQotCQlSZWdpc3RlclNobWVtQ2FsbGJhY2tzKGJ1aWx0aW5fc3Vic3lzdGVtc1tp XSk7CiB9CiAKIC8qCg== --000000000000ce45a6064e64d0ba--