-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
None
-
None
-
None
-
None
-
None
-
None
-
None
SERVER-135561 adds a SharedMemoryBudget for operations whose work runs on several threads (the SBE exchange worker pool). While an operation is connected to a budget, the main operation tracker's own counters are a signed per-thread balance, not the operation's memory in use. The operation's real total is in the budget.
Some operation-wide readers still call OperationMemoryUsageTracker::inUseTrackedMemoryBytes(), which returns only the main thread's balance:
- queryMemoryCheckLoadShedding() (query_memory_load_shedding.cpp:490) uses it to decide whether an operation is a shed candidate and how likely it is to be shed.
- The idle-cursor sweep (cursor_manager.cpp:248) uses it to decide whether a cursor has memory to reclaim.
- clientcursor.cpp:250 (cursor memory stats) reads the same figure. Not yet checked.
Impact
If workers hold the memory and the main thread holds little or none, both paths see "nothing to reclaim" and skip the operation, even under memory pressure. It affects only operations that use the shared budget, which is gated by featureFlagQueryMemoryTracking.
Proposed approach
- Make inUseTrackedMemoryBytes() return max(budget unique total, 0) while the tracker is connected, so the consumers above need no change. Alternative: add a shared-total accessor and update each consumer.
- Return the unique figure, since the limit and shedding use unique.
- Update the tests that read the main balance while connected. ConnectedTrackerMayGoNegativeWhenAnotherThreadChargedTheMemory is one.
- Add a test where workers hold all the memory and the main balance is 0, checking that the shedding eligibility and the sweep see the shared total.
Open question: the idle-cursor sweep reads a stashed tracker from another thread. _sharedBudget is a plain shared_ptr that the last worker release resets. Check what lock the sweep holds, so that reading it cannot race with a release or a reconnect.
- is related to
-
SERVER-135561 Integrate MemoryUsageTracker in the parallel processing
-
- In Code Review
-