Commit d549a84
fix(process/cache): balance parent refcount ops during LRU eviction
Update process.Cache to properly perform refcount operations in the eviction path.
When a process tracked by process.Cache gets LRU evicted due to pressure before its
exit event arrives, we currently only update metrics and move on without doing any
refcount operations.
When the child's exit event later arrives, the exit handler cannot find the child in
the cache, so GetParentProcessInternal returns nil and the parent-- is skipped. This
leads to an imbalance as process.cacheGarbageCollector will only clean those entries
with balanced refcounts (refcnt=0). The entries remain in the cache longer than they
should, flooding the cache with invalid entries and increasing eviction pressure.
To fix this, we decrement the parent refcount in the eviction callback, but only for
entries still marked inUse. An unconditional decrement in the callback would
double-count parent-- for these normally-exiting processes, driving the still-live
parent's refcount to zero prematurely and causing it to be garbage-collected while
still running.
Signed-off-by: David Windsor <dwindsor@gmail.com>1 parent 9564909 commit d549a84
1 file changed
Lines changed: 27 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
148 | 153 | | |
149 | 154 | | |
150 | | - | |
| 155 | + | |
151 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
152 | 176 | | |
153 | 177 | | |
154 | 178 | | |
155 | 179 | | |
156 | 180 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 181 | + | |
| 182 | + | |
161 | 183 | | |
162 | 184 | | |
163 | 185 | | |
| |||
0 commit comments