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

Make Large allocations naturally aligned #124

Merged
merged 7 commits into from
Feb 5, 2020
Merged

Make Large allocations naturally aligned #124

merged 7 commits into from
Feb 5, 2020

Conversation

mjp41
Copy link
Member

@mjp41 mjp41 commented Feb 4, 2020

This makes all large allocations aligned to their size next power of two size.

This introduces a new strategy for aligning blocks on platforms without a way to fetched aligned virtual memory (e.g. VirtualAlloc2, or mmap with MAP_ALIGNED).

To aid in debugging also uses mprotect to switch off unused pages in debug on posix platforms. This enables better testing of the Commit/Decommit code from Posix platforms.

This makes any large allocation naturally aligned to its size. This
means all alignment requests can be handled without checks.
The PAL API previously allowed for returning more memory than asked for.
This was when the PAL performed the alignment work, now this is done in
large alloc, so removing from the PAL.
On platforms that do not support aligned mmap/VirtualAlloc,
we need to produce heavily aligned blocks to guarantee we can meet
all possible alignment requests.

This commit grabs a block much larger than requested, and then produces
"offcuts" before and after the block of smaller/same "large_classes".  This
enables one mmap/virtual alloc request to services many other requests
for aligned memory.
By turning page access on and off, we can simulate the Windows
Commit/Decommit states on Posix platforms.

This is just enabled in Debug for now.
@mjp41
Copy link
Member Author

mjp41 commented Feb 4, 2020

#114 needs this.

src/mem/largealloc.h Outdated Show resolved Hide resolved
src/pal/pal_freebsd_kernel.h Outdated Show resolved Hide resolved
src/pal/pal_posix.h Outdated Show resolved Hide resolved
src/pal/pal_posix.h Show resolved Hide resolved
src/test/func/fixed_region/fixed_region.cc Show resolved Hide resolved
src/test/func/two_alloc_types/main.cc Show resolved Hide resolved
@mjp41 mjp41 merged commit 1d72024 into master Feb 5, 2020
@mjp41 mjp41 deleted the alignment branch February 6, 2020 09:08
mjp41 added a commit to mjp41/snmalloc-rs that referenced this pull request Feb 7, 2020
`snmalloc` now supports alignment of all allocations with
  microsoft/snmalloc#124
This comment is no longer required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants