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 1rLZMg-008ipW-OG for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 01:51: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 1rLZLg-00Gp0K-5a for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 01:50:12 +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 1rLZLf-00Gov4-Ri for pgsql-hackers@lists.postgresql.org; Fri, 05 Jan 2024 01:50:11 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rLZLc-00Dmb3-KM for pgsql-hackers@lists.postgresql.org; Fri, 05 Jan 2024 01:50:10 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso790164a12.3 for ; Thu, 04 Jan 2024 17:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1704419407; x=1705024207; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=/OQzxbQEjVRxa3WZxUMVw7coQ/IKSkOE1FNWvSLS45Y=; b=JYti4Mzz707Zhfx1Gl4JPDA3/VnVhX22k9/KLzR7mHw2YiEJ5s2H6/60O9O8+X/wLM KGWxDQ61qQmRbEbTXrf1fTGLYTPpbOu2LL+/nGjjUAliTqW9VVSUGCU0k/guF3tnzsae znUmTuA3lTrp7VJ9o/pFbhLE6DOvPCV4nk5pDS6LnrLtuz2W0RKvQOqQSBmbOB8H/GLn fDrk/zbyFqrnbajISYW9Oh4Sqy6pGRvB33cima92xLtjWHR3Uu5udyx6dlCSkTzOw1s7 k88WOmwUGY0rytt49ALDwuoMOcWm2xyHMP7U4wsm+IfI2ywkm376j8gI2lh0W9Fhm20F dnBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704419407; x=1705024207; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/OQzxbQEjVRxa3WZxUMVw7coQ/IKSkOE1FNWvSLS45Y=; b=kgLB8ekvFmPejwP1VNgka5+/VScOY7V0ll+aoicNQ6hK/5Uz0GgnUB+nmOO+8v9TpV Pi9zOaUmjVsOroT/lQs3H6k69/ix3Q+gZ+TyBtEeQtA7cFdT3r8Pd1usEEkxVXzjNctC H7yJe3Fzw8XdxzeJvtpDP+CDWRuofqeMH03ztf1aVqy19mP/9bPyCpXXTyGLKrQx+Xuc x8W5fHHal4xgjZ/XKWpyx4/SgRrS4sC15CCqi0n40IlfAmDGJgtUOjg380VAIvks66ru SiruOS4Gvb6ZfLcu/7Nh34YafIFNaaicZ0gzbIsnS7bRQU2jPhL4DddsqDGE/PeyngGG YjHQ== X-Gm-Message-State: AOJu0YwoI3PdNwnXMB2R/1gwQBDEq7NSk4mfyHVeIFpDyzcXyhPSixet ISb3BBy0h8iLR+f2ra1fMiCSDNOZeeCG X-Google-Smtp-Source: AGHT+IEsTKtNNoxPdm0WGLLyIio3chICs0QNKKo1CddgBA4D+9Tu9/IpCEJdZqe/htP+FSbKdC65Jg== X-Received: by 2002:a05:6a20:b399:b0:196:d0bf:bb53 with SMTP id eg25-20020a056a20b39900b00196d0bfbb53mr1200563pzb.67.1704419407154; Thu, 04 Jan 2024 17:50:07 -0800 (PST) Received: from [172.18.10.36] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id l6-20020a170902d34600b001d4ac8ac969sm249168plk.275.2024.01.04.17.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 17:50:06 -0800 (PST) Message-ID: <73df9831747b01ced949102610dc44ca6026ee1c.camel@j-davis.com> Subject: Re: Improve WALRead() to suck data directly from WAL buffers when possible From: Jeff Davis To: Bharath Rupireddy Cc: Andres Freund , Dilip Kumar , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org, Nathan Bossart , Masahiko Sawada Date: Thu, 04 Jan 2024 17:50:05 -0800 In-Reply-To: References: <0d84c025e38673cb575dcf4987d050fe7b1e1a1f.camel@j-davis.com> <20231011224353.cl7c2s222dw3de4j@awork3.anarazel.de> <5c6e8e60c5c156a9f51ccf850f70829e45a985a1.camel@j-davis.com> <4132fe48f831ed6f73a9eb191af5fe475384969c.camel@j-davis.com> <20231104004348.zhxzk2p266i3r2z2@awork3.anarazel.de> <20231109205836.zjoawdrn4q77yemv@awork3.anarazel.de> <3750ff9c2a5556808827e7fc5bcc0bd16e9facf4.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2023-12-20 at 15:36 +0530, Bharath Rupireddy wrote: > Thanks. Attaching remaining patches as v18 patch-set after commits > c3a8e2a7cb16 and 766571be1659. Comments: I still think the right thing for this patch is to call XLogReadFromBuffers() directly from the callers who need it, and not change WALRead(). I am open to changing this later, but for now that makes sense to me so that we can clearly identify which callers benefit and why. I have brought this up a few times before[1][2], so there must be some reason that I don't understand -- can you explain it? The XLogReadFromBuffersResult is never used. I can see how it might be useful for testing or asserts, but it's not used even in the test module. I don't think we should clutter the API with that kind of thing -- let's just return the nread. I also do not like the terminology "partial hit" to be used in this way. Perhaps "short read" or something about hitting the end of readable WAL would be better? I like how the callers of WALRead() are being more precise about the bytes they are requesting. You've added several spinlock acquisitions to the loop. Two explicitly, and one implicitly in WaitXLogInsertionsToFinish(). These may allow you to read slightly further, but introduce performance risk. Was this discussed? The callers are not checking for XLREADBUGS_UNINITIALIZED_WAL, so it seems like there's a risk of getting partially-written data? And it's not clear to me the check of the wal page headers is the right one anyway. It seems like all of this would be simpler if you checked first how far you can safely read data, and then just loop and read that far. I'm not sure that it's worth it to try to mix the validity checks with the reading of the data. Regards, Jeff Davis [1]=C2=A0https://www.postgresql.org/message-id/4132fe48f831ed6f73a9eb191af5= fe475384969c.camel%40j-davis.com [2] https://www.postgresql.org/message-id/2ef04861c0f77e7ae78b703770cc2bbbac3d8= 5e6.camel@j-davis.com