Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pjJG8-0008Nj-0O for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Apr 2023 12:26:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pjJG6-000537-SG for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Apr 2023 12:26:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pjJG6-00051W-HE for pgsql-hackers@lists.postgresql.org; Mon, 03 Apr 2023 12:26:02 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pjJG4-0003NX-3H for pgsql-hackers@postgresql.org; Mon, 03 Apr 2023 12:26:01 +0000 Received: by mail-ed1-x536.google.com with SMTP id ew6so116530567edb.7 for ; Mon, 03 Apr 2023 05:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1680524758; 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=2uLzKleAtwS70FCPUxJe9wc6ztcLdIj8Gn2KoEsegIY=; b=PGQLzzGJb5PRfsgwNqagQ5hKKXiZgFtFSWeHn28qYUCDtp34xga+MltVZQZVYilNot dNsNLZmoJoZT0kLXOBlGQBOdWQApWV53iZuIZf3FGYWiTkj7aLMZxwibEhtmxWqswtE9 akX8TJc2wP9GxT6geUtSTITi79lXmosDHBz8lcwUIRxgd/9z1C0iaOA7VR6/LmwI+bvb g0Ycyow+4E++chwQEu3zT7SBDvY3L7MSpVpjsgB0jyZ42jCyyLVxk1gWUpA25etKqwga z8tZ5aR8zXZKhmDf8KNs0oAIhiNgOo0h234IvGCwNtrXe1ArdbhaOyKd+Yds0H5053my 2/CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680524758; 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=2uLzKleAtwS70FCPUxJe9wc6ztcLdIj8Gn2KoEsegIY=; b=QQe/nfmrGFf1jaRi4uoFWK3o3porBY6OzISrXEtYgOmkxBwgJ2tL2+wGoR/gvFMrWd vCjP/1y+fXTdlyOIm7UEIKeAjRC4py6JncVQPJmUgdoePXf0bDuEDIAFG93HjMMPuAFE 3lj6Jhjkaj/muxGe8AFWEGajYbewwdd7zmQZNkKV5vrnjxFAqYpLP4mkUx4i4Kn4/UZV hDABfVOjzsKOhh3TJGjBDIX/7pTqzk71gieMp78krNvUIbjOKhG7SAzRof5eNjwROlrX Qib5QvZP2NfSJDDvDOSlvvT0N1I4YTDghj4+eHI4n2x83lHY0hYIAI04DyTn8uVkDcBt CFaw== X-Gm-Message-State: AAQBX9fBrkmWrEiwv3Zv0/S/3zHltDXZ9rl6AZUH5LaGqN7RE4uL6OOo B6eJVWCCU+7cdfPoC0YK6DHpE0RB+aQi4bhQMH110OKQEfwLCwCXd1iVP5gu3eDPR3dyVjyTVzK ZQnOLPVWwsYJ+L/hjOTMwDAaPUiCEZt9GKcCbgsZuv52/tjSpjZUiLp6vR6sggRLC84OI7lh3zq sIQdnqhfI0MsspbEHWL1E2sMySYx4T5UZyK/ZI X-Google-Smtp-Source: AKy350Yj0syodTE8YcsgS0b40A8qiI58nIwFfkBEdt0RlKbRpb8I7z3UWUCWiAXytl9tXvVmNF+3tw== X-Received: by 2002:a17:907:7787:b0:939:90ee:e086 with SMTP id ky7-20020a170907778700b0093990eee086mr35270190ejc.28.1680524758606; Mon, 03 Apr 2023 05:25:58 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-228-162.bb.vodafone.cz. [86.49.228.162]) by smtp.gmail.com with ESMTPSA id q15-20020a17090676cf00b00947c0cecceasm3912221ejn.206.2023.04.03.05.25.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 03 Apr 2023 05:25:58 -0700 (PDT) Message-ID: Date: Mon, 3 Apr 2023 14:25:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: hio.c does visibilitymap_pin()/IO while holding buffer lock Content-Language: en-US To: Andres Freund , Tom Lane Cc: pgsql-hackers@postgresql.org, Tomas Vondra , Anastasia Lubennikova , Pavan Deolasee , Jeff Janes References: <20230325025740.wzvchp2kromw4zqz@awork3.anarazel.de> <0c11032a-d91b-8875-ab7b-4554776390c5@enterprisedb.com> <20230325163903.eu67kqcqo4llhc4u@awork3.anarazel.de> <2602455.1679763437@sss.pgh.pa.us> <20230325181707.at3kwsh7uvkhfype@awork3.anarazel.de> <20230329012102.zpviu2e7kyfrovxn@awork3.anarazel.de> <20230329021721.l3rujmv3jjmktt5i@awork3.anarazel.de> <20230402224024.aealekgu2df4cnhs@awork3.anarazel.de> From: Tomas Vondra In-Reply-To: <20230402224024.aealekgu2df4cnhs@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/3/23 00:40, Andres Freund wrote: > Hi, > > On 2023-03-28 19:17:21 -0700, Andres Freund wrote: >> On 2023-03-28 18:21:02 -0700, Andres Freund wrote: >>> Here's a draft patch. >> >> Attached is v2, with a stupid bug fixed and a bit of comment / pgindent >> polish. > > I'd welcome some review (Tomas?), but otherwise I'm planning to push ahead > with this. > I guess the 0001 part was already pushed, so I should be looking only at 0002, correct? I think 0002 makes RelationGetBufferForTuple() harder to understand. I'm not saying it's incorrect, but I find it hard to reason about the new combinations of conditions :-( I mean, it only had this condition: if (otherBuffer != InvalidBuffer) { ... } but now it have if (unlockedTargetBuffer) { ... } else if (otherBuffer != InvalidBuffer) { ... } if (unlockedTargetBuffer || otherBuffer != InvalidBuffer) { ... } Not sure how to improve that :-/ but not exactly trivial to figure out what's going to happen. Maybe this * If we unlocked the target buffer above, it's unlikely, but possible, * that another backend used space on this page. might say what we're going to do in this case. I mean - I understand some backend may use space in unlocked page, but what does that mean for this code? What is it going to do? (The same comment talks about the next condition in much more detail, for example.) Also, isn't it a bit strange the free space check now happens outside any if condition? It used to happen in the if (otherBuffer != InvalidBuffer) { ... } block, but now it happens outside. > I'm still debating with myself whether this commit (or a prerequisite commit) > should move logic dealing with the buffer ordering into > GetVisibilityMapPins(), so we don't need two blocks like this: > > > if (otherBuffer == InvalidBuffer || targetBlock <= otherBlock) > GetVisibilityMapPins(relation, buffer, otherBuffer, > targetBlock, otherBlock, vmbuffer, > vmbuffer_other); > else > GetVisibilityMapPins(relation, otherBuffer, buffer, > otherBlock, targetBlock, vmbuffer_other, > vmbuffer); > ... > > if (otherBuffer != InvalidBuffer) > { > if (GetVisibilityMapPins(relation, otherBuffer, buffer, > otherBlock, targetBlock, vmbuffer_other, > vmbuffer)) > unlockedTargetBuffer = true; > } > else > { > if (GetVisibilityMapPins(relation, buffer, InvalidBuffer, > targetBlock, InvalidBlockNumber, > vmbuffer, InvalidBuffer)) > unlockedTargetBuffer = true; > } > } > Yeah. I haven't tried, but I imagine it'd make RelationGetBufferForTuple a little bit. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company