forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emmalloc: Fix allocations of high alignment (emscripten-core#20704)
Take the alignment into account when requesting new memory from the OS. If the alignment is high then we need to ask for enough to ensure we end up aligned, or else we can end up allocating double the memory we need (see emscripten-core#20645). This only changes the amount we allocate from the OS if the alignment is non- standard, that is, this is NFC for normal calls to malloc. Also remove an assertion that limited the maximum alignment. mimalloc wants 4 MB alignment. Fixes emscripten-core#20654
- Loading branch information
Showing
10 changed files
with
80 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"a.html": 567, | ||
"a.html.gz": 379, | ||
"a.js": 17921, | ||
"a.js.gz": 8079, | ||
"a.js": 17841, | ||
"a.js.gz": 8088, | ||
"a.mem": 3171, | ||
"a.mem.gz": 2713, | ||
"total": 21659, | ||
"total_gz": 11171 | ||
"total": 21579, | ||
"total_gz": 11180 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"a.html": 567, | ||
"a.html.gz": 379, | ||
"a.js": 17399, | ||
"a.js.gz": 7910, | ||
"a.js": 17319, | ||
"a.js.gz": 7908, | ||
"a.mem": 3171, | ||
"a.mem.gz": 2713, | ||
"total": 21137, | ||
"total_gz": 11002 | ||
"total": 21057, | ||
"total_gz": 11000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <assert.h> | ||
#include <emscripten/console.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
size_t sizeT(void* p) { | ||
return (size_t)p; | ||
} | ||
|
||
int main() { | ||
const size_t MB = 1024 * 1024; | ||
const size_t ALIGN = 4 * MB; | ||
const size_t SIZE = 32 * MB; | ||
|
||
// Allocate a very large chunk of memory (32MB) with very high alignment (4 | ||
// MB). This is similar to what mimalloc does in practice. | ||
void* before = sbrk(0); | ||
void* p = aligned_alloc(ALIGN, SIZE); | ||
void* after = sbrk(0); | ||
emscripten_console_logf("before: %p after: %p p: %p\n", before, after, p); | ||
|
||
// The allocation must be properly aligned. | ||
assert(sizeT(p) % ALIGN == 0); | ||
|
||
// We should only have sbrk'd a reasonable amount (this is a regression test | ||
// for #20645 where we sbrk'd double the necessary amount). We expect at most | ||
// 36 MB (the size of the allocation plus the alignment) plus a few bytes of | ||
// general overhead. | ||
assert(sizeT(after) - sizeT(before) < ALIGN + SIZE + 100); | ||
|
||
emscripten_console_log("success"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters