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 1w9TGQ-001SfP-2h for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 19:36:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9TGP-004fWj-0z for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Apr 2026 19:36:05 +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 1w9TGO-004fWb-30 for pgsql-hackers@lists.postgresql.org; Sun, 05 Apr 2026 19:36:05 +0000 Received: from lahtoruutu.iki.fi ([185.185.170.37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w9TGM-00000000jYt-1qB5 for pgsql-hackers@postgresql.org; Sun, 05 Apr 2026 19:36:04 +0000 Received: from [10.0.2.15] (unknown [130.41.208.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4fpjPC4MG4z49Pxf; Sun, 05 Apr 2026 22:35:59 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1775417760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhPAvl+73Y2f4CsyXrQejdZbQsR8Z7vi5sAeqK+nYrA=; b=B6Z7ui5y7fYjwA8R6JfxEwcqFraBPY46n6QR6MEq/WTBeA/dcAa/Euy7lATf2IxwKdrCnn XbL6aDp2q9NF0NNXBYAiZk6q1x0JfiVMMEarTAhxXHaqAa4whR5tJRGrw3/0apWDNrvZ4Q J0bExgCoC4IeCl5QYuKd839Z6Ie1I+DtTipdX6hpjG26zcFkYudpU91VWhDKFXBKV8F11f eEke7RtJAeAscX86dc2QZtoSLqpCHn7uAnOlW0rSdfcSPklS4o100caR9VfZhllVNFsqSI RIx+xmJF11nsDxkffbzertn8/PtudyPP1F3rYMkMatPuvk0WDFEJaOQdntBk2w== ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1775417760; b=R4/QZFmPoH9rNNchWtYzJDdl34+lgZhZC+UDKRcEZDwwmynYnTU2JyitIMCSiR/RzQ2FKf sIlC7C6K7MuZfj+6PJEJttW+pXmM1KRBkKsTyB0JfbtUqxE8y2tLaul0MD5QalZEEpqwuy 9bnCcYH5n/ooqTuoBp8yM/rUW4dtgXi3UoB3YCIUtXZy4Vc5mHP9oSVkedvHeKAKjAX+ef yvS3FWsfgZyi2Pm94NZ7V9h36Kzj/Zn03sYHs//AnfPgwRyG37YC75V0c5T/0J1uZkYP00 WFr5y7Tx1k0iIxAx3Ms7vY2VhXAI//hB5uwY8cznTWOinZwI1EdZHrqDTkiK2A== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1775417760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhPAvl+73Y2f4CsyXrQejdZbQsR8Z7vi5sAeqK+nYrA=; b=M9m+4A8TuoDoubxCSnljfagQO2zZc0ZR1SwKkYyZwxD523aVFPNYT3vGZUvaYB7l3Vrej7 9Nv6pSyjFGa6oy5ODUI+/terMxkX021WeZ2RwDFYxOO2KWxjvAranmKPqIxoJSagxUiMwt jdCHoe5FZiXw5jh9rsrGiIqCv3qKv8u2Vx5qjVr98bAOOByXQcG9tlt3D0p4LvIuNbcbwp u9am0YkcKAL9q1jGX4i1GKymbWO1jU919jcgCD041rg8Pu0s9AyqT5WYJjQleXtWADkbsa 5Tfbybyc3wHhPgBdpJSEdDVTl1fI2Sg5w+vGxjAoNJSzDS3IpwGaNRdDu7ECIg== Message-ID: <9de1782f-c30d-48c5-9b15-5d36da5f0fa4@iki.fi> Date: Sun, 5 Apr 2026 22:35:58 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Better shared data structure management and resizable shared data structures To: Matthias van de Meent Cc: Ashutosh Bapat , Robert Haas , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com References: <113724ab-0028-493f-9605-6e8570f0939f@iki.fi> <791c3f18-f4de-4d84-ac6b-c7ccc074dd38@iki.fi> <9d919bd9-94dd-4bda-8ccf-ebced4178c53@iki.fi> <470e7ebe-0971-49f6-8e46-9b8f6395f88b@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 04/04/2026 16:51, Matthias van de Meent wrote: >> +++ b/src/include/storage/shmem.h >> +/* >> + * Shared memory is reserved and allocated in stages at postmaster startup, >> + * and in EXEC_BACKEND mode, there's some extra work done to "attach" to them >> + * at backend startup. ShmemCallbacks holds callback functions that are >> + * called at different stages. >> + */ >> +typedef struct ShmemCallbacks > > Maybe this should also have the opportunity for a (before_)shmem_exit callback? Hmm, yeah, perhaps, but I'm going to skip that for now. We already have a mechanism for shmem-exit callbacks, and I'm not sure how that would plug into this. I think we can do that later if it turns out to be a good idea, and I don't think it changes the parts that's included in the patches now. >> + * on-demaind in a backend. If a subsystem sets this flag, the callbacks are >> + * called immediately after registration, to initialize or attach to the >> + * requested shared memory areas. > > Ideally we only immediately call the callbacks if we're under > postmaster, or in a standalone backend; we shouldn't allocate shmem > for some preloaded libraries that set this flag, at least not ahead of > loading all preload libraries. Right, the SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP flag doesn't do anything if called during shared_preload_libraries processing. I'll re-word the comment to clarify that. > While it's mostly mechanical changes, it did make me notice the rather > annoying allocation patterns by XLOGShmemRequest. It allocates various > types of data in one go (which, in principle, is fine) but in doing so > it adds its own alignment tricks etc, and I'm not super stoked about > that. If time allows, could we clean that up? I'm not going to cram it into these patches, but +1. - Heikki