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 1qz08i-00Ceh6-Og for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Nov 2023 19:47:32 +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 1qz08g-002vmo-Hu for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Nov 2023 19:47:30 +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 1qz08g-002vmg-4L for pgsql-hackers@lists.postgresql.org; Fri, 03 Nov 2023 19:47:30 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qz08d-003oVn-4U for pgsql-hackers@lists.postgresql.org; Fri, 03 Nov 2023 19:47:28 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-1e993765c1bso1422137fac.3 for ; Fri, 03 Nov 2023 12:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1699040846; x=1699645646; 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=bqpBtJa2oMAlyUaBuzYthJwQkDy4bW5wRpDwlB54Fq4=; b=YILo/UicWMjIEqgWSZ1wD8hAnwabsnu1CswcyGIj48JtMnkdMOqY+f0tJyqDZbziiW l43VJmSZIbkrXdcUPbK3E24l8FDmynyrLQUYnEJVQRDpS+Sd7RMpwVTLITnsP66XccwR uIfXr2KpVYD8xl3g5c9eIqrY2CcpFKAuxdfyxQfOgSzxEPMfSwCbGBS4AJddyrvj2opk h5NlzY+uj4hFGFipLqLWhllfJRKfmps2LCD9D0X4XXoH5YGRaQNyQ6GadxyL2ZmeEf2y f4VuR9WBrrLofNdQ4Lt40BBSlyl7WTCOkOC5hm/G4IaPHzzXKuMAw0OSHIMl4i69Ijn9 YFfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699040846; x=1699645646; 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=bqpBtJa2oMAlyUaBuzYthJwQkDy4bW5wRpDwlB54Fq4=; b=l8vmShVsA52VcCuMDg7av75s0rvAlCVORt/j8/LsIOMdm9E79SeaQLr2cFzGd+jSzF r2rPK8s8052yK0yKgvjGzprdE8FyN56J327l8J+7piYmDy4SSK/7YzRm2sVTMMzyxjd6 0JpVr18GTFQTBb+zjDPV2udBHCxWsvHh5evYuCHiwyDtCnO3ixiVzcJ/BO3kdSaykiSp WmQa9Cw4w6BhbBSJ3CftK8P6D2j0ir351YqSUGbKF7hDRuIU7coobddwfkgF+h1cHydT K0t4OOqVaPMFPYN6qK51u0SCEAiYuFFc/jx0ZdVoM7IFY/wWhQkwaMpyjz3aLyw3QC+O RInA== X-Gm-Message-State: AOJu0YzeL56RU28rvAI5irI8xAy6vYEuHAUr5VmFElSe/VVnoAezTCdP X7LuX7AG8BRQeZv5SbyOp/2nmA== X-Google-Smtp-Source: AGHT+IFElVUnMLLdNjFV2c+++KdSzotG9UsTbI9jdYlRdNHTug6NxWO6E2SX9u0isqrViFsHaaOpyQ== X-Received: by 2002:a05:6870:2887:b0:1ea:647f:a9b6 with SMTP id gy7-20020a056870288700b001ea647fa9b6mr29620826oab.44.1699040846437; Fri, 03 Nov 2023 12:47:26 -0700 (PDT) Received: from [172.18.10.34] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id k4-20020a63ba04000000b005ae776b8616sm1458524pgf.19.2023.11.03.12.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:47:25 -0700 (PDT) Message-ID: 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: Fri, 03 Nov 2023 12:47:24 -0700 In-Reply-To: References: <20221212.115717.1183698540772933396.horikyota.ntt@gmail.com> <628b07b79743e2614ab1724f516cbd41560d6551.camel@j-davis.com> <20230114203403.4zpg72fw2qb34awf@awork3.anarazel.de> <0d84c025e38673cb575dcf4987d050fe7b1e1a1f.camel@j-davis.com> <20231011224353.cl7c2s222dw3de4j@awork3.anarazel.de> <5c6e8e60c5c156a9f51ccf850f70829e45a985a1.camel@j-davis.com> <4132fe48f831ed6f73a9eb191af5fe475384969c.camel@j-davis.com> <2ef04861c0f77e7ae78b703770cc2bbbac3d85e6.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 Fri, 2023-11-03 at 20:23 +0530, Bharath Rupireddy wrote: > >=20 > OldestInitializedPage is introduced in v14-0001 patch. Please have a > look. I don't see why that's necessary if we move to the algorithm I suggested below that doesn't require a lock. > >=20 > Okay. Current patch doesn't support this [partial hit of newer pages] > case. OK, no need to support it until you see a reason. > >=20 > >=20 > > I think it needs something like: > >=20 > > =C2=A0 pg_atomic_write_u64(&XLogCtl->xlblocks[nextidx], > > InvalidXLogRecPtr); > > =C2=A0 pg_write_barrier(); > >=20 > > before the MemSet. >=20 > I think it works. First, xlblocks needs to be turned to an array of > 64-bit atomics and then the above change. Does anyone see a reason we shouldn't move to atomics here? >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pg_write_barrier(); >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *((volatile XLogRecPtr *) &XLo= gCtl->xlblocks[nextidx]) =3D > NewPageEndPtr; I am confused why the "volatile" is required on that line (not from your patch). I sent a separate message about that: https://www.postgresql.org/message-id/784f72ac09061fe5eaa5335cc347340c367c7= 3ac.camel@j-davis.com > I think the 3 things that helps read from WAL buffers without > WALBufMappingLock are: 1) couple of the read barriers in > XLogReadFromBuffers, 2) atomically initializing xlblocks[idx] to > InvalidXLogRecPtr plus a write barrier in AdvanceXLInsertBuffer(), 3) > the following sanity check to see if the read page is valid in > XLogReadFromBuffers(). If it sounds sensible, I'll work towards > coding > it up. Thoughts? I like it. I think it will ultimately be a fairly simple loop. And by moving to atomics, we won't need the delicate comment in GetXLogBuffer(). Regards, Jeff Davis