Skip to content

Commit

Permalink
Change to dynamic memory allocation/commit on windows
Browse files Browse the repository at this point in the history
This commit changes how the Windows memory allocation/commitment
is done by switching from committing all memory immediately
to only committing memory dynamically as it gets allocated.

This resolves the Windows errors that PR ponylang#1614 and PR ponylang#1629 have
been encountering related to `ponyint_virt_alloc` and `The paging
file is too small for this operation to complete.`
  • Loading branch information
dipinhora committed Mar 9, 2017
1 parent 6c05624 commit 45ed7b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libponyrt/mem/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void* ponyint_virt_alloc(size_t bytes)
void* p;

#if defined(PLATFORM_IS_WINDOWS)
p = VirtualAlloc(NULL, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
p = VirtualAlloc(NULL, bytes, MEM_RESERVE, PAGE_READWRITE);
#elif defined(PLATFORM_IS_POSIX_BASED)
#if defined(PLATFORM_IS_LINUX)
p = mmap(0, bytes, PROT_READ | PROT_WRITE,
Expand Down
22 changes: 22 additions & 0 deletions src/libponyrt/mem/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,14 @@ static void* pool_alloc_pages(size_t size)
pool_block_t* block = (pool_block_t*)ponyint_virt_alloc(POOL_MMAP);
size_t rem = POOL_MMAP - size;

#if defined(PLATFORM_IS_WINDOWS)
// Commit pages that have only been reserved so far
// so block information can be written.
// This is safe even if the same pages have already
// been commited previously.
VirtualAlloc(block, 1024, MEM_COMMIT, PAGE_READWRITE);
#endif

block->size = rem;
block->next = NULL;
block->prev = NULL;
Expand Down Expand Up @@ -853,6 +861,13 @@ void* ponyint_pool_alloc(size_t index)
pool_local_t* pool = pool_local;
void* p = pool_get(pool, index);

#if defined(PLATFORM_IS_WINDOWS)
// Commit pages that have only been reserved so far.
// This is safe even if the same pages have already
// been commited previously.
VirtualAlloc(p, ponyint_pool_size(index), MEM_COMMIT, PAGE_READWRITE);
#endif

TRACK_ALLOC(p, POOL_MIN << index);

#ifdef USE_VALGRIND
Expand Down Expand Up @@ -905,6 +920,13 @@ void* ponyint_pool_alloc_size(size_t size)
size = ponyint_pool_adjust_size(size);
void* p = pool_alloc_pages(size);

#if defined(PLATFORM_IS_WINDOWS)
// Commit pages that have only been reserved so far.
// This is safe even if the same pages have already
// been commited previously.
VirtualAlloc(p, size, MEM_COMMIT, PAGE_READWRITE);
#endif

TRACK_ALLOC(p, size);

#ifdef USE_VALGRIND
Expand Down

0 comments on commit 45ed7b1

Please sign in to comment.