-
Notifications
You must be signed in to change notification settings - Fork 160
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
Reduce memory usage on windows when running external programs #3335
Reduce memory usage on windows when running external programs #3335
Conversation
on Cygwin Using MAP_NORESERVE on Cygwin prevents the need to commit physical pages for the entirety of mmap'd regions until they are actually used.
Interesting. On Linux we assume people haven't disabled over-commit, as the 64-bit GAP can reserve very large chunks of memory space upfront, which we assume will be allocated lazily when we use it. Therefore I don't think this will make anything worse, and might well make cygwin better (particularly as we move to larger 64-bit memory spaces) |
On Cygwin you're ultimately dealing with the Windows memory manager, so some things are different, and what |
One could also argue that it would be better, rather than making this fix Cygwin-specific, there should be no harm in passing For starters I kept it Cygwin-specific, but if you agree I could change that. |
Any thoughts on the question of not making this cygwin-specific? |
If we don't need it on Linux, I'd probably leave it, just because this code has in the past proved to be sensitive to changes causing problems on weird BSDs like DragonFly and the like, so (personally) I try not to change the memory allocation unless we are fixing a specific issue (like this one). |
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.