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 1rh1bT-009CM1-8Z for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 06:15:11 +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 1rh1bR-00594z-2N for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 06:15:09 +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 1rh1bQ-00594r-PU for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 06:15:09 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rh1bN-002kfp-9Y for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 06:15:08 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-513382f40e9so2009749e87.2 for ; Sun, 03 Mar 2024 22:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709532905; x=1710137705; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=52KbcPy1C8NSERQfmH9UNjvgqMuJHBzY4q333+G+z80=; b=FmWthcFgUbn/7h6rAzzPDyiBHbZIqxq26KiLoB0lbU9erP6s2Llx8G4Mumh27sIwgB GEgu4lwhubmy0fYpEO9zFHb9tE8nbYMiPiv+06NOvOr6eeWNvQOoRW1fjSYjIJFQxpHh NSzI5T4IlptfleQ1pbvt6J+TmOK7pn+QkGdM5LIEePktC7gr0GuVXHwihxrR8sLTFfK+ w3zrApFCZzNySrQjC0v5LlOxU6/Pf1OStSqgyLTeP6nQG3tvwDsKY+NaLQ/zHxFklEru zcZ2qJhpNGkzOrwFoiMn5sp/XV9wz3liwrVXLkgxm/NwDgwUhWMKQJsqcyPNfLOXuRbY Lxjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709532905; x=1710137705; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=52KbcPy1C8NSERQfmH9UNjvgqMuJHBzY4q333+G+z80=; b=FLO/nAckTcHYB9GwdG85qzEYTfE+Qg2z/PwxWAubfhPN7+SIN894yvCMuyJ68OXy61 kmU8ibFMcDkRKvQqbIiy8iMHKULZioNYECKwFkwiILET+eGAscAD3AvKWXXjxzE9mhG+ fB+heCfoq54VyVb5zj/62HUtCSuschPRT7fxy8tI9Skx84gYqKQlBQuCYwjlObdn39Uy yKYNTkLWf55W55G3cBmsbX8iW1yAYptBIUAvaZHb0XtbY/P4Qb9ZVx9bHGTowu8Ixq8t /J1pYPM1BZBLj4Hjx70CkzpCQuUtZwRGakBFUQBU/UiVrBYGQK4SCFR5WQbUhuWFI0cw Nc0A== X-Gm-Message-State: AOJu0Yzre0KYLkIFWxWDeBYtWeNTScO5yqrQZ825MJOfVWqSB5ZICcOf m8PzpcrP29rL9QrCt3oMy2Hiz0UuiEJWEFuqIwM/UmA+nAZ6/vH1WLU9TMOi39LXoYvo1bw2L2s 8Tn5FF5m0l5bFrkL2kHFXaePV0Wg= X-Google-Smtp-Source: AGHT+IHH9FtW33eTMrE4GREP33JZacuc2fvi1ksiG7nK263ZybJEiqqz2xj3hA7iuhR0VJf1T9JPTh9eMYJ1HQK4xeI= X-Received: by 2002:ac2:5508:0:b0:512:bdd3:1539 with SMTP id j8-20020ac25508000000b00512bdd31539mr5153399lfk.37.1709532904502; Sun, 03 Mar 2024 22:15:04 -0800 (PST) MIME-Version: 1.0 References: <202403031429.zvfh7chvuk24@alvherre.pgsql> In-Reply-To: <202403031429.zvfh7chvuk24@alvherre.pgsql> From: Dilip Kumar Date: Mon, 4 Mar 2024 11:44:48 +0530 Message-ID: Subject: Re: pgsql: Improve performance of subsystems on top of SLRU To: Alvaro Herrera Cc: pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 4, 2024 at 1:56=E2=80=AFAM Alvaro Herrera wrote: > > On 2024-Feb-28, Alvaro Herrera wrote: > > > Improve performance of subsystems on top of SLRU > > Coverity had the following complaint about this commit: > > _________________________________________________________________________= _______________________________ > *** CID NNNNNNN: Control flow issues (DEADCODE) > /srv/coverity/git/pgsql-git/postgresql/src/backend/access/transam/multixa= ct.c: 1375 in GetMultiXactIdMembers() > 1369 * and acquire the lock of the new bank. > 1370 */ > 1371 lock =3D SimpleLruGetBankLock(MultiXactOffsetCtl, pageno)= ; > 1372 if (lock !=3D prevlock) > 1373 { > 1374 if (prevlock !=3D NULL) > >>> CID 1592913: Control flow issues (DEADCODE) > >>> Execution cannot reach this statement: "LWLockRelease(prevlock);"= . > 1375 LWLockRelease(prevlock); > 1376 LWLockAcquire(lock, LW_EXCLUSIVE); > 1377 prevlock =3D lock; > 1378 } > 1379 > 1380 slotno =3D SimpleLruReadPage(MultiXactOffsetCtl, pageno, = true, multi); > > And I think it's correct that this is somewhat bogus, or at least > confusing: the only way to have control back here on line 1371 after > having executed once is via the "goto retry" line below; and there we > release "prevlock" and set it to NULL beforehand, so it's impossible for > prevlock to be NULL. Looking closer I think this code is all confused, > so I suggest to rework it as shown in the attached patch. > > I'll have a look at the other places where we use this "prevlock" coding > pattern tomorrow. + /* Acquire the bank lock for the page we need. */ lock =3D SimpleLruGetBankLock(MultiXactOffsetCtl, pageno); - if (lock !=3D prevlock) - { - if (prevlock !=3D NULL) - LWLockRelease(prevlock); - LWLockAcquire(lock, LW_EXCLUSIVE); - prevlock =3D lock; - } + LWLockAcquire(lock, LW_EXCLUSIVE); This part is definitely an improvement. I am not sure about the other changes, I mean that makes the code much simpler but now we are not releasing the 'MultiXactOffsetCtl' related bank lock, and later in the following loop, we are comparing that lock against 'MultiXactMemberCtl' related bank lock. This makes code simpler because now in the loop we are sure that we are always holding the lock but I do not like comparing the bank locks for 2 different SLRUs, although there is no problem as there would not be a common lock address, anyway, I do not have any strong objection to what you have done here. --=20 Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com