Commit d8153d4
Fix expand ceiling bug in ObjectSizeController
Summary:
## Background
Object cache capacity is configured by setting `l1EntriesLimit` via `ObjectCacheConfig::setCacheCapacity()`. During initialization, the cache estimates how many slabs are needed to hold that many entries:
allocsPerSlab = Slab::kSize / l1AllocSize (items that fit in one slab)
slabsPerShard = ceil(l1EntriesLimit / numShards / allocsPerSlab)
Because of the ceiling division, the total number of allocation slots (slabsPerShard × allocsPerSlab × numShards) is always >= l1EntriesLimit. The surplus slots are filled with "structural placeholders" — dummy items that prevent user data from exceeding the configured limit.
## Bug & Fix
In `FreeMemoryOnly` mode, `work()` calls `expandCacheByEntriesNum(expandCacheBy)` directly — it never flows through `adjustCacheEntriesLimit()` where the `std::min(newEntriesLimit, l1EntriesLimit)` cap lives. Without a ceiling check inside `expandCacheByEntriesNum()` itself, repeated expand calls could pop structural placeholders, pushing `currentEntriesLimit_` above `l1EntriesLimit`.
Example (l1EntriesLimit=100, 5 structural placeholders from slab rounding):
After init: currentEntriesLimit_=100, placeholders=5
Shrink by 10: currentEntriesLimit_=90, placeholders=15
Expand by 15: pops all 15 → currentEntriesLimit_=105 > 100!
Fix: pre-calculate `maxExpand = l1EntriesLimit - currentEntriesLimit_` as the loop bound in `expandCacheByEntriesNum()`, so it caps itself regardless of the call path. Also snapshot the atomic `currentEntriesLimit_` in `adjustCacheEntriesLimit()` and fix `totalEntriesExpanded_` counter.
Reviewed By: rlyerly
Differential Revision: D97062845
fbshipit-source-id: e736a9325dcea88bc2ff4e4b44d9e0e9859891451 parent fe39d81 commit d8153d4
2 files changed
Lines changed: 95 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
244 | | - | |
| 245 | + | |
| 246 | + | |
245 | 247 | | |
246 | 248 | | |
247 | | - | |
248 | | - | |
249 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
250 | 252 | | |
251 | 253 | | |
252 | | - | |
| 254 | + | |
| 255 | + | |
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| |||
275 | 278 | | |
276 | 279 | | |
277 | 280 | | |
278 | | - | |
| 281 | + | |
| 282 | + | |
279 | 283 | | |
280 | | - | |
| 284 | + | |
| 285 | + | |
281 | 286 | | |
282 | 287 | | |
283 | 288 | | |
284 | 289 | | |
285 | | - | |
| 290 | + | |
286 | 291 | | |
287 | 292 | | |
288 | 293 | | |
289 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
290 | 302 | | |
291 | 303 | | |
292 | 304 | | |
| 305 | + | |
293 | 306 | | |
294 | 307 | | |
295 | 308 | | |
296 | | - | |
| 309 | + | |
297 | 310 | | |
298 | 311 | | |
299 | 312 | | |
300 | | - | |
| 313 | + | |
| 314 | + | |
301 | 315 | | |
302 | | - | |
| 316 | + | |
| 317 | + | |
303 | 318 | | |
304 | 319 | | |
305 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2343 | 2343 | | |
2344 | 2344 | | |
2345 | 2345 | | |
2346 | | - | |
| 2346 | + | |
2347 | 2347 | | |
2348 | 2348 | | |
2349 | 2349 | | |
| |||
2448 | 2448 | | |
2449 | 2449 | | |
2450 | 2450 | | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| 2494 | + | |
| 2495 | + | |
| 2496 | + | |
| 2497 | + | |
| 2498 | + | |
| 2499 | + | |
| 2500 | + | |
| 2501 | + | |
| 2502 | + | |
| 2503 | + | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
2451 | 2517 | | |
2452 | 2518 | | |
0 commit comments