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 1vprK8-000DFl-0X for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Feb 2026 17:14:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vprK7-0003AM-11 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Feb 2026 17:14:52 +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 1vprK6-0003AD-34 for pgsql-hackers@lists.postgresql.org; Tue, 10 Feb 2026 17:14:51 +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 1vprK3-000000000oq-3oaG for pgsql-hackers@postgresql.org; Tue, 10 Feb 2026 17:14:50 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (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 4f9Sq91vwSzyW5; Tue, 10 Feb 2026 19:14:45 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1770743685; 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: in-reply-to:in-reply-to:references:references; bh=CQ20Io6O30qGL2hE6NV8yn5oWbnOdRSHLoezOSHB+gE=; b=xEFvpDgscG4ySQynKueKSlMFhiic0MuEOk9vEgNqkl/WZw07WvgoOgSEHplbdSUU1fiH5e cBnKtVWvQ9osMj/0zjcwpiXmwGoQ1lnAtls7B52+tDdlEa4XuwEfnnfhDgnmieDBaFZHyC rJ/RvO+Rh9ACM36WGZhEU7XpwCrnrVY= ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=meesny; cv=none; t=1770743685; b=bXIxOiNgCHk24oL60FU5F/6p28FUeU6tRrZAXpY90myBG1NX99CDJpA8oNtcMEP2fNSHw4 e/HvF3i0kmW9lLwIOqn3M3DkSAwl1XZ6ZWK2s7pea8r6/L13fWK+gzLS3X54EwTBpOEcAJ KgFIskL3ROyTsEbMb1Sxii9fmw/mwoQ= 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=1770743685; 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: in-reply-to:in-reply-to:references:references; bh=CQ20Io6O30qGL2hE6NV8yn5oWbnOdRSHLoezOSHB+gE=; b=TPvqoZ7hYWo0BA7LgG8bCkxlpmg4h3ih+Z4nXrMdXmeXKniT1I0NnCjD0v1/trtILjVTxO ZI6Lxg2+GLoswONGa6BPwU2ZOc/lVGayxk297oYMMtSLfD5n6ZzD/SYG04WAjWTjRDzoGB RiDQWRVDW0YTI00xmGl2+RMDLxfnCsk= Content-Type: multipart/mixed; boundary="------------tO07Ts5MzAV7Scwq6Q3jVTHb" Message-ID: <1cb0d7e9-d6dd-4517-a7cd-0ad98e1207f3@iki.fi> Date: Tue, 10 Feb 2026 19:14:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: PGPROC alignment (was Re: pgsql: Separate RecoveryConflictReasons from procsignals) To: Andres Freund Cc: Bertrand Drouvot , "pgsql-hackers@postgresql.org" References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------tO07Ts5MzAV7Scwq6Q3jVTHb Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit (moving to pgsql-hackers) On 10/02/2026 18:41, Andres Freund wrote: > On 2026-02-10 17:52:16 +0200, Heikki Linnakangas wrote: >> If there's a performance reason to keep have it be aligned - and maybe there >> is - we should pad it explicitly. > > We should make it a power of two or such. There are some workloads where the > indexing from GetPGProcByNumber() shows up, because it ends up having to be > implemented as a 64 bit multiplication, which has a reasonably high latency > (3-5 cycles). Whereas a shift has a latency of 1 and typically higher > throughput too. Power of two means going to 1024 bytes. That's a lot of padding. Where have you seen that show up? Attached is a patch to align to cache line boundary. That's straightforward if that's what we want to do. > Re false sharing: We should really separate stuff that changes (like > e.g. pendingRecoveryConflicts) and never changing stuff (backendType). You > don't need overlapping structs to have false sharing issues if you mix > different access patterns inside a struct that's accessed across processes... Makes sense, although I don't want to optimize too hard for performance, at the expense of readability. The current order is pretty random anyway, though. It'd probably be good to move the subxids cache to the end of the struct. That'd act as natural padding, as it's not very frequently used, especially the tail end of the cache. Or come to think of it, it might be good to move the subxids cache out of PGPROC altogether. It's mostly frequently accessed in GetSnapshotData(), and for that it'd actually be better if it was in a separate "mirrored" array, similar to the main xid and subxidStates. That would eliminate the pgprocnos[pgxactoff] lookup from GetSnapshotdata() altogether. I'm a little reluctant to mess with this without a concrete benchmark though. Got one in mind? - Heikki --------------tO07Ts5MzAV7Scwq6Q3jVTHb Content-Type: text/x-patch; charset=UTF-8; name="0001-Align-PGPROC-to-cache-line-boundary.patch" Content-Disposition: attachment; filename="0001-Align-PGPROC-to-cache-line-boundary.patch" Content-Transfer-Encoding: base64 RnJvbSBhM2UyZDk0ZjZhM2FiMjE1YWZkM2U4Y2VlNjI0YmQ5YzA5ZWM1MzkxIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBIZWlra2kgTGl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