memblock: refactor internal allocation functions