399 Star 1.4K Fork 1.5K

GVPopenGauss / openGauss-server

 / 详情

Improving incremental checkpoint logic to add free buffers to candidate list

待办的
任务
创建于  
2022-05-10 12:33

Is this a BUG REPORT or FEATURE REQUEST?:

Uncomment only one, leave it on its own line:

  • bug
  • feature

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);

评论 (2)

mysqlonarm 创建了任务

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.

zhangxubo 添加了
 
sig/storageengine
标签

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
5622128 opengauss bot 1581905080
C++
1
https://gitee.com/opengauss/openGauss-server.git
git@gitee.com:opengauss/openGauss-server.git
opengauss
openGauss-server
openGauss-server

搜索帮助