In fact El Salvador inaugurated one of the largest prisons in the world specifically to deal with the issue of overcrowding. It can house up to 40k inmates. Overcrowding is no longer an issue.

The prison system has very well structured incentives for good behaviour and skill development on the inside, coupled with a healthy dose of additional punishment for bad behaviour. All in all the stick is pretty big, and the carrot is pretty juicy.