Kmem rework

This refactoring is intended to simplify the code while making it easier to share code between ZoL and other Open ZFS platforms.