engine/partitions: add sorting and partitioning by free resources

Still work to do, but taking it one step at a time