Skip to content

SIGILL Illegal instrucion on Vec::reserve(2^32+1) #19426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
payload opened this issue Nov 30, 2014 · 8 comments
Closed

SIGILL Illegal instrucion on Vec::reserve(2^32+1) #19426

payload opened this issue Nov 30, 2014 · 8 comments

Comments

@payload
Copy link

payload commented Nov 30, 2014

on 64bit machine, compiled for 64bit. test case:

fn main() {
    let big: uint = 1024*1024*1024*4 + 1; // 2^32+1
    let mut vec: Vec<u8> = Vec::new();
    vec.reserve(big);
}

likely related: #18726

@Gankra
Copy link
Contributor

Gankra commented Nov 30, 2014

CC me

@thestinger
Copy link
Contributor

Rust handles out-of-memory by aborting like this.

@Gankra
Copy link
Contributor

Gankra commented Nov 30, 2014

Oh yeah, I guess you would need like 16-32 gigs of ram in a 64-bit machine on most OSes to successfully complete that reserve (which asks for an 8GB array)?

@thestinger
Copy link
Contributor

It will work if you enable full overcommit, but not by default on Linux.

@payload
Copy link
Author

payload commented Nov 30, 2014

It asks for 4GB+1B. A malloc in C of 4GB+1B works perfectly fine, cause it is just a request for memory to the kernel and not an actual usage of this memory. to the best of my knowledge in C on Linux one would have to write at each allocated page to actual consume those 4GB+1B.

@Gankra
Copy link
Contributor

Gankra commented Nov 30, 2014

@payload If you want 4GB + 1B use reserve_exact. reserve rounds allocations for amortization.

@Gankra
Copy link
Contributor

Gankra commented Nov 30, 2014

Admittedly, we could maybe make reserve check if the given number is at least the size of the current allocation, and call reserve_exact if it is.

Also note that Rust uses its own instance of jemalloc, and not the system allocator.

@thestinger
Copy link
Contributor

to the best of my knowledge in C on Linux one would have to write at each allocated page to actual consume

Linux supports full overcommit and virtual memory accounting but doesn't use either by default. It defaults to overcommit with heuristics returning allocation errors in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants