Reduce memory usage on windows when running external programs #3335
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a version of the patch from https://trac.sagemath.org/ticket/27214
TL;DR This is an issue that has come up in the past with Pari as well. When you mmap a large region of memory in Cygwin, and then fork() the process, the entirety of that region has to have physical memory committed to it.
This is a known issue on Cygwin and is sort-of by design (or rather a known limitation due to the underlying OS). The workaround, generally, is to use the non-POSIX
MAP_NORESERVE
flag which comes from Linux, but has slightly different, albeit similar implications.For now we just use the
MAP_NORESERVE
flag on Cygwin, though it could be used on Linux as well. The implication is that it is possible to reserve a larger region of memory even if there are not enough physical pages at the time of themmap()
call to fill the entire region (though if there is enough physical memory later then it's no problem). The main downside to this is that if you reach a point where you do run out of physical memory to handle writes to the mmap'd region, then the application will crash (segfault most likely). Though I haven't tried to reproduce such a situation in GAP.