Fix problem with virtual memory commit in OOM scenario on Linux (#5609)
Fix problem with virtual memory commit in OOM scenario on Linux (#5609)

A stress tests have uncovered a mysterious issue with virtual memory committing on
Linux. During some stress tests, all of a sudden, segments of GC heap got unmapped
or virtual allocator has reserved a block of memory twice.
It turned out that the issue was caused by a strange behavior of mmap in the OOM case.
When we commit a subrange of previously reserved memory (reservation uses mmap with
PROT_NONE, commit uses mmap with PROT_READ | PROT_WRITE) and the mmap fails due to
OOM, it ends up leaving the whole range that was supposed to be committed completely
unmapped. A later attempt to reserve virtual memory finds this block as a free one
and happily reserves a block in it. But our VM allocator is not aware of this issue.

The fix is to use another way to commit pages in a reserved range - using mprotect
to change their protection from the initial PROT_NONE to PROT_READ | PROT_WRITE.
This way doesn't have the problem. I've verified that it works on OSX too, so
I am switching to that way unconditionally.
Decommit still uses mmap so that we don't have to keep track of dirty pages and
so that the pages are really returned to the system in decommit.
ruben-ayrapetyan/coreclr,yizhang82/coreclr,ruben-ayrapetyan/coreclr,JonHanna/coreclr,vinnyrom/coreclr,James-Ko/coreclr,ZhichengZhu/coreclr,roncain/coreclr,dasMulli/coreclr,bartdesmet/coreclr,yeaicc/coreclr,krk/coreclr,AlexGhiondea/coreclr,roncain/coreclr,dpodder/coreclr,dasMulli/coreclr,botaberg/coreclr,tijoytom/coreclr,shahid-pk/coreclr,dpodder/coreclr,parjong/coreclr,JonHanna/coreclr,vinnyrom/coreclr,krytarowski/coreclr,qiudesong/coreclr,pgavlin/coreclr,ZhichengZhu/coreclr,naamunds/coreclr,josteink/coreclr,naamunds/coreclr,wateret/coreclr,dasMulli/coreclr,rartemev/coreclr,James-Ko/coreclr,kyulee1/coreclr,yizhang82/coreclr,ragmani/coreclr,poizan42/coreclr,ragmani/coreclr,krytarowski/coreclr,cydhaselton/coreclr,James-Ko/coreclr,gkhanna79/coreclr,roncain/coreclr,sjsinju/coreclr,hseok-oh/coreclr,rartemev/coreclr,wateret/coreclr,hseok-oh/coreclr,krk/coreclr,YongseopKim/coreclr,parjong/coreclr,AlexGhiondea/coreclr,mmitche/coreclr,cmckinsey/coreclr,shahid-pk/coreclr,botaberg/coreclr,ramarag/coreclr,pgavlin/coreclr,jhendrixMSFT/coreclr,manu-silicon/coreclr,alexperovich/coreclr,JosephTremoulet/coreclr,ramarag/coreclr,jamesqo/coreclr,jhendrixMSFT/coreclr,cshung/coreclr,wtgodbe/coreclr,AlexGhiondea/coreclr,tijoytom/coreclr,Dmitry-Me/coreclr,neurospeech/coreclr,manu-silicon/coreclr,pgavlin/coreclr,martinwoodward/coreclr,bartdesmet/coreclr,wtgodbe/coreclr,naamunds/coreclr,manu-silicon/coreclr,yizhang82/coreclr,wtgodbe/coreclr,kyulee1/coreclr,josteink/coreclr,russellhadley/coreclr,parjong/coreclr,JonHanna/coreclr,josteink/coreclr,krk/coreclr,cmckinsey/coreclr,tijoytom/coreclr,gkhanna79/coreclr,Dmitry-Me/coreclr,sjsinju/coreclr,neurospeech/coreclr,hseok-oh/coreclr,sjsinju/coreclr,ruben-ayrapetyan/coreclr,shahid-pk/coreclr,pgavlin/coreclr,bartdesmet/coreclr,cydhaselton/coreclr,qiudesong/coreclr,Dmitry-Me/coreclr,roncain/coreclr,YongseopKim/coreclr,cydhaselton/coreclr,hseok-oh/coreclr,cmckinsey/coreclr,vinnyrom/coreclr,shahid-pk/coreclr,krytarowski/coreclr,rartemev/coreclr,manu-silicon/coreclr,jamesqo/coreclr,roncain/coreclr,ramarag/coreclr,ZhichengZhu/coreclr,JosephTremoulet/coreclr,ZhichengZhu/coreclr,gkhanna79/coreclr,martinwoodward/coreclr,parjong/coreclr,ZhichengZhu/coreclr,ruben-ayrapetyan/coreclr,KrzysztofCwalina/coreclr,sagood/coreclr,sagood/coreclr,mskvortsov/coreclr,rartemev/coreclr,poizan42/coreclr,martinwoodward/coreclr,bartdesmet/coreclr,cydhaselton/coreclr,cydhaselton/coreclr,neurospeech/coreclr,cshung/coreclr,wtgodbe/coreclr,ragmani/coreclr,wateret/coreclr,dasMulli/coreclr,naamunds/coreclr,parjong/coreclr,ruben-ayrapetyan/coreclr,yizhang82/coreclr,Dmitry-Me/coreclr,wtgodbe/coreclr,rartemev/coreclr,roncain/coreclr,cmckinsey/coreclr,kyulee1/coreclr,ramarag/coreclr,sagood/coreclr,yeaicc/coreclr,dasMulli/coreclr,ramarag/coreclr,jhendrixMSFT/coreclr,cmckinsey/coreclr,jhendrixMSFT/coreclr,dasMulli/coreclr,mskvortsov/coreclr,jamesqo/coreclr,JonHanna/coreclr,poizan42/coreclr,mskvortsov/coreclr,manu-silicon/coreclr,James-Ko/coreclr,sagood/coreclr,naamunds/coreclr,pgavlin/coreclr,qiudesong/coreclr,ragmani/coreclr,dasMulli/coreclr,shahid-pk/coreclr,tijoytom/coreclr,bartdesmet/coreclr,JonHanna/coreclr,krytarowski/coreclr,Dmitry-Me/coreclr,pgavlin/coreclr,yeaicc/coreclr,mmitche/coreclr,yeaicc/coreclr,jhendrixMSFT/coreclr,yeaicc/coreclr,vinnyrom/coreclr,James-Ko/coreclr,ramarag/coreclr,dpodder/coreclr,yizhang82/coreclr,JosephTremoulet/coreclr,sagood/coreclr,neurospeech/coreclr,cshung/coreclr,wateret/coreclr,botaberg/coreclr,sjsinju/coreclr,JonHanna/coreclr,ragmani/coreclr,wtgodbe/coreclr,alexperovich/coreclr,ZhichengZhu/coreclr,jhendrixMSFT/coreclr,AlexGhiondea/coreclr,AlexGhiondea/coreclr,krk/coreclr,hseok-oh/coreclr,mskvortsov/coreclr,poizan42/coreclr,russellhadley/coreclr,James-Ko/coreclr,manu-silicon/coreclr,kyulee1/coreclr,YongseopKim/coreclr,alexperovich/coreclr,vinnyrom/coreclr,JosephTremoulet/coreclr,jamesqo/coreclr,roncain/coreclr,mskvortsov/coreclr,cydhaselton/coreclr,KrzysztofCwalina/coreclr,Dmitry-Me/coreclr,martinwoodward/coreclr,KrzysztofCwalina/coreclr,hseok-oh/coreclr,poizan42/coreclr,krk/coreclr,JosephTremoulet/coreclr,wateret/coreclr,josteink/coreclr,AlexGhiondea/coreclr,jamesqo/coreclr,neurospeech/coreclr,martinwoodward/coreclr,shahid-pk/coreclr,parjong/coreclr,qiudesong/coreclr,qiudesong/coreclr,bartdesmet/coreclr,manu-silicon/coreclr,cshung/coreclr,alexperovich/coreclr,naamunds/coreclr,jhendrixMSFT/coreclr,YongseopKim/coreclr,KrzysztofCwalina/coreclr,russellhadley/coreclr,martinwoodward/coreclr,mmitche/coreclr,Dmitry-Me/coreclr,sagood/coreclr,jamesqo/coreclr,ruben-ayrapetyan/coreclr,alexperovich/coreclr,dpodder/coreclr,gkhanna79/coreclr,dpodder/coreclr,krk/coreclr,botaberg/coreclr,mmitche/coreclr,josteink/coreclr,krytarowski/coreclr,yeaicc/coreclr,cmckinsey/coreclr,cmckinsey/coreclr,kyulee1/coreclr,sjsinju/coreclr,botaberg/coreclr,botaberg/coreclr,dpodder/coreclr,sjsinju/coreclr,ramarag/coreclr,ZhichengZhu/coreclr,neurospeech/coreclr,ragmani/coreclr,josteink/coreclr,qiudesong/coreclr,gkhanna79/coreclr,cshung/coreclr,gkhanna79/coreclr,KrzysztofCwalina/coreclr,mmitche/coreclr,vinnyrom/coreclr,cshung/coreclr,mskvortsov/coreclr,russellhadley/coreclr,tijoytom/coreclr,KrzysztofCwalina/coreclr,krytarowski/coreclr,YongseopKim/coreclr,russellhadley/coreclr,yizhang82/coreclr,russellhadley/coreclr,mmitche/coreclr,YongseopKim/coreclr,alexperovich/coreclr,KrzysztofCwalina/coreclr,JosephTremoulet/coreclr,rartemev/coreclr,tijoytom/coreclr,martinwoodward/coreclr,bartdesmet/coreclr,vinnyrom/coreclr,kyulee1/coreclr,josteink/coreclr,wateret/coreclr,shahid-pk/coreclr,naamunds/coreclr,poizan42/coreclr,yeaicc/coreclr