Skip to content

Commit

Permalink
fix bug in printing eviction success rate
Browse files Browse the repository at this point in the history
Summary:
This change fixes below bug printing wrong eviction success rate.

Evict Attempts: 439,372 Success: -4198434145486952.50%
RAM Evictions : 618,369

This happens because of the overflow in below code https://fburl.com/code/ln24ozv0

```
    out << folly::sformat(
               "Evict Attempts: {:,} Success: {:.2f}%",
               evictAttempts,
               invertPctFn(evictAttempts - numEvictions, evictAttempts)
```

Again, this could happen because evictAttempts and numEvictions are not taken atomically
https://fburl.com/code/i587dhfh

Reviewed By: therealgymmy

Differential Revision: D46043428

fbshipit-source-id: 022a07e09c1093ca705e9e57596fa912497ba32d
  • Loading branch information
Jaesoo Lee authored and facebook-github-bot committed Jun 5, 2023
1 parent ad0b378 commit b20b514
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cachelib/cachebench/cache/CacheStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ struct Stats {
allocAttempts,
invertPctFn(allocFailures, allocAttempts))
<< std::endl;
out << folly::sformat(
"Evict Attempts: {:,} Success: {:.2f}%",
evictAttempts,
invertPctFn(evictAttempts - numEvictions, evictAttempts))
out << folly::sformat("Evict Attempts: {:,} Success: {:.2f}%",
evictAttempts,
pctFn(numEvictions, evictAttempts))
<< std::endl;
out << folly::sformat("RAM Evictions : {:,}", numEvictions) << std::endl;

Expand Down

0 comments on commit b20b514

Please sign in to comment.