Skip to content

tidb: global memory arbitrator mechanism (#22882) - #24606

Open
ti-chi-bot wants to merge 12 commits into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-22882-to-release-8.5
Open

ti-chi-bot wants to merge 12 commits into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-22882-to-release-8.5

Conversation

@ti-chi-bot

@ti-chi-bot ti-chi-bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #22882

This PR is translated from: pingcap/docs-cn#20955

First-time contributors' checklist

What is changed, added or deleted? (Required)

Add documentation for the TiDB global memory arbitrator mode, including:

  • Add a Memory arbitrator mode section to configure-memory-usage.md, describing the working principles, configuration methods, monitoring metrics, and best practices for the standard and priority modes.
  • Add descriptions for the following system variables to system-variables.md:
    • tidb_mem_arbitrator_mode: sets the global memory management mode for a TiDB instance.
    • tidb_mem_arbitrator_query_reserved: sets the amount of memory reserved in advance for a SQL statement before execution.
    • tidb_mem_arbitrator_soft_limit: sets the upper limit of memory allocation for a TiDB instance.
    • tidb_mem_arbitrator_wait_averse: controls the behavior of SQL statements when waiting for memory resources, including the meanings of the values 0 (default, disabled), 1, and nolimit.

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions (in Chinese).

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Summary by CodeRabbit

  • Documentation
    • Added TiDB Cloud guidance for configuring and monitoring memory arbitration, including disable, standard, and priority modes and how arbitration handles memory pressure.
    • Documented four experimental settings available in CLOUD.202609.1: tidb_mem_arbitrator_mode, tidb_mem_arbitrator_query_reserved, tidb_mem_arbitrator_soft_limit, and tidb_mem_arbitrator_wait_averse.
    • Explained priority-based scheduling, session memory reservations, allocation limits, wait behavior, and the nolimit option.
    • Clarified that memory arbitration and alarm guidance applies to TiDB.

@ti-chi-bot ti-chi-bot added lgtm needs-1-more-lgtm Indicates a PR needs 1 more LGTM. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. type/compatibility-or-feature-change This PR involves compatibility changes or feature behavior changes. v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3. labels Nov 2, 2026
@ti-chi-bot ti-chi-bot mentioned this pull request Nov 2, 2026
2 of 14 tasks
@ti-chi-bot

ti-chi-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign oreoxmt for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The documentation adds TiDB Cloud memory arbitrator guidance and four system-variable entries. It describes arbitration modes, subscription scheduling, quota and termination behavior, monitoring, and operational guidance. It also wraps existing alarm content in TiDB-only tags and removes the obsolete Others heading.

Changes: Memory arbitrator documentation

Layer / File(s) Summary
Mode and configuration controls
configure-memory-usage.md, system-variables.md
Documents the disable, standard, and priority modes and adds four system-variable entries covering mode, reserved query memory, soft limits, and wait-averse behavior. Removes the obsolete Others heading.
Quota and scheduling behavior
configure-memory-usage.md
Describes quota categories, subscription scheduling, SQL termination, memory-risk handling, and arbitrator limits.
Monitoring and operational guidance
configure-memory-usage.md
Adds Grafana metrics, memory-wait fields in query views, and operational guidance. Wraps the excessive-memory alarm section in TiDB-only content and removes trailing whitespace from the disk-spill description.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: qiancai

Merge Risk: Moderate · previous review 67890

The memory-arbitrator documentation can mislead configuration, retry behavior, and navigation. Correct these issues before merging.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the main change, adding documentation for the TiDB global memory arbitrator. It is specific and concise, and it matches the changeset, which adds a memory arbitrator section and four s…
Description check Passed The description follows the repository template. It fills in the changes section with the new configure-memory-usage.md section and the four system variables. It marks the master version and includes …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change, adding documentation for the TiDB global memory arbitrator. It is specific and concise, and it matches the changeset, which adds a memory arbitrator section and four system variables. The trailing reference (#22882) is harmless.

Full details: Description check

Explanation

The description follows the repository template. It fills in the changes section with the new configure-memory-usage.md section and the four system variables. It marks the master version and includes related references. The First-time contributors' checklist is ticked. The AI agent involvement and the affected-version checkboxes are handled as expected. The description lists the changes but has no explicit statement about why they are needed beyond the cherry-pick context, which is minor.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (2 skipped: 2 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between dd7bfd0 and 2d85d2a.

Files selected for processing: 2
  • configure-memory-usage.md
  • system-variables.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread configure-memory-usage.md Resolved
Comment thread configure-memory-usage.md

- When the memory usage of a TiDB instance exceeds the limit, TiDB might randomly terminate running SQL statements.
- Memory resources follow a "use first and report later" mechanism, and memory usage is isolated across different SQL statements. As a result, TiDB cannot centrally schedule or control memory resources at the instance level.
- Under high memory pressure, the overhead of Go garbage collection (GC) increases significantly, and in severe cases might cause out of memory (OOM) issues.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial · Maintainability & Code Quality · Quick win

Fix the new compound modifiers.

LanguageTool flags out of memory and first in, first out in the added prose. Use the hyphenated forms.

Suggested replacement
-- Under high memory pressure, the overhead of Go garbage collection (GC) increases significantly, and in severe cases might cause out of memory (OOM) issues.
+- Under high memory pressure, the overhead of Go garbage collection (GC) increases significantly, and in severe cases might cause out-of-memory (OOM) issues.
 
-In `standard` mode, during SQL execution, SQL dynamically subscribes to memory resources from the arbitrator and blocks to wait when resources are insufficient. The arbitrator processes subscription requests on a first in, first out (FIFO) basis.
+In `standard` mode, during SQL execution, SQL dynamically subscribes to memory resources from the arbitrator and blocks to wait when resources are insufficient. The arbitrator processes subscription requests on a first-in, first-out (FIFO) basis.

Also applies to: 277-277

Tools
LanguageTool

[grammar] ~234-~234: Use a hyphen to join words.
Context: ...tly, and in severe cases might cause out of memory (OOM) issues. Starting from v9.0...

(QB_NEW_EN_HYPHEN)

Sources: Path instructions, Linters/SAST tools

Comment thread configure-memory-usage.md Resolved
Comment thread configure-memory-usage.md Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Update the four system-variable links in… · configure-memory-usage.md:242

configure-memory-usage.md:242
Minor · Functional Correctness · Quick win

Update the four system-variable links in configure-memory-usage.md.

The -new-in-v900 anchors do not match the headings in system-variables.md. Those headings are marked New in CLOUD.202609.1, and the repository has no alias for that marker. Lines 242, 292, 301, 305, and 307 use the old anchor, so each link can miss its entry. Replace these anchors with the anchor generated for the CLOUD.202609.1 heading, or add explicit {#tidb_mem_arbitrator_...} IDs to the four headings. The explicit-ID form matches the existing tidb_stmt_summary_* headings. Use one approach for all five links.

Source: Path instructions

Duplicate comments: 3
configure-memory-usage.md: 3

234-234: Minor · Maintainability & Code Quality · Quick win

Hyphenate the compound modifiers in both added sentences.

Apply these exact replacements.

- Under high memory pressure, the overhead of Go garbage collection (GC) increases significantly, and in severe cases might cause out-of-memory (OOM) issues.
In `standard` mode, during SQL execution, SQL dynamically subscribes to memory resources from the arbitrator and blocks to wait when resources are insufficient. The arbitrator processes subscription requests on a first-in, first-out (FIFO) basis.

Also applies to: 277-277

Sources: Path instructions, Linters/SAST tools


273-273: Major · Functional Correctness · Quick win

Calculate out-of-control from the effective soft limit.

tidb_mem_arbitrator_soft_limit accepts 0, a ratio, or a byte value. Subtracting the raw setting is incorrect for the default and ratio forms. This also conflicts with the definitions in system-variables.md.

Suggested replacement
`out-of-control` is a risk metric that requires special attention. It is dynamically calculated by the arbitrator, with a minimum value equal to the difference between `tidb_server_memory_limit` and the effective byte value of `tidb_mem_arbitrator_soft_limit`. For `0`, the effective value is `95%` of `tidb_server_memory_limit`; for a ratio such as `0.8`, the effective value is `tidb_server_memory_limit * 0.8`; for a byte value, the effective value is that byte value. The arbitrator quantifies this type of risky memory quota as accurately as possible and reserves space for it during memory allocation, thereby reducing the risk of OOM in the TiDB instance.

Source: Path instructions


356-356: Minor · Functional Correctness · Quick win

Specify the wait-averse value.

The default value 0 disables this behavior. The current instruction does not enable the fast-fail path.

    - If you want SQL to fail quickly when memory resources are insufficient and then be retried on another node, set `tidb_mem_arbitrator_wait_averse` to `1`.

Source: Path instructions


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 2d85d2a and f9e2ec8.

Files selected for processing: 2
  • configure-memory-usage.md
  • system-variables.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Remove the link to the TiDB-only alarm section. · configure-memory-usage.md:254

configure-memory-usage.md:254
Minor · Functional Correctness · Quick win

Remove the link to the TiDB-only alarm section.

The Cloud-only content links to a heading that is excluded from the TiDB Cloud page. Remove the link and keep the text as plain text.

Suggested fix
-    - The overall memory usage of the TiDB instance is expected not to exceed the limit of [`tidb_server_memory_limit`](/system-variables.md#tidb_server_memory_limit-new-in-v640), and the [alarm for high memory usage](#trigger-the-alarm-of-excessive-memory-usage) no longer takes effect.
+    - The overall memory usage of the TiDB instance is expected not to exceed the limit of [`tidb_server_memory_limit`](/system-variables.md#tidb_server_memory_limit-new-in-v640), and the alarm for high memory usage no longer takes effect.

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f9e2ec8 and 6789088.

Files selected for processing: 2
  • configure-memory-usage.md
  • system-variables.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread configure-memory-usage.md
- Memory resources are used with a subscribe-before-allocation mechanism and are uniformly scheduled by the memory arbitrator in each TiDB instance.
- The overall memory usage of the TiDB instance is expected not to exceed the limit of [`tidb_server_memory_limit`](/system-variables.md#tidb_server_memory_limit-new-in-v640), and the [alarm for high memory usage](#trigger-the-alarm-of-excessive-memory-usage) no longer takes effect.
- The behavior of the following system variables remains effective:
- [`tidb_mem_oom_action`](/system-variables.md#tidb_mem_oom_action-new-in-v610)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tidb_mem_oom_action is read-only for TiDB X

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default behavior of tidb_mem_oom_action still takes effect.

Comment thread configure-memory-usage.md
- `CompilePlan`: compiling the execution plan

Memory arbitrator mode pools the arbitrable memory resources in each TiDB instance. The memory resources corresponding to `tidb_server_memory_limit` are divided into the following four categories, which can be viewed through the `Mem Quota Stats` monitoring metric:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is the tidb_server_memory_limit metric available for TiDB X?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tidb_server_memory_limit is read only for essential mode.

Comment thread configure-memory-usage.md
- memory used by the Go runtime
- other untracked memory usage

`out-of-control` is a risk metric that requires special attention. It is dynamically calculated by the arbitrator, with a minimum value of `tidb_server_memory_limit - tidb_mem_arbitrator_soft_limit`. The arbitrator quantifies this type of risky memory quota as accurately as possible and reserves space for it during memory allocation, thereby reducing the risk of OOM in the TiDB instance.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is this out-of-control metric available for TiDB X?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is

Comment thread configure-memory-usage.md

TiDB internally caches the historical maximum memory usage of some SQL statements and pre-subscribes sufficient memory quota before the next execution of the SQL. If it is known that a SQL statement has a large amount of uncontrolled memory usage, you can use the [`tidb_mem_arbitrator_query_reserved`](/system-variables.md#tidb_mem_arbitrator_query_reserved-new-in-v900) system variable to specify the quota subscribed by the SQL. The larger the value, the safer the global memory, but the lower the memory resource utilization. Pre-subscribing sufficient or excess quota can effectively ensure the isolation of memory resources for SQL.

### Monitoring and observability metrics

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Are these metrics available for TiDB X?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I've add relevant grafana to repo tidbcloud/clinic-grafana.

Comment thread configure-memory-usage.md Outdated
- `AVG_MEM_ARBITRATION`: the average time that SQL waits for memory resources
- `MAX_MEM_ARBITRATION`: the maximum time that SQL waits for memory resources

### Best practices

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the best practices applicable to TiDB X?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the entire Best practices section from this Cloud documentation backport. The 95% tuning recommendation requires a writable tidb_server_memory_limit, which is read-only on Starter and Essential. The other recommendations assume customers can configure resource groups, change individual TiDB server configurations, or route retries to a specific node. We can add plan-specific guidance once those options and their customer-facing configuration paths are confirmed.

TiDB X SQL feature limits

@solotzg solotzg self-assigned this Nov 30, 2026
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
@ti-chi-bot

ti-chi-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

@solotzg: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@solotzg solotzg mentioned this pull request Dec 2, 2026
1 of 15 tasks

@solotzg solotzg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Best practices section has been removed as requested. I found several remaining accuracy and Cloud-rendering issues in the updated content.

@solotzg solotzg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Best practices section has been removed as requested. I found several remaining accuracy and Cloud-rendering issues in the updated content.

Comment thread configure-memory-usage.md Resolved
Comment thread configure-memory-usage.md Resolved
Comment thread configure-memory-usage.md Resolved
Comment thread system-variables.md Resolved
Comment thread system-variables.md Resolved
@ti-chi-bot

ti-chi-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

@solotzg: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Updated the link for the alarm on high memory usage to point to the correct section in the same document.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm needs-1-more-lgtm Indicates a PR needs 1 more LGTM. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. type/compatibility-or-feature-change This PR involves compatibility changes or feature behavior changes. v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants