MCPcopy Create free account
hub / github.com/facebook/CacheLib / TEST

Function TEST

cachelib/allocator/tests/MemoryMonitorTest.cpp:27–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25constexpr size_t kGBytes = kMBytes * 1024;
26
27TEST(MemoryMonitorTest, increasingRateLimiter) {
28 RateLimiter rl(true /*detectIncrease*/);
29 rl.setWindowSize(10 /*windowSize*/);
30 size_t rssVal = 10 * kGBytes; // Start at 10GB
31 size_t reclaimPerIter = 2 * kGBytes * 5 / 100; // 5% of upper-lower bounds
32 while (rssVal < 30 * kGBytes) {
33 rl.addValue(rssVal); // Growth by 1GB per poll period
34 EXPECT_EQ(0, rl.throttle(reclaimPerIter));
35 rssVal += kGBytes;
36 }
37 // Reclaiming is stopped for next 10 iterations, followed by gradual
38 // increase in next 10 iterations to full unthrottled reclaim.
39 for (int i = 0; i < 21; i++) {
40 if (i < 10) {
41 rssVal += 10 * kMBytes; // Next 10 steps growth stops
42 }
43 rl.addValue(rssVal);
44 if (i == 20) {
45 EXPECT_EQ(reclaimPerIter, rl.throttle(reclaimPerIter));
46 } else if (i >= 10) {
47 EXPECT_LT(0, rl.throttle(reclaimPerIter));
48 } else {
49 EXPECT_EQ(0, rl.throttle(reclaimPerIter));
50 }
51 }
52 // While rss is dropping, reclaim is unthrottled
53 for (int i = 0; i < 10; i++) {
54 rssVal -= kGBytes;
55 rl.addValue(rssVal);
56 EXPECT_EQ(reclaimPerIter, rl.throttle(reclaimPerIter));
57 }
58}
59
60TEST(MemoryMonitorTest, decreasingRateLimiter) {
61 RateLimiter rl(false /*detectIncrease*/);

Callers

nothing calls this directly

Calls 5

getMemAvailableFunction · 0.85
setCgroupMemoryAdvisingFunction · 0.85
setWindowSizeMethod · 0.80
addValueMethod · 0.80
throttleMethod · 0.45

Tested by

no test coverage detected