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 1rbkTa-00Gnu8-CZ for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Feb 2024 16:57:14 +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 1rbkTX-00ANGA-Q6 for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Feb 2024 16:57:11 +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 1rbkTX-00ANG2-GV for pgsql-hackers@lists.postgresql.org; Sun, 18 Feb 2024 16:57:11 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rbkTP-007OIR-6h for pgsql-hackers@postgresql.org; Sun, 18 Feb 2024 16:57:09 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6e0f43074edso2060955a34.1 for ; Sun, 18 Feb 2024 08:57:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1708275422; x=1708880222; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ghc8eh5gGfv9xUz4SEX5vKJTHcA+Tg+uj1CbRKNuqqE=; b=Xk5ilkehwVK2skQSAswg61KDzM8nbCWMOT162rcs0PH+cc7b6bB0UP9XVTSQzhkkzS 0wzuWFDZO9BRAar6CpvRh5vIk9cXvXKVuxsp4DNIGKaPhAeTCJi0CXegYDyRoINCco8b wBgdlZtaf5q3gL9GB+LI1rEDjUEbi77rK6zgosQGmegWpFq6xAR9IZuc+Uh92HGyNsGi +DRQGOm+MEM/NQF/jzeDPZInLEBqjW2do7uFFGWJdA+rPqthxifthQwsdxM/vyUeBAfs G8kFevS/FyhnvtAPS3A2cukkVeF4dIrEM8B3Gq3JRG6hEsZ9kkJ0fg3OBCgVS/jwCdOe spQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708275422; x=1708880222; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ghc8eh5gGfv9xUz4SEX5vKJTHcA+Tg+uj1CbRKNuqqE=; b=ToB3rOfnDzC/fC3xL3RFmyrQ6i0MoawgtX0/WCgCeF4FKue93Yat1gbQMkZnM2m4IQ iaiffV8OocSDoPzquFD0nprNVBnII6kw+RL9wuLz4l8xNfhdcKA43UEgSBDe9nMhGGwn I8T2vpV/3mxn9jq29jbdoBQuwaiYk0hN26E8t5ueA+sIAMytmvpuGzInhhj7OHB0ebLa WYvEnFj2yPmELEXGfAi16ATH1N2n3klMN9Wz+bFLg+3RfSx3GpgwhrMywuafyIa5c8Rc fmc7YpHh8oEdEmH9829iE6gupO0Z16YNOVuI+MaT5gbtdt0b/MYTlZI8nyO/qKUxvpyl PpPQ== X-Forwarded-Encrypted: i=1; AJvYcCUSOHmpdCrMyn9UZbQUOBXoVisF1WcRa1wyip6lPGmifmDCNVrgA+2I74O6DKhxG3h+LsiHa0hYOIPGDt8H76vPKOuE+3URy1ReZL+p X-Gm-Message-State: AOJu0YxdieF2E+QnS0e7R2OB/szj8Vz+kzIJsbtXEshP8XINFs5lX0wS O5ZcJiRXOrfjkhrUZhTkSF3w9EU79AclCqCArcNehusjddoa0QhS1wNMofdtVw== X-Google-Smtp-Source: AGHT+IHFmZ1kTpOWt+p3q/URex44jaRV4+ZrMbqbBQTGzsBEQRtFb1Fu4Cq7Zrj9Rhkw9YbrPDevGQ== X-Received: by 2002:a9d:73c7:0:b0:6e2:ea4c:6475 with SMTP id m7-20020a9d73c7000000b006e2ea4c6475mr8820226otk.14.1708275422102; Sun, 18 Feb 2024 08:57:02 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id t25-20020a9d5919000000b006e2dfaa9317sm680942oth.18.2024.02.18.08.57.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Feb 2024 08:57:01 -0800 (PST) Message-ID: <8c4a5f06-7476-4646-bb8a-6581a26b0650@enterprisedb.com> Date: Sun, 18 Feb 2024 17:56:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Thoughts about NUM_BUFFER_PARTITIONS Content-Language: en-US To: Li Japin Cc: wenhui qiu , Heikki Linnakangas , PostgreSQL-development References: <7335b43e-6d79-4e8c-a33b-e4e864a0a46c@enterprisedb.com> <5C838C5E-D89C-495C-A0E2-87FC683462CD@hotmail.com> From: Tomas Vondra In-Reply-To: <5C838C5E-D89C-495C-A0E2-87FC683462CD@hotmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/18/24 03:30, Li Japin wrote: > > >> On Feb 10, 2024, at 20:15, Tomas Vondra wrote: >> >> On 2/8/24 14:27, wenhui qiu wrote: >>> Hi Heikki Linnakangas >>> I think the larger shared buffer higher the probability of multiple >>> backend processes accessing the same bucket slot BufMappingLock >>> simultaneously, ( InitBufTable(NBuffers + NUM_BUFFER_PARTITIONS); When I >>> have free time, I want to do this test. I have seen some tests, but the >>> result report is in Chinese >>> >> >> I think Heikki is right this is unrelated to the amount of RAM. The >> partitions are meant to reduce the number of lock collisions when >> multiple processes try to map a buffer concurrently. But the machines >> got much larger in this regard too - in 2006 the common CPUs had maybe >> 2-4 cores, now it's common to have CPUs with ~100 cores, and systems >> with multiple of them. OTOH the time spent holing the partition lock >> should be pretty low, IIRC we pretty much just pin the buffer before >> releasing it, and the backend should do plenty other expensive stuff. So >> who knows how many backends end up doing the locking at the same time. >> >> OTOH, with 128 partitions it takes just 14 backends to have 50% chance >> of a conflict, so with enough cores ... But how many partitions would be >> enough? With 1024 partitions it still takes only 38 backends to get 50% >> chance of a collision. Better, but considering we now have hundreds of >> cores, not sure if sufficient. >> >> (Obviously, we probably want much lower probability of a collision, I >> only used 50% to illustrate the changes). >> > > I find it seems need to change MAX_SIMUL_LWLOCKS if we enlarge the NUM_BUFFER_PARTITIONS, > I didn’t find any comments to describe the relation between MAX_SIMUL_LWLOCKS and > NUM_BUFFER_PARTITIONS, am I missing someghing? IMHO the relationship is pretty simple - MAX_SIMUL_LWLOCKS needs to be higher than NUM_BUFFER_PARTITIONS, so that the backend can acquire all the partition locks if needed. There's other places that acquire a bunch of locks, and all of them need to be careful not to exceed MAX_SIMUL_LWLOCKS. For example gist has GIST_MAX_SPLIT_PAGES. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company