You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tidb: global memory arbitrator mechanism (#22882) - #24606
I've signed the Contributor License Agreement, which is required for the repository owners to accept my contribution.
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.
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.
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:
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.
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
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.
The memory-arbitrator documentation can mislead configuration, retry behavior, and navigation. Correct these issues before merging.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
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
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
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
- 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.
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...
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`.
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.
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.
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.
- 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:
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:
`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.
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
standardandprioritymodes.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 values0(default, disabled),1, andnolimit.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).
What is the related PR or file link(s)?
Do your changes match any of the following descriptions?
Summary by CodeRabbit
disable,standard, andprioritymodes and how arbitration handles memory pressure.CLOUD.202609.1:tidb_mem_arbitrator_mode,tidb_mem_arbitrator_query_reserved,tidb_mem_arbitrator_soft_limit, andtidb_mem_arbitrator_wait_averse.nolimitoption.