gc() can overflow stack in case the cache has too many entries in it; since stack size is only 1M per thread, this happenned for our customer at 124530 entries in cache on a heavily loaded nscd with many users and groups.
Created attachment 2104 [details] Proposed patch
The change is too pessimistic when it comes to using the stack. I've checked in a modified patch.