Skip to content
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

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/sysmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ int SyTryToIncreasePool(void)
#define MAP_ANONYMOUS MAP_ANON
#endif

#ifdef SYS_IS_CYGWIN32
#define GAP_MMAP_FLAGS MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE
#else
#define GAP_MMAP_FLAGS MAP_PRIVATE|MAP_ANONYMOUS
#endif

static void *SyMMapStart = NULL; /* Start of mmap'ed region for POOL */
static void *SyMMapEnd; /* End of mmap'ed region for POOL */
static void *SyMMapAdvised; /* We have already advised about non-usage
Expand Down Expand Up @@ -341,15 +347,15 @@ static void * SyAnonMMap(size_t size)
size = SyRoundUpToPagesize(size);
#ifdef SYS_IS_64_BIT
/* The following is at 16 Terabyte: */
result = mmap((void *) (16L*1024*1024*1024*1024), size,
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
result = mmap((void *) (16L*1024*1024*1024*1024), size,
PROT_READ|PROT_WRITE, GAP_MMAP_FLAGS, -1, 0);
if (result == MAP_FAILED) {
result = mmap(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
GAP_MMAP_FLAGS, -1, 0);
}
#else
result = mmap(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
GAP_MMAP_FLAGS, -1, 0);
#endif
if (result == MAP_FAILED)
result = NULL;
Expand All @@ -370,7 +376,7 @@ static int SyTryToIncreasePool(void)
size = (Int) SyMMapEnd - (Int) SyMMapStart;
newchunk = SyRoundUpToPagesize(size/2);
result = mmap(SyMMapEnd, newchunk, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
GAP_MMAP_FLAGS, -1, 0);
if (result == MAP_FAILED) return -1;
if (result != SyMMapEnd) {
munmap(result,newchunk);
Expand Down
4 changes: 0 additions & 4 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,11 +1072,7 @@ void InitSystem (
#else
SyStorMin = 64 * 1024L;
SyStorMax = 1024*1024L; /* This is in kB! */
#ifdef SYS_IS_CYGWIN32
SyAllocPool = 0; /* works better on cygwin */
#else
SyAllocPool = 1536L*1024*1024; /* Note this is in bytes! */
#endif
#endif
SyStorOverrun = 0;
SyStorKill = 0;
Expand Down