Description
In dotnet/performance#1992, the customer shared with us the traces that illustrate the problem. The trace shows us that because a demotion happened, we have plenty of free space in gen 0, so we are not acquiring new segments, but then the last object is probably pinned (we cannot observe that from the trace, but given that demotion happened, this is highly likely ... ) so we don't have much space at the end of the ephemeral segment. (low ephemeral end space is observed)
We have a heuristic rule to say that if we are running out of space at the end of the ephemeral segment, then trigger a gen 1 GC. The hope is that by doing a higher generation GC, we should be able to free up more space at the end of the ephemeral segment. But our observation is that the rule is repeatedly triggered (probably because the pin is still there), so those higher generation GCs are not freeing the end space for us. Also, since nothing much happened to the higher generation objects, the GCs are not productive at all.
We should tune that rule to make sure that won't happen again. To do that, we might want to take the demotion or the free spaces into account in addition to just low ephemeral end space.