How to allocate huge byte array safely

I see that the code in the OP is using with_capacity+set_len, so it's uninitialized. Do you get the same behaviour if you do vec![1; len]? Writing the pages ought to force the OS to actually give you the memory.

(Note also that getting uninitialized memory in safe rust is unsound, so please do something about it regardless.)