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 1wheqV-000Lg0-1B for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 02:50:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wheqT-00AW0d-2n for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 02:50:38 +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.96) (envelope-from ) id 1wheqT-00AW0Q-1t for pgsql-hackers@lists.postgresql.org; Thu, 09 Jul 2026 02:50:38 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wheqS-00000000FdT-1b9E for pgsql-hackers@postgresql.org; Thu, 09 Jul 2026 02:50:37 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-44cb057311bso828110fac.0 for ; Wed, 08 Jul 2026 19:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783565436; x=1784170236; darn=postgresql.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=x8Gp3Y//fJgCg9xRNBSUbjH6G+SzbwCvPU0BicEWbhc=; b=jLvZQ2JnxqY3xVhLCVXsQLEiQPhSx5GxMOw2u0BVSY8stGwFNEj+8I4C/g7zjOFarw wPV9EU9Khggt2AgQHUy+wl7vzIPnxxsk1Uv1irSmelqefbUXKBeMIV5XGSbNvbbM2FBc GUsGMUBx6drEIu/F0sEoY+7+7H+Hj8yqrVKAW8eJl7lMSBRvX3I06p4OfYooyrIdeH53 pKTa2Rd752DYZRFZdFdB3YhPkoIxSEwdPNcIQjefxxiDNGQlct2WU4BJ6xVfVsugTTZl mma59uF7XYbssLnRoeIMFh4HCaRYvIXYjyv6ERhnLasCdDDlmIaaxg0hnNybHbqhZItn ICkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783565436; x=1784170236; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=x8Gp3Y//fJgCg9xRNBSUbjH6G+SzbwCvPU0BicEWbhc=; b=DPdw+xOlBMrA9qCI5VXdkvCho1Jq28U/edLJg5mmWQYMKfkLKKSPpSFfMXUHvZsSV6 V6VX9b2OuQM+Hm9pIzWyJ4PjPYTN/48z4jJT/An+q7F++VzlQLgHsfao1c9xpgGiksPv y+SLFZgSkH6JYRWnTkvHDbFgWcJ1Tpbp4gV7bMFNmoXhueCfJPDjZ2hG9C7sc+QHmPqg 6Shi3mQGVXJTkbJzaz8vXHNxLkLbl8k3g3TqVrBFuIy2P9npY2DbTMsyoVMIIqT0Ev6d t9mW9qzumAggAITD3NG4QOSJOLnjY2a8NCen9o2BJhmAfqs+a9CdKL7yIKnbC0rT/A7v SSEQ== X-Gm-Message-State: AOJu0YynOaZkMI+8m3+djlkDhGajPTg9xzj5fnSWYHfTlADXtR7yAJIa xZVcqT8UeIbnFRw//582SO2ksCQDGYhOmQyanTtjr8EiPr4swFwTSt8hPLhr3Q== X-Gm-Gg: AfdE7clLXwV65jNc9/hsbQXG/5fYch77tiXOlkVl6y0qWVlKGuBGUIU74hAHx1JlJLM F4N6tBLljR9SSvBbaKTXaHIMs2UHZnENBZ91/xBgX3R18auDzBduwM/QBHuOKPy7gUqTsCbEYQ/ zrHQC6DkRCcYcDzxKxVC3wS1kwOOsFRi8yw/frt6L5tWSVxJO8kR7Tg106+MQTm4zPZyZePuCYX Sa2nPmFdfqETrqGOB9byQgEN77M+WaIfeBBH3L57QX3QAZXUV2Hj+uIxRSf6AelzxDRnYF4h2FE gwZsAYZGemnTLx0+Gr81OQy87y/ViUnffdgnBlxEXPewYAzurDStKFs+Z1T9kq6wi1EFRoWrERk SoSfALFBQ6iB0Wey/NHY3POOf3k3obTW53WdA5QZY8328wlCQme0SoOPGk8aQBa3BDLWF88b2gX /S/5gUakJZEOKaDMlyvrdUCQEZvWzQrdvCDYk5SK/WhdKX92pXqaQKwHkszeXZLjZYO/DC757V1 zBZmDSU7eM= X-Received: by 2002:a05:6870:d893:b0:43b:4d09:5bab with SMTP id 586e51a60fabf-4516376b946mr3381344fac.4.1783565435845; Wed, 08 Jul 2026 19:50:35 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-45191643b1fsm712999fac.10.2026.07.08.19.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 19:50:35 -0700 (PDT) Date: Wed, 8 Jul 2026 21:50:33 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Cc: michael@paquier.xyz Subject: remove WaitEventCustomCounterData Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="65l7A33W789+zwjF" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --65l7A33W789+zwjF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline While trying to understand the extent of our spinlock usage, I noticed that WaitEventCustomCounterData->mutex is unnecessary because the counter is only ever accessed with WaitEventCustomLock held exclusively. So, here's a patch to simplify matters a bit. Thoughts? -- nathan --65l7A33W789+zwjF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-remove-WaitEventCustomCounterData.patch From 6fe5fb011363d1fc96f97412e0665d13216147b6 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 8 Jul 2026 21:50:04 -0500 Subject: [PATCH v1 1/1] remove WaitEventCustomCounterData --- src/backend/utils/activity/wait_event.c | 29 ++++++------------------- src/tools/pgindent/typedefs.list | 1 - 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c index 95635c7f56c..7ee6f99fb50 100644 --- a/src/backend/utils/activity/wait_event.c +++ b/src/backend/utils/activity/wait_event.c @@ -81,14 +81,7 @@ typedef struct WaitEventCustomEntryByName /* dynamic allocation counter for custom wait events */ -typedef struct WaitEventCustomCounterData -{ - int nextId; /* next ID to assign */ - slock_t mutex; /* protects the counter */ -} WaitEventCustomCounterData; - -/* pointer to the shared memory */ -static WaitEventCustomCounterData *WaitEventCustomCounter; +static int *WaitEventCustomCounter; /* first event ID of custom wait events */ #define WAIT_EVENT_CUSTOM_INITIAL_ID 1 @@ -110,8 +103,8 @@ const ShmemCallbacks WaitEventCustomShmemCallbacks = { static void WaitEventCustomShmemRequest(void *arg) { - ShmemRequestStruct(.name = "WaitEventCustomCounterData", - .size = sizeof(WaitEventCustomCounterData), + ShmemRequestStruct(.name = "WaitEventCustomCounter", + .size = sizeof(int), .ptr = (void **) &WaitEventCustomCounter, ); ShmemRequestHash(.name = "WaitEventCustom hash by wait event information", @@ -134,9 +127,8 @@ WaitEventCustomShmemRequest(void *arg) static void WaitEventCustomShmemInit(void *arg) { - /* initialize the allocation counter and its spinlock. */ - WaitEventCustomCounter->nextId = WAIT_EVENT_CUSTOM_INITIAL_ID; - SpinLockInit(&WaitEventCustomCounter->mutex); + /* initialize the allocation counter */ + *WaitEventCustomCounter = WAIT_EVENT_CUSTOM_INITIAL_ID; } /* @@ -221,19 +213,12 @@ WaitEventCustomNew(uint32 classId, const char *wait_event_name) } /* Allocate a new event Id */ - SpinLockAcquire(&WaitEventCustomCounter->mutex); - - if (WaitEventCustomCounter->nextId >= WAIT_EVENT_CUSTOM_HASH_SIZE) - { - SpinLockRelease(&WaitEventCustomCounter->mutex); + if (*WaitEventCustomCounter >= WAIT_EVENT_CUSTOM_HASH_SIZE) ereport(ERROR, errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("too many custom wait events")); - } - - eventId = WaitEventCustomCounter->nextId++; - SpinLockRelease(&WaitEventCustomCounter->mutex); + eventId = (*WaitEventCustomCounter)++; /* Register the new wait event */ wait_event_info = classId | eventId; diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index ffb413ab612..3174e0e4ab8 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -3418,7 +3418,6 @@ WaitEvent WaitEventActivity WaitEventBuffer WaitEventClient -WaitEventCustomCounterData WaitEventCustomEntryByInfo WaitEventCustomEntryByName WaitEventIO -- 2.50.1 (Apple Git-155) --65l7A33W789+zwjF--