pgsql: Prefetch data referenced by the WAL, take II.
Thomas Munro <tmunro@postgresql.org>
From: Thomas Munro <tmunro@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Date: 2022-04-07T07:44:20Z
Lists: pgsql-hackers
Prefetch data referenced by the WAL, take II. Introduce a new GUC recovery_prefetch. When enabled, look ahead in the WAL and try to initiate asynchronous reading of referenced data blocks that are not yet cached in our buffer pool. For now, this is done with posix_fadvise(), which has several caveats. Since not all OSes have that system call, "try" is provided so that it can be enabled where available. Better mechanisms for asynchronous I/O are possible in later work. Set to "try" for now for test coverage. Default setting to be finalized before release. The GUC wal_decode_buffer_size limits the distance we can look ahead in bytes of decoded data. The existing GUC maintenance_io_concurrency is used to limit the number of concurrent I/Os allowed, based on pessimistic heuristics used to infer that I/Os have begun and completed. We'll also not look more than maintenance_io_concurrency * 4 block references ahead. Reviewed-by: Julien Rouhaud <rjuju123@gmail.com> Reviewed-by: Tomas Vondra <tomas.vondra@2ndquadrant.com> Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> (earlier version) Reviewed-by: Andres Freund <andres@anarazel.de> (earlier version) Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> (earlier version) Tested-by: Tomas Vondra <tomas.vondra@2ndquadrant.com> (earlier version) Tested-by: Jakub Wartak <Jakub.Wartak@tomtom.com> (earlier version) Tested-by: Dmitry Dolgov <9erthalion6@gmail.com> (earlier version) Tested-by: Sait Talha Nisanci <Sait.Nisanci@microsoft.com> (earlier version) Discussion: https://postgr.es/m/CA%2BhUKGJ4VJN8ttxScUFM8dOKX0BrBiboo5uz1cq%3DAovOddfHpA%40mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/5dc0418fab281d017a61a5756240467af982bdfd Modified Files -------------- doc/src/sgml/config.sgml | 64 ++ doc/src/sgml/monitoring.sgml | 86 +- doc/src/sgml/wal.sgml | 12 + src/backend/access/transam/Makefile | 1 + src/backend/access/transam/xlog.c | 2 + src/backend/access/transam/xlogprefetcher.c | 1082 +++++++++++++++++++++++++ src/backend/access/transam/xlogreader.c | 27 +- src/backend/access/transam/xlogrecovery.c | 179 ++-- src/backend/access/transam/xlogutils.c | 27 +- src/backend/catalog/system_views.sql | 14 + src/backend/storage/buffer/bufmgr.c | 4 + src/backend/storage/freespace/freespace.c | 3 +- src/backend/storage/ipc/ipci.c | 3 + src/backend/storage/smgr/md.c | 6 +- src/backend/utils/adt/pgstatfuncs.c | 5 +- src/backend/utils/misc/guc.c | 55 +- src/backend/utils/misc/postgresql.conf.sample | 6 + src/include/access/xlog.h | 1 + src/include/access/xlogprefetcher.h | 53 ++ src/include/access/xlogreader.h | 8 + src/include/access/xlogutils.h | 3 +- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_proc.dat | 7 + src/include/utils/guc.h | 4 + src/include/utils/guc_tables.h | 1 + src/test/regress/expected/rules.out | 11 + src/tools/pgindent/typedefs.list | 6 + 27 files changed, 1595 insertions(+), 77 deletions(-)
Commits
-
Improve wal_decode_buffer_size description some more
- 8e7a0b4a3674 16.0 landed
- 892cac912499 15.0 landed
-
Include some missing headers.
- 5b186308fbc4 15.0 landed
-
Prefetch data referenced by the WAL, take II.
- 5dc0418fab28 15.0 cited