-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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_util: make memory quota alloc and free simpler #16938
Conversation
Signed-off-by: glorv <glorvs@163.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Signed-off-by: glorv <glorvs@163.com>
Signed-off-by: glorv <glorvs@163.com>
@overvenus @Connor1996 PTAL, thanks~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok(_) => return, | ||
Err(current) => in_use_bytes = current, | ||
} | ||
let bytes = bytes as isize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the bytes is larger than isize::MAX
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. In order to handle overflow, I added a hard limit for a single alloc call.
Signed-off-by: glorv <glorvs@163.com>
Signed-off-by: glorv <glorvs@163.com>
/retest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to check numeric bounds with every method call.
Err(current) => in_use_bytes = current, | ||
} | ||
} | ||
self.in_use.fetch_add(bytes as isize, Ordering::Relaxed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the previous implementation also has this issue that the value of in_use
can overflow.
Since the API design for alloc_force
does not return an error, I think it is the caller's responsibility to ensure that both the actual memory allocation and this counter increase should success after calling alloc_force
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second alloc will return an error in the previous implementation.
It's okay that sometimes in_use
is larger than capacity
, but it's not okay that alloc
continues returning success.
Signed-off-by: glorv <glorvs@163.com>
@overvenus @Connor1996 PTAL again, thanks~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
components/tikv_util/src/memory.rs
Outdated
if bytes > MAX_MEMORY_ALLOC_SIZE { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some log or metrics here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Add a warn log for oversized alloc. Maybe we can also add a metrics for the alloc size distribution histogram later if we really need it.
Signed-off-by: glorv <glorvs@163.com>
Signed-off-by: glorv <glorvs@163.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
@glorv: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger
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. |
This pull request has been accepted and is ready to merge. Commit hash: e9c10c4
|
What is changed and how it works?
Issue Number: ref #15990
What's Changed:
benchmark Result: (The benchmark was running with a modified version of https://github.com/overvenus/benches-rust/blob/82c75f87bb7b9fabdbb2bbcf2bb11cc8f726d3a8/benches/memory.rs to compare the old and new version of MemoryQuota)
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Side effects
Release note