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 1t3nKl-00EgyM-Ex for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Oct 2024 02:12:19 +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 1t3nKj-00Fngg-OK for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Oct 2024 02:12:18 +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 1t3nKj-00FngL-Ej for pgsql-hackers@lists.postgresql.org; Thu, 24 Oct 2024 02:12:17 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t3nKd-002XpU-CL for pgsql-hackers@postgresql.org; Thu, 24 Oct 2024 02:12:16 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-37d4fd00574so267492f8f.0 for ; Wed, 23 Oct 2024 19:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729735930; x=1730340730; darn=postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=1d9gtk7V9MaolqnnWbeIu+w/Cyfc49SV0ELTsCZIoqE=; b=NQxyG/plyBgPU40kFuM7lvFsoy5imHhzEa7ny2v9DsavRSpeH+slK7lh1LsrjfXnNN 5j2GH4ak1a2aEncUo/DV88pUq6tNUf3TXGs9DPkFbRz6+XKUK6RMIanQ1WUCo1E+Nr7r 3wNAvSgw9q0Ya26zU2HZKY/FsCWX1Pf4nCvK2V9koRrgn/dzYPuFNTZJ892sK0TYIqAE LV2TdPfJfFDnUcH9Cj5bjS9I2OIzUmo6WhXKuAsd/iFEqLwAojulzbhNy73eT9ipC03x BimiSpGNSXC/SxGRquuMkdaeI43SFu+7HW9UGiy5N/E5q+x76XoQbD3drDwppcJ2UFei QOng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729735930; x=1730340730; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1d9gtk7V9MaolqnnWbeIu+w/Cyfc49SV0ELTsCZIoqE=; b=aRwF6RxnUf69vDrfXD6d2xCRDPlk2bMc5z9lYeuhfVx040kworhCr4btJ1VxnMCaph +LFc9wIM10LrC2kbYHgzQmyltSnCnFv5zzNvtxbXLm5SO75QZelEE7+7wZUsrVQT2fJZ sbDnsi2QefJnZcmo4O/QPjHPbwgVS0xxVl7VVDu7aZrpgSTj4wY5FkHYWb/38URL6N9O QFySxl5vxzb0sXDtEmFZdz2ajkCn3utBJXGQaBxhV0bOieJydAmWXkW9VRzPGoXR5keC 4CWshn5P5MvIpDmtHt9MfQ8uiEEI51B1yDZFEmoZaj/K9oOcsH3SXU3TDqjv9hJjvaKP jwsg== X-Gm-Message-State: AOJu0YxsBKXrMKWZj99jLM6b37VrA3aC/EK+5D4mXCgdCX00T28SbUh+ Tmqwy3gADgSa9anV1yxIS4qVpqGZztQj/LkuF+j9+M7ot5BI3sncOCmHKTeT X-Google-Smtp-Source: AGHT+IE2wls+YxdoxNEkSaUKnvkVWuW5R+k2Dyg3mtqGP3d9CSQTXs5EgafHoSAqkNawF+wY/J2RYA== X-Received: by 2002:a5d:534c:0:b0:37d:443b:7ca4 with SMTP id ffacd0b85a97d-3803ac4a080mr199561f8f.14.1729735929508; Wed, 23 Oct 2024 19:12:09 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ee0b9bc90sm10104683f8f.100.2024.10.23.19.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 19:12:09 -0700 (PDT) Date: Thu, 24 Oct 2024 02:12:07 +0000 From: Bertrand Drouvot To: Fujii Masao Cc: pgsql-hackers@postgresql.org Subject: Re: Refactor GetLockStatusData() by skipping unused backends and groups Message-ID: References: <5a0f78d1-0f56-439b-b4d3-2bae9d262c6c@oss.nttdata.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5a0f78d1-0f56-439b-b4d3-2bae9d262c6c@oss.nttdata.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Oct 23, 2024 at 01:19:37AM +0900, Fujii Masao wrote: > > I understand that PGPROC entries with pid=0 are typically those not yet allocated to > any backends. Yes, as you mentioned, prepared transactions also have pid=0. However, > GetLockStatusData() loops up to ProcGlobal->allProcCount, which is MaxBackends plus > NUM_AUXILIARY_PROCS, excluding prepared transactions. Therefore, GetLockStatusData() > doesn't seem to check PGPROC entries for prepared transactions at all. > > In proc.c > -------------- > /* XXX allProcCount isn't really all of them; it excludes prepared xacts */ > ProcGlobal->allProcCount = MaxBackends + NUM_AUXILIARY_PROCS; > -------------- Oh right, thanks for pointing out! > I removed the period at the end to match the usual convention in the codebase > for single-line comment. > > I've attached v2 patch. Thanks for the new version! > You mean adding an assertion check to ensure that the slot ID calculated by > FAST_PATH_SLOT() is less than FP_LOCK_SLOTS_PER_BACKEND? Yes. > But GetLockStatusData() > already calls FAST_PATH_GET_BITS() right after FAST_PATH_SLOT(), > and FAST_PATH_GET_BITS() has an assertion that validates this. Oh right, it's "already" in FAST_PATH_GROUP() (and FAST_PATH_INDEX()). > So, probably > we can consider that this check is already in place. If it’s still worth adding, > perhaps placing it inside the FAST_PATH_SLOT() macro could be an option... > Or current assertion check is enough? Thought? Given that it's already done in FAST_PATH_GET_BITS(), I think that's fine as it is and v2 LGTM. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com