Is this a BUG REPORT or FEATURE REQUEST?:
Uncomment only one, leave it on its own line:
- bug
What happened:
Problem:
In opengauss, each instance of bgwriter maintains a candidate list.
This list helps source the next free buffer when requested by the flow-through BufferAlloc.
A buffer is removed from the list when requested and added back to the list as part of the incremental checkpoint flow scan.
Incremental checkpoint will scan the buffers allotted to the said bgwriter instance (in batches) and all possible buffers that qualify, are added to the candidate list.
Scanning of N buffers also involves Locking these N buffer headers which of course involves a significant cost (though no/less contention is expected).
Also, scanning is done even though all the buffers are already in the candidate list.
At times, when very few buffers are removed from the candidate list the toll of adding these buffers back to the candidate list involves a full scan of all the buffers allotted to the respective bgwriter instance.
What you expected to happen:
Proposal:
Proposed patch tends to skip the scan if
- all buffers are already on the candidate list.
- 90% of the buffers are already on the candidate list
This effective means a scan is not triggered if some handful of the buffers needs to be added to the list there-by saving locking of the N buffers just to find out that these buffers are already on the list.
Effect is quite imminent with a read-only workload where-in the buffers are not dirtied and so immediately qualify to enter the candidate list (unless workload is using it).
How to reproduce it (as minimally and precisely as possible):
pgbench read-only workload
Anything else we need to know?:
Environment:
Version: opengauss v2.1.0
OS (e.g. from /etc/os-release):
NAME="openEuler"
VERSION="20.03 (LTS-SP2)"
ID="openEuler"
VERSION_ID="20.03"
PRETTY_NAME="openEuler 20.03 (LTS-SP2)"
ANSI_COLOR="0;31"
Kernel (e.g. uname -a
):
Linux openEuler169 4.19.90-2106.3.0.0095.oe1.aarch64 #1 SMP Wed Jun 23 14:51:58 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
Install tools:
Others:
diff --git a/src/gausskernel/process/postmaster/bgwriter.cpp b/src/gausskernel/process/postmaster/bgwriter.cpp
index 082b34fb..060baa67 100755
--- a/src/gausskernel/process/postmaster/bgwriter.cpp
+++ b/src/gausskernel/process/postmaster/bgwriter.cpp
@@ -1004,10 +1004,19 @@ static uint32 get_candidate_buf(bool *contain_hashbucket)
BufferDesc *buf_desc = NULL;
uint32 local_buf_state;
CkptSortItem* item = NULL;
- uint32 max_flush_num = get_bgwriter_flush_num();
int thread_id = t_thrd.bgwriter_cxt.thread_id;
- bool segment_bgwriter = IS_SEGMENT_BGWRITER(thread_id);
BgWriterProc *bgwriter = &g_instance.bgwriter_cxt.bgwriter_procs[thread_id];
+
+ /* a. all element are already added to candidate list, skip scaning
+ b. candidate list is big enough to handle burst traffic, skip scaning */
+ int64 curr_cand_list_size = get_thread_candidate_nums(thread_id);
+ int64 threshold = bgwriter->cand_list_size * 0.9;
+ if (curr_cand_list_size >= threshold) {
+ return need_flush_num;
+ }
+
+ uint32 max_flush_num = get_bgwriter_flush_num();
+ bool segment_bgwriter = IS_SEGMENT_BGWRITER(thread_id);
CkptSortItem *dirty_buf_list = bgwriter->dirty_buf_list;
int batch_scan_num = MIN(bgwriter->cand_list_size, MAX_SCAN_BATCH_NUM);
int start = MAX(bgwriter->buf_id_start, bgwriter->next_scan_loc);
Hey @mysqlonarm, Welcome to openGauss Community.
All of the projects in openGauss Community are maintained by @opengauss-bot.
That means the developers can comment below every pull request or issue to trigger Bot Commands.
Please follow instructions at Here to find the details.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
登录 后才可以发表评论