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

os/bluestore: fix target_buffer value overflow in Cache::trim() #12507

Merged
merged 1 commit into from Dec 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/os/bluestore/BlueStore.cc
Expand Up @@ -530,7 +530,17 @@ void BlueStore::Cache::trim(
uint64_t current_buffer = _get_buffer_bytes();
uint64_t current = current_meta + current_buffer;

uint64_t target_meta = target_bytes * target_meta_ratio;
uint64_t target_meta = target_bytes * (double)target_meta_ratio; //need to cast to double
//since float(1) might produce inaccurate value
// for target_meta (a bit greater than target_bytes)
// that causes overflow in target_buffer below.
//Consider the following code:
//uint64_t i =(uint64_t)227*1024*1024*1024 + 1;
//float f = 1;
//uint64_t i2 = i*f;
//assert(i == i2);

target_meta = min(target_bytes, target_meta); //and just in case that ratio is > 1
uint64_t target_buffer = target_bytes - target_meta;

if (current <= target_bytes) {
Expand Down