pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Eliminate divide in new fast-path locking code
Date: Sat, 26 Apr 2025 23:53:59 +0000
Message-ID: <E1u8pLK-001wsp-2X@gemulon.postgresql.org> (raw)

Eliminate divide in new fast-path locking code

c4d5cb71d2 adjusted the fast-path locking code to allow some
configuration of the number of fast-path locking slots via the
max_locks_per_transaction GUC.  In that commit the FAST_PATH_REL_GROUP()
macro used integer division to determine the fast-path locking group slot
to use for the lock.

The divisor in this case is always a power-of-two value.  Here we swap
out the divide by a bitwise-AND, which is a significantly faster
operation to perform.

In passing, adjust the code that's setting FastPathLockGroupsPerBackend
so that it's more clear that the value being set is a power-of-two.

Also, adjust some comments in the area which contained some magic
numbers.  It seems better to justify the 1024 upper limit in the
location where the #define is made instead of where it is used.

Author: David Rowley <drowleyml@gmail.com>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://postgr.es/m/CAApHDvodr3bcnpxcs7+k-3cFwYR0tP-BYhyd2PpDhe-bCx9i=g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/936457419d797dfaf37191db53d5efb1279eae6d

Modified Files
--------------
src/backend/storage/lmgr/lock.c   |  5 ++++-
src/backend/utils/init/postinit.c | 34 +++++++++++++++-------------------
src/include/storage/proc.h        |  8 ++++++++
3 files changed, 27 insertions(+), 20 deletions(-)



Message-ID: <E1u8pLK-001wsp-2X@gemulon.postgresql.org>
Permalink:  ../E1u8pLK-001wsp-2X@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1u8pLK-001wsp-2X@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Eliminate divide in new fast-path locking code
  In-Reply-To: <E1u8pLK-001wsp-2X@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox