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.94.2) (envelope-from ) id 1t8xhW-006xGc-2O for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 08:17:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t8xhT-00DSY5-H7 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 08:17:08 +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.94.2) (envelope-from ) id 1t8xhS-00DSXx-Ah for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 08:17:07 +0000 Received: from fout-b8-smtp.messagingengine.com ([202.12.124.151]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t8xhN-000e96-SV for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 08:17:06 +0000 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id BDC09114010E; Thu, 7 Nov 2024 03:17:00 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 07 Nov 2024 03:17:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1730967420; x=1731053820; bh=qvrjlDbEEP eELW7qlT9jQzg9pnlCi1mloPnZfjEwiuQ=; b=MMrUL2+38pw5J3Yd4cWk5qcHvM 1IR5tIl3TqstU4UyTJCBfgBppa/IyygYcfhIKWupejRXozSSUPn6G6sRzUJfJiXD zLSH3LcrJ23MIyAP7m6QgetvJqvFhEevOEkH/8F4V98eGfv63jDdONLYwRV1Ukwj UUS7zd3r85rtTYYUlIkxYTEwwyg17IfN4sjjBtSntj8IgFXuEkuizM8qRfmsMDKE oKvHSuPTwQ/UC7ywWe/i2108WCPSiWR/sqlN2tPGdxQ3luQF4LIdjX1avU0OJHSV ESdf4y95CPHWXeb18xJfFqVvgqfBXDePBKBXiUMP1MXiFQdMpdgqMupw1nUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1730967420; x=1731053820; bh=qvrjlDbEEPeELW7qlT9jQzg9pnlCi1mloPn ZfjEwiuQ=; b=cilINfN3jxQlmsACpoeIvEgs5gPD59Dnc92Xf0vCuFhyzTB5H70 bgJ7aahw66BRSSgNdiw/aeowZTgd8wjqFr5ymuwaaiGoyXAv/TEt4Esy88fCElCm ZJHU1LcTHe/WmgvawGmLts+OBneBOI2e5K0sIm7dNs5RxP59c9VOFEG7u7fdetjh OTcPNkpLFv11z+8+Qpulablpo7tD40/nL0SFRiqFxJUJcXmBBS/P3LqkVwL9XsoC Y8Q4qigLzztBM+JxYSaPvnYD4amjwBdgCacjlQrs94z+S8NBsZdo8/h/7CVRt+C1 nPO4VkATxsTIfTUYkxBvicNlRkJN7vcZaog== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdefgdduudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteel ieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouh htpdhrtghpthhtoheplhhithhskhgvvhhitghhkhgrrhhinhgrsehgmhgrihhlrdgtohhm pdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvg hsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 7 Nov 2024 03:16:59 -0500 (EST) Date: Thu, 7 Nov 2024 17:16:51 +0900 From: Michael Paquier To: Karina Litskevich Cc: Postgres hackers Subject: Re: pg_stat_statements: Avoid holding excessive lock Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5M+apD7tAdVWvGot" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --5M+apD7tAdVWvGot Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Nov 05, 2024 at 08:37:08PM +0300, Karina Litskevich wrote: > I suggest eliminating holding the excessive lock. See the attached patch. > This would also restore the consistency between the code and the comments > about entry's mutex spinlock usage. You are right. minmax_stats_since and stats_since are only set when an entry is allocated or reset, so this is not going to matter. > + /* > + * There is no need to hold entry->mutex when reading stats_since and > + * minmax_stats_since for (unlike counters) they are always written > + * while holding pgss->lock exclusively. We are holding pgss->lock > + * shared so there should be no race here. > + */ > stats_since = entry->stats_since; > minmax_stats_since = entry->minmax_stats_since; > - SpinLockRelease(&entry->mutex); The comment could be simpler, say a "The spinlock is not required when reading these two as they are always updated when holding pgss->lock exclusively.". Or something like that. -- Michael --5M+apD7tAdVWvGot Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmcsd3MACgkQnvQgOdby QH1E3Q//dVtD256Iw9kKYLhV1wgx/M6t0XqP1UKEBQ1z13+SM2D1Qpmi/eky6oje pEGcyGfRrz1ID8jNmhwdbrO2YsFdm/EWgjlO2LDfryB64gzDlFlrzAWmrq/nrTtC cJLDu/qiUxOymotpFWlzw13BtgURM2s8pkBxozMD0PM9Av80D/TQTeUoH88yJmWr 9U2HQAhezvyV5kx34EVRthQ0E7LPZ8DfbeHC796J6/Q/GTiqphW3uCbItZdtCybs AXgv+AvmR06qG7uwuUudsia4tNnzVlDhLYGWIsKu8qApWziQQAke6EwP2Q8uD5dR cH179dqOqBLqOAAAHC4lmsJJa3jbPJCJgJd8P6pTgdJjtql1E3AiwBk7OT/VlG0I 6wFsiFDjR0j3GLEPS63IGsgpd7mjXN4rSe/NiXDPYIU0RubOL+O7pAjMzGZXTFfp uJ30/ruDdK8g1fTV/xBgEE1j0sBZ/E5yhJkOU0HS3JVnkcC6ie95Al5qZkcWU3kD ujbUXkUYqCKuSNoqCjnMTQ1sI+gJaHDFVhIgBYlBSJUf2p8ms+o9M/pm3srlFrpL 8UZ/XTh2hf6Hsb8Q5Hr9tghu6468IqvOnORQ9w/eMT1awHJq1ObV1p1SGkVT7Bcq l5ND8KVb0/bX5NSFCP3jYDbT+T5REu85rNv9VSlgLFLErohGP2A= =hRf7 -----END PGP SIGNATURE----- --5M+apD7tAdVWvGot--