Hacker News new | ask | show | jobs
by one_off_comment 1688 days ago
There's gotta be some way to programmatically determine it, right? It may not be portable. It may require some system calls or something, but there's gotta be a way, right?
4 comments

I guess you could mlock() your memory and see if that succeeds or fails. When overcommit is enabled no memory is really safe.
Maybe a system call that checks whether writing to a page would result in a fault? What if we had memory file descriptors for pages? We'd be able to use them with epoll and io_uring to asynchronously check whether it's safe to write to the pages they represent.
I'm not an expert enough to tell you; I just read the article and decided that it was too long so summarized for others. There's some discussion upthread about catching SIGSEGV and other methods, FWIW.
The question is what problem are you actually trying to solve.

You can get away with just about anything if you do it in a child worker process which can safely crash.