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 1wF5iY-004jno-2K for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Apr 2026 07:40:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wF5iV-007KSS-3D for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Apr 2026 07:40:20 +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 1wF5iV-007KSK-2G for pgsql-hackers@lists.postgresql.org; Tue, 21 Apr 2026 07:40:19 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wF5iT-00000002GNb-1bI0 for pgsql-hackers@postgresql.org; Tue, 21 Apr 2026 07:40:19 +0000 Received: from [10.0.2.15] (unknown [137.83.235.84]) (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 meesny.iki.fi (Postfix) with ESMTPSA id 4g0Dlz3cM0zyQH; Tue, 21 Apr 2026 10:40:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1776757216; 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=d7R73hq7rVNVq9g4LtJUx/LdM1Mcb4viN2jjXD3t4k8=; b=e+roC+Jn++S9ZUcjWQmIPBhHXNuAed5qJ19UiDG8+IJKcIlVp1aR/dXGPvplZ/1MX5YtnK Z5UqKs8+XakH7bYvJxxzPIMjiNaKfXVSzmP52rCHjBBsImVor2DuMTzf3u9IZfpDw8n23L 15GehsGisqdSQQHPaOyZQRgCcDhaD2A= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1776757216; b=hQUuDSAgPF6mGvbpex/uER4rxSPFXTt40h49e9K480eQCBxuNi1vuDkrltveKtS2AZ0QfP 9hQpT35nAszscJx4HuUvDXlQQfhFqm2eqAUjRpBk+j/e1W9XfzozyCiX5v2w7HFclQ6Up3 mBXdKn9/0fhYwzJ8Gwson6ICYrarBR4= 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=meesny; t=1776757216; 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=d7R73hq7rVNVq9g4LtJUx/LdM1Mcb4viN2jjXD3t4k8=; b=Suk8mGzek3fbL5kmgqTXLZAUuZIJ6y8kXfGdK5JydfA8Ob5f1ymMQerJ2xgs3oiAfBdLP/ iYW0rgr0IcDb/VMbrxdC+IhwH9pLbAh3oqT8xw5tGMggi85r0PhsBuSF9zixZvDXShdITW DILjjS8mffxNQXQuXH53f8gqLb5KX/k= Message-ID: Date: Tue, 21 Apr 2026 10:40:14 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Better shared data structure management and resizable shared data structures To: Ashutosh Bapat Cc: =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= , 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> <87y0iz2c1v.fsf@wibble.ilmari.org> <4297b4ee-5248-415f-ae12-abf2a23f4ab6@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 07/04/2026 17:19, Ashutosh Bapat wrote: > Hi Heikki, > CallShmemCallbacksAfterStartup() holds ShmemIndexLock while invoking > init_fn/attach_fn callbacks. That looks wrong. Before this commit, > init or attach code was not run with the lock held. Any reason the > lock is held while calling init and attach callbacks. Since these > function can come from extensions, we don't have control on what goes > in those functions, and thus looks problematic. Further, it will > serialize all the attach_fn executions across backends, since each > will be run under the lock. This was intentional, I added a note in the docs about it: When RegisterShmemCallbacks() is called after startup, it will immediately call the appropriate callbacks, depending on whether the requested memory areas were already initialized by another backend. The callbacks will be called while holding an internal lock, which prevents concurrent two backends from initializing the memory area concurrently. That "internal lock" is ShmemIndexLock. I piggybacked on that since the code needs to acquire it anyway for the hash table lookups. With the old ShmemInitStruct() interface, extensions needed to do the locking themselves, usually by holding AddinShmemInitLock. (Now that I read that again, the grammar on the last sentence sounds awkward...) > In my case, the init_fn was performing ShmemIndex lookup which > deadlocked. It's questionable whether init function should lookup > ShmemIndex but, it's not something that needs to be prohibited > either. Yeah I'm curious what the use case is. We could easily introduce another lock or reuse AddinShmemInitLock for this. - Heikki