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 1tQy8e-006Oy6-3R for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Dec 2024 00:23:36 +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 1tQy8c-005mJr-4y for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Dec 2024 00:23:33 +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.94.2) (envelope-from ) id 1tQy8b-005mH7-5v for pgsql-hackers@lists.postgresql.org; Fri, 27 Dec 2024 00:23:33 +0000 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tQy8Z-000ioJ-02 for pgsql-hackers@lists.postgresql.org; Fri, 27 Dec 2024 00:23:31 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 3D21013801C5; Thu, 26 Dec 2024 19:23:30 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 26 Dec 2024 19:23:30 -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 :message-id:mime-version:reply-to:subject:subject:to:to; s=fm2; t=1735259010; x=1735345410; bh=Tq8NRHcZyVzrcpa8bPOjcfF8OiQY3whM Yr/Ql/pOwiQ=; b=jBxvaSxnzNtu7+FY0A3w4798Xn5k0BviEYuyXAtrG12+wqGo u1lm+iwWA6s1WBIhs3+1BN/Ic1U2oHwB/oDCZIBh22nEjm1XC7cEZpnofMDgQpGZ bNgyP5CQKKtZ1dgmruxsYJy4t2y8bA5ioPsviDJRKA+yQ47dJTRaEvudaiDP7ZiF oBzusfPe8Y9PRc9Z43NWggKyxzU5nv1WdtKY4MBVkCnEfion/fQBHEjCiIvz2ikW tNN+/9/0tSWTL2A9XtnWu+iKf1KJ/XPNKG+WO7zT2QozVGHI7lHA6E2lg9Dsg852 T6uffcPnXR5DULJ/x8LGlG/E0cnfT8T1KBCGTA== 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:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735259010; x= 1735345410; bh=Tq8NRHcZyVzrcpa8bPOjcfF8OiQY3whMYr/Ql/pOwiQ=; b=i +1uR/AdkPDSqr/do195aZQrytsFWIqr8JScq0Fsw02l0aEfBxBo5t42dDcNlYPsg Tf/vuOgImtQuLJP46Sw+W5L2DC/PUUdiAruX174wxV73vJS8U3LahORGicVl9FMB gMXIrQYT47e0SrCeNecyNSUR84+h/I/QI6YBDh2NxvXgf+iq1ECGECkeEPek57YF O+JlihD+iyfRTit6KwAZYT/g22ia3kF+4B11PwoYsTo0QdZZDGmYsBA6A4Cm2nVb abQi/rq2HRFKltmsYDffrcfb/895gcgSTMTTn2d4w0FeDkoZvqViJI/tOFiOSJxE S+vJOEorJYMFFf1U/avPw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudduledgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfgg tggusehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomh hitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgeffkedu feeutdffteevgeduvdffveduuefgudffgfelhfeludeghfejfeffteeinecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgr qhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghs qhhlrdhorhhgpdhrtghpthhtohepsggvrhhtrhgrnhguughrohhuvhhothdrphhgsehgmh grihhlrdgtohhm X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Dec 2024 19:23:27 -0500 (EST) Date: Fri, 27 Dec 2024 09:23:12 +0900 From: Michael Paquier To: Postgres hackers Cc: Bertrand Drouvot Subject: Fix handling of injection_points regarding pending stats Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XVDjTINYhr5PlByi" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --XVDjTINYhr5PlByi Content-Type: multipart/mixed; boundary="Ei5FCfEnZZLhcy4e" Content-Disposition: inline --Ei5FCfEnZZLhcy4e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, While doing more stuff related to pgstats and WAL, I have bumped on the fact that the module injection_points uses for its variable-numbered stats a pending flush callback but it does not handle its entries so as these would be handled locally first, with a final flush timed by pgstat_report_stat() that would itself call the pending flush callback. This is a less efficient practice, because it requires to touch the pgstats dshash more often than necessary. This is caused by the use of pgstat_get_entry_ref_locked() rather than pgstat_prep_pending_entry() which would make sure to time the flush of any pending entries appropriately depending on pgstat_report_stat(). I'd like to fix the module so as the flush timing is controlled like all the other stats kinds, which is a better and more efficient practice to have anyway as this code should stand as a template for custom pgstats kinds. While doing so, I have also noticed that injection_stats_flush_cb() missed a pgstat_unlock_entry() when entries get locked. All that is addressed in the patch attached. Feel free if you have any comments. Thanks, -- Michael --Ei5FCfEnZZLhcy4e Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-injection_points-Tweak-variable-numbered-stats-to-wo.patch" Content-Transfer-Encoding: quoted-printable =46rom d0aae1f873ec4f0cde91d851d131767e7ca66171 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Fri, 27 Dec 2024 09:16:02 +0900 Subject: [PATCH] injection_points: Tweak variable-numbered stats to work wi= th pending data As coded, the module was not using pending entries to store its data locally before a flush to the central dshash is done with a timed pgstat_report_stat() call. Hence, the flush callback was defined, but finished by being not used. As a template, this is more efficient than the original logic of updating directly the shared memory entries as this reduces the interactions that need to be done with the pgstats hash table in shared memory. injection_stats_flush_cb() was also missing a pgstat_unlock_entry(), so add one, while on it. --- .../modules/injection_points/injection_stats.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/test/modules/injection_points/injection_stats.c b/src/test= /modules/injection_points/injection_stats.c index e16b9db284..21d5c10f39 100644 --- a/src/test/modules/injection_points/injection_stats.c +++ b/src/test/modules/injection_points/injection_stats.c @@ -80,6 +80,9 @@ injection_stats_flush_cb(PgStat_EntryRef *entry_ref, bool= nowait) return false; =20 shfuncent->stats.numcalls +=3D localent->numcalls; + + pgstat_unlock_entry(entry_ref); + return true; } =20 @@ -127,13 +130,13 @@ pgstat_create_inj(const char *name) if (!inj_stats_loaded || !inj_stats_enabled) return; =20 - entry_ref =3D pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidO= id, - PGSTAT_INJ_IDX(name), false); + entry_ref =3D pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid, + PGSTAT_INJ_IDX(name), NULL); + shstatent =3D (PgStatShared_InjectionPoint *) entry_ref->shared_stats; =20 /* initialize shared memory data */ memset(&shstatent->stats, 0, sizeof(shstatent->stats)); - pgstat_unlock_entry(entry_ref); } =20 /* @@ -168,16 +171,14 @@ pgstat_report_inj(const char *name) if (!inj_stats_loaded || !inj_stats_enabled) return; =20 - entry_ref =3D pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidO= id, - PGSTAT_INJ_IDX(name), false); + entry_ref =3D pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid, + PGSTAT_INJ_IDX(name), NULL); =20 shstatent =3D (PgStatShared_InjectionPoint *) entry_ref->shared_stats; statent =3D &shstatent->stats; =20 /* Update the injection point statistics */ statent->numcalls++; - - pgstat_unlock_entry(entry_ref); } =20 /* --=20 2.45.2 --Ei5FCfEnZZLhcy4e-- --XVDjTINYhr5PlByi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmdt83AACgkQnvQgOdby QH0NdA//e5+XD34x67enTP9oEb362a3TpDhg5+lhm7MYnoGSQX4LIDicAQejr4kA o+vHAyon6LgNLagPsseZafSXSN2QE2SZEll0mII+S5ZiKLMs5YB2obAXfDBDPTwJ Hppni00P3oJieTi5uf2Jjw1jempTIrHkkycYATnvNZzTPR49aPMwHyxlmnvgqBXT 1YD958Zrccg1QD3N860pgnodS7HKeV7tYJ0jPt5fJTl2+xavOoqNdNAsVUkeQzMn 36UNYe6CkR/iKbzFm9k7hXRAs0meeCIRXgYjfg52YUHnmKQ+ZdmoQvnScmJgQYJ6 cNEeQAgLEtDDLKwFmxGEb6gL9412aq/nxFoOw3a7LMeXY8n7I4sp/xV/CZDfb8uG FmUXZmNo8vc2HEIDQfQHyT231RCfOkqUOLRh/k2RAx4KSOrFLoRIvjrhnRa3BMtg itUMwPHitwOgxL1MN5HbzGwGJCh87xh86tmNc4YpEB3HOVmsbRmTdoe7iY+sNG+/ D2p6dxqDSMwPzshp8n4Fk4AnKtDPdNknmIYjyiUaCI0ny8P4JXsA3rCxwihLn7he zHysEQHqxajRlzvFDSSPe6+TlOGFo3Q25HqSrvtwlDPAMuExBtnaHTzILdccquHC b6wdjUMfjAC4iz/7Bf7GkieK0Xodm/LXlTKxnI9Mqz/+9APyMio= =2AaJ -----END PGP SIGNATURE----- --XVDjTINYhr5PlByi--