Memory slab stats

This bases on and improves #560. It's also rebased on current master, and skips the commit which got reverted in #560.