Skip to content

Commit

Permalink
Don't set SyAllocPool = 0 for Cygwin, but do use MAP_NORESERVE for mmaps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
embray authored and ChrisJefferson committed Mar 12, 2019
1 parent 1213dab commit e73953f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit e73953f

Please sign in to comment.