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 1uzt3L-0089ON-3o for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Sep 2025 08:34:43 +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 1uzt2K-00Bx9w-2D for pgsql-hackers@arkaria.postgresql.org; Sat, 20 Sep 2025 08:33:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uzt2J-00Bx9o-MO for pgsql-hackers@lists.postgresql.org; Sat, 20 Sep 2025 08:33:39 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uzt2F-001qDQ-29 for pgsql-hackers@lists.postgresql.org; Sat, 20 Sep 2025 08:33:39 +0000 Received: by mail-pg1-x52c.google.com with SMTP id 41be03b00d2f7-b552590d8cdso1162621a12.0 for ; Sat, 20 Sep 2025 01:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758357215; x=1758962015; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MTb4CnehG2JJWonijp7mVbepmXJbULDPT6361R5PhGo=; b=dwc6eCr3BZ2ZEV8eLJ7gj14DpBY/8FvQstdyntuee11i96RUNz9pBgNNGi52aTjNkD IComdPFMr+AjYzn/+12IVc6mHB1KkDcEgGaI6NSTe2T2KAQW4vokQw4/Th6Fq+mnKe4Y GHwL0vlL3XTQaCgQCEqqXahczKP7RvCuX1xZDCRcEgUncsSD0VuRM5yZNvrhWL8+tthO /8lPtjuk7/d91x1MjFHOvMhd67+rmYi4j2krvj/bW+Wi8KhgDLdvlnAtEv6kwDNrksAn +d3KBaDAgmwsQ3W/ICrczTQ5vLd37MegzrVtS6MGvTXCvk+k0/wT1PzRRzg5cQnbwOjV Qa6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758357215; x=1758962015; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MTb4CnehG2JJWonijp7mVbepmXJbULDPT6361R5PhGo=; b=E7zrG/Rs3eeAM277jzpOuyO6gnMwpuZdrcIaLCRJRPV9KybfW21KGC4SQF4D1d7pK0 d0e5UGPTh9S2ks4ANO07AJYYgZF29zbDWcWKZwvDwDextm++C5QPlkBGTZ5D276SLxUH CaO5AGloAgbSeeefnGUygMg/fXXw9bChmNn/V578MIx3Txceh3gdDsB04VMlfOXAo2Xz zRs2QGBU3mJAUPRFCYPsNtAGpi9cBdKE7IuZZBgYxZkrl5X+6I4J3rlltwjgk8dZvMFC iNAdzbD5GSHACshwrfFDxMlkACDIwi5k+q4j/UGBeoEP5AZkF4vsyWicLYtPDVTqSOmZ dG/g== X-Gm-Message-State: AOJu0YwASpGJZ8DqYw9BNfwuxZIaXSdD7Mevh235vEgyDKRqgqyNBtKh 9xO3Jc3C/Qx5zOu+lKNyh/E/VC2nTL32V1WDH6pVivBpN8Gz3RRDPX7c X-Gm-Gg: ASbGncuhh0C0V7Qjr8R4Co3Axd5yXNGuZ525amnVYqXxcBNorUSn4fl/5g1DAuH83Bi IE8WsUKwcS4i+fobOB3l99l2WsnPahKKo2mnaSJVpCOIWMhV1PRTCIJ5/w/1yRn+xT60Of37i5K lkEbZ4CurW4Z/5diLqbEsJyY6EsIvaRKEO+ynlDUIcQo2XmZy6UczPmblmXSZdKuQt3cDqW90yY W/HLoOPH32aqdWM4yStHw4CRnFY8vGD03C6uU1jKA1bt7hHizcl4Qf9wYuvtQkhmW1x9JpgYr/f qzQNpMEWdNwL3shsyuSXJaIUVJUWx3vPqOgtpJa44cL+2wALyDp1wNGQvKmkGiId7wQal4/rznH a4CLJb2n+QE1qhG06WOml8QU8X+B/dknP3+gANh4trf4T X-Google-Smtp-Source: AGHT+IEDsxc8fuvNSMulKhrBUsoZaYb0t6G2DoEiBH+C9AfyqCqFnrD16eJDbJYJquvQceA3ZgXRBg== X-Received: by 2002:a17:903:11d2:b0:267:d2f9:2327 with SMTP id d9443c01a7336-269ba46b4efmr80030005ad.27.1758357214894; Sat, 20 Sep 2025 01:33:34 -0700 (PDT) Received: from smtpclient.apple ([106.11.200.207]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2698018a6b3sm76310565ad.59.2025.09.20.01.33.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Sep 2025 01:33:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Use WALReadFromBuffers in more places From: Jingtang Zhang In-Reply-To: Date: Sat, 20 Sep 2025 16:33:20 +0800 Cc: pgsql-hackers@lists.postgresql.org, Nitin Jadhav Content-Transfer-Encoding: quoted-printable Message-Id: <92F510DF-321D-4385-B1D8-71781B50777B@gmail.com> References: To: Bharath Rupireddy X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi~ > Thanks for looking at this. Yes, the WAL writers can zero out flushed > buffers before WALReadFromBuffers gets to them. However, > WALReadFromBuffers was intentionally designed as an opportunistic > optimization - it's a "try this first, quickly" approach before > falling back to reading from WAL files. The no-locks design ensures it > never gets in the way of backends generating WAL, which is critical > for overall system performance. Yes, it is actually an interesting thing, beyond current topic. Since we are using buffered I/O, even though we cannot read from WAL buffer = due to the opportunistic AdvanceXLInsertBuffer by WAL writer, later WALRead = may still find the page inside OS page cache, with high probability, because = the page has just been written out. So WALRead will be fast, too. But if we are moving forward to direct I/O some day in the future, the = cost of WALReadFromBuffers and WALRead might be obvious. Maybe the = opportunistic WAL buffer initialization could keep a small ratio of old pages inside = WAL buffer so these pages can still be hit by WALReadFromBuffers. > I rebased and attached the v3 patch. The v3 patch LGTM. =E2=80=94 Regards, Jingtang Alibaba Cloud