Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tikv_alloc: Add per thread memory usage #16255

Merged
merged 28 commits into from
May 6, 2024
Merged

Conversation

Connor1996
Copy link
Member

@Connor1996 Connor1996 commented Dec 29, 2023

What is changed and how it works?

Issue Number: Ref #15927

What's Changed:

Add per thread memory usage

Jemalloc has mapped memory stats per arena. We can bind each thread with a dedicated arena, then we have per thread memory usage.

The total memory ~== block cache size + total of per thread footprint
截屏2024-04-07 16 28 25

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Release note

Add per thread memory usage

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Copy link
Contributor

ti-chi-bot bot commented Dec 29, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • glorv
  • overvenus

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@@ -545,6 +545,7 @@ where
let t = thread::Builder::new()
.name(name)
.spawn_wrapper(move || {
tikv_alloc::thread_allocate_exclusive_arena().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Does it mean memory arena can not be shared between threads?
Will it aggravate memory fragment or even OOM?
Can it tell how much memory is held (but not allocated) by a thread?

Copy link
Member Author

Choose a reason for hiding this comment

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

  • By default, the number of arena is four times of CPU cores. So currently, it's already nearly one arena per one thread. So I don't think it would aggravate memory fragment in TiKV case.

  • What you mean by "held" is holding the memory allocated by other thread? Can't as allocator doesn't have the knowledge that the memory ownership is moved to another thread. At least, when it's freed in other threads, the memory usage accounted in the original allocated thread would be decreased.

Copy link
Member

Choose a reason for hiding this comment

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

Should we consider implementing a configuration switch to disable this feature, as a precautionary measure in case it triggers unforeseen issues?

Copy link
Contributor

Choose a reason for hiding this comment

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

According to the document, " There is a small fixed per-arena overhead, and additionally, arenas manage memory completely independently of each other, which means a small fixed increase in overall memory fragmentation. These overheads are not generally an issue, given the number of arenas normally used. Note that using substantially more arenas than the default is not likely to improve performance, mainly due to reduced cache performance. However, it may make sense to reduce the number of arenas if an application does not make much use of the allocation functions."

To make sure the overhead is small, can you run some read write mixed workload to compare the memory usage with and without this feature? @Connor1996

Copy link
Member Author

Choose a reason for hiding this comment

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

There are four rounds of sysbench tests, read_only, insert, write_only, read_write case respectively. And there is no noticeable difference in memory usage
07ce2f8c-43c6-4ca9-9d31-1e161785afbc

@ti-chi-bot ti-chi-bot bot added size/XL and removed size/M labels Apr 2, 2024
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@ti-chi-bot ti-chi-bot bot removed the needs-rebase label Apr 30, 2024
@Connor1996
Copy link
Member Author

/test

Copy link
Contributor

ti-chi-bot bot commented Apr 30, 2024

@Connor1996: The /test command needs one or more targets.
The following commands are available to trigger required jobs:

  • /test pull-unit-test

Use /test all to run all jobs.

In response to this:

/test

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/test-infra repository.

@Connor1996
Copy link
Member Author

/merge

Copy link
Contributor

ti-chi-bot bot commented Apr 30, 2024

@Connor1996: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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 ti-community-infra/tichi repository.

Copy link
Contributor

ti-chi-bot bot commented Apr 30, 2024

This pull request has been accepted and is ready to merge.

Commit hash: 7a3df1d

@ti-chi-bot ti-chi-bot bot added the status/can-merge Status: Can merge to base branch label Apr 30, 2024
@glorv
Copy link
Contributor

glorv commented Apr 30, 2024

@Connor1996 you need to address the DCO first

@Connor1996
Copy link
Member Author

/test

Copy link
Contributor

ti-chi-bot bot commented Apr 30, 2024

@Connor1996: The /test command needs one or more targets.
The following commands are available to trigger required jobs:

  • /test pull-unit-test

Use /test all to run all jobs.

In response to this:

/test

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/test-infra repository.

@Connor1996
Copy link
Member Author

/test pull-unit-test

1 similar comment
@Connor1996
Copy link
Member Author

/test pull-unit-test

@glorv
Copy link
Contributor

glorv commented Apr 30, 2024

--- TRY 3 STDERR:        tikv config::tests::test_config_template_no_superfluous_keys ---

thread 'config::tests::test_config_template_no_superfluous_keys' panicked at src/config/mod.rs:6878:10:

called `Result::unwrap()` on an `Err` value: Error { inner: ErrorInner { kind: Wanted { expected: "newline", found: "a comma" }, line: Some(99), col: 37, at: Some(4428), message: "", key: [] } }

stack backtrace:

   0: rust_begin_unwind

             at /rustc/89e2160c4ca5808657ed55392620ed1dbbce78d1/library/std/src/panicking.rs:645:5

   1: core::panicking::panic_fmt

             at /rustc/89e2160c4ca5808657ed55392620ed1dbbce78d1/library/core/src/panicking.rs:72:14

   2: core::result::unwrap_failed

             at /rustc/89e2160c4ca5808657ed55392620ed1dbbce78d1/library/core/src/result.rs:1649:5

   3: core::result::Result<T,E>::unwrap

   4: tikv::config::tests::test_config_template_no_superfluous_keys

   5: tikv::config::tests::test_config_template_no_superfluous_keys::{{closure}}

   6: core::ops::function::FnOnce::call_once

   7: core::ops::function::FnOnce::call_once

             at /rustc/89e2160c4ca5808657ed55392620ed1dbbce78d1/library/core/src/ops/function.rs:250:5

note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@Connor1996 Seems on test case need to be fixed

Signed-off-by: Connor1996 <zbk602423539@gmail.com>
@ti-chi-bot ti-chi-bot bot removed the status/can-merge Status: Can merge to base branch label May 6, 2024
@Connor1996
Copy link
Member Author

/merge

Copy link
Contributor

ti-chi-bot bot commented May 6, 2024

@Connor1996: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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 ti-community-infra/tichi repository.

Copy link
Contributor

ti-chi-bot bot commented May 6, 2024

This pull request has been accepted and is ready to merge.

Commit hash: c4fdfa9

@ti-chi-bot ti-chi-bot bot added the status/can-merge Status: Can merge to base branch label May 6, 2024
@ti-chi-bot ti-chi-bot bot merged commit 88099c9 into tikv:master May 6, 2024
7 checks passed
@ti-chi-bot ti-chi-bot bot added this to the Pool milestone May 6, 2024
@Connor1996 Connor1996 deleted the mem branch May 6, 2024 06:40
@Connor1996
Copy link
Member Author

/cherry-pick release-8.1

ti-chi-bot pushed a commit to ti-chi-bot/tikv that referenced this pull request May 13, 2024
ref tikv#15927

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

@Connor1996: new pull request created to branch release-8.1: #17005.

In response to this:

/cherry-pick release-8.1

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 ti-community-infra/tichi repository.

ti-chi-bot bot added a commit that referenced this pull request May 13, 2024
ref #15927

Add per thread memory usage

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: Connor1996 <zbk602423539@gmail.com>

Co-authored-by: Connor <zbk602423539@gmail.com>
Co-authored-by: Connor1996 <zbk602423539@gmail.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note size/XXL status/can-merge Status: Can merge to base branch status/LGT2 Status: PR - There are already 2 approvals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants