Rewrite background writer. bgwriter-rewrite
authorAndres Freund <andres@anarazel.de>
Fri, 19 Feb 2016 20:07:51 +0000 (12:07 -0800)
committerAndres Freund <andres@anarazel.de>
Tue, 11 Jun 2019 02:01:00 +0000 (19:01 -0700)
commit7c5df799aa12dc43f4d8bcef78120225cda990e0
tree58c24f441033017298ae014ea925060b5ef79197
parent53094143e3c1fc9a8090cce66e73e26d58c67b93
Rewrite background writer.

This currently consists out of two major parts:

1) Add more statistics, to be able to even evaluate the effects of
   bgwriter changes / problems. This should probably be split into a
   separate commit.

   It's remarkable how odd the set of current measurements is, and how
   many different mechanisms for transporting those values we
   currently have. The patch adds and replaces a few measurements, but
   doesn't yet do enough cleanup (have fewer transport mechanisms,
   split into different views).

2) A new bgwriter implementation (that can be turned on by setting the
   bgwriter_legacy GUC to false). There's a few major differences:

   a) bgwriter performs the clock sweep - that makes it a lot easier
      to actually find buffers worthwhile to clean. It's quite
      possible to get into situations where the old bgwriter can't do
      anything for a while because all buffers have a usagecount > 0.
   b) When a buffer is encountered by bgwriter, after performing clock
      sweep, is clean and has usage/pin count of 0 (i.e. it can be
      reclaimed), then we also push it onto the queue.
   c) It just has a ringbuffer of clean buffers, that backends can
      drain. Bgwriter pushes (without any locks) entries onto the
      queue, backends can pop them of.
   d) The pacing logic is a lot simpler. There's a ringbuffer that
      bgwriter tries to fill. There's a low watermark that causes
      backends to wake up bgwriter.
16 files changed:
src/backend/access/transam/xlog.c
src/backend/catalog/system_views.sql
src/backend/postmaster/bgwriter.c
src/backend/postmaster/checkpointer.c
src/backend/postmaster/pgstat.c
src/backend/storage/buffer/buf_init.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/freelist.c
src/backend/utils/adt/pgstatfuncs.c
src/backend/utils/misc/guc.c
src/include/catalog/pg_proc.dat
src/include/pgstat.h
src/include/postmaster/bgwriter.h
src/include/storage/buf_internals.h
src/include/storage/bufmgr.h
src/test/regress/expected/rules.out