Skip to content

memory: apply cgroup limit immediately - #11063

Open
okJiang wants to merge 1 commit into
tikv:masterfrom
okJiang:codex/issue-10719-cgroup-memory-cache
Open

memory: apply cgroup limit immediately#11063
okJiang wants to merge 1 commit into
tikv:masterfrom
okJiang:codex/issue-10719-cgroup-memory-cache

Conversation

@okJiang

@okJiang okJiang commented Jul 29, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: ref #10719

When PD is started by systemd under a cgroup, package initialization can cache the host physical memory before InitMemoryHook selects the cgroup memory hooks.

Because the total-memory cache remains valid for 60 seconds, RegionSyncer can size its history buffer using the host memory and retain an oversized limit for the process lifetime.

What is changed and how does it work?

When InitMemoryHook selects cgroup memory hooks, immediately replace the cached total memory with the detected cgroup limit and invalidate the cached memory usage.

Add a regression test that verifies stale physical-memory cache entries are replaced during the hook switch.

Check List

Tests

  • Unit test
  • Manual test

Manual test:

  • Verified PD startup with 2, 4, 8, 16, and 32 GiB cgroup limits.
  • Verified the corresponding RegionSync history capacities were 10k, 10k, 20k, 40k, and 80k.

Release note

Fix PD memory-aware sizing to use the cgroup memory limit immediately at startup.

Summary by CodeRabbit

  • Bug Fixes

    • Improved memory reporting in cgroup environments by using the detected cgroup memory limit and current usage.
    • Ensured cached memory values refresh correctly when cgroup-based limits are applied.
  • Tests

    • Added coverage to verify accurate memory totals and cache invalidation when switching to cgroup memory data.

Signed-off-by: okjiang <819421878@qq.com>
@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has signed the dco. labels Jul 29, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

[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 nolouch 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

@ti-chi-bot ti-chi-bot Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2410d9d8-1843-4fe9-8abb-988a8531338a

📥 Commits

Reviewing files that changed from the base of the PR and between fad3ff9 and 550a135.

📒 Files selected for processing (2)
  • pkg/memory/meminfo.go
  • pkg/memory/meminfo_test.go

📝 Walkthrough

Walkthrough

InitMemoryHook now uses a helper to switch to cgroup memory readers and refresh cached limits and usage. A new test verifies the cgroup total and invalidated usage cache.

Changes

Cgroup memory hook

Layer / File(s) Summary
Cgroup hook and cache update
pkg/memory/meminfo.go
The cgroup branch calls useCgroupMemoryHook, which selects cgroup readers, updates memLimit, and invalidates memUsage.
Hook cache test coverage
pkg/memory/meminfo_test.go
Adds leak-checking test setup and verifies the cgroup total and reset usage timestamp while restoring shared state.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: applying the cgroup memory limit immediately.
Description check ✅ Passed The description matches the template with problem, change details, tests, manual validation, and a release note.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@ti-chi-bot

ti-chi-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

@okJiang: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen-3 550a135 link true /test pull-unit-test-next-gen-3

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.32%. Comparing base (070828c) to head (550a135).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11063      +/-   ##
==========================================
+ Coverage   79.23%   79.32%   +0.09%     
==========================================
  Files         540      541       +1     
  Lines       76010    76358     +348     
==========================================
+ Hits        60226    60571     +345     
- Misses      11533    11535       +2     
- Partials     4251     4252       +1     
Flag Coverage Δ
unittests 79.32% <83.33%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant