前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Postgresql源码(11)StrategyGetBuffer新buffer分配流程图

Postgresql源码(11)StrategyGetBuffer新buffer分配流程图

作者头像
mingjie
发布2022-05-12 08:21:03
2110
发布2022-05-12 08:21:03
举报

bgwriter配合唤醒

src/backend/storage/buffer/README

代码语言:javascript
复制
Background Writer's Processing
------------------------------

The background writer is designed to write out pages that are likely to be
recycled soon, thereby offloading the writing work from active backends.
To do this, it scans forward circularly from the current position of
nextVictimBuffer (which it does not change!), looking for buffers that are
dirty and not pinned nor marked with a positive usage count.  It pins,
writes, and releases any such buffer.
  • bgwriter旨在write out可能很快被回收的页面,分担backend的工作。
  • bgwriter从 nextVictimBuffer 的当前位置(不会改变!)循环向前扫描,寻找脏的、未pin或usage count>0的缓冲区。
  • bgwriter pin、write out和release缓冲区。
代码语言:javascript
复制
If we can assume that reading nextVictimBuffer is an atomic action, then
the writer doesn't even need to take buffer_strategy_lock in order to look
for buffers to write; it needs only to spinlock each buffer header for long
enough to check the dirtybit.  Even without that assumption, the writer
only needs to take the lock long enough to read the variable value, not
while scanning the buffers.  (This is a very substantial improvement in
the contention cost of the writer compared to PG 8.0.)
  • 如果可以假设读取 nextVictimBuffer 是一个原子操作,那bgwriter不需要加buffer_strategy_lock 来寻找要写入的缓冲区
  • bgwriter只需要spin锁定每个缓冲区hdr足够长的时间来检查脏位
代码语言:javascript
复制
The background writer takes shared content lock on a buffer while writing it
out (and anyone else who flushes buffer contents to disk must do so too).
This ensures that the page image transferred to disk is reasonably consistent.
We might miss a hint-bit update or two but that isn't a problem, for the same
reasons mentioned under buffer access rules.

As of 8.4, background writer starts during recovery mode when there is
some form of potentially extended recovery to perform. It performs an
identical service to normal processing, except that checkpoints it
writes are technically restartpoints.
  • bgwriter在写出缓冲区加锁:shared content lock(其他任何将缓冲区内容刷盘也必须这样做)确保传输到磁盘的页面一致。

buffer id 分配流程

图
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-11-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • bgwriter配合唤醒
  • buffer id 分配流程
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档