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

[wasm] mmap/lock free allocator optimizations #102265

Merged
merged 1 commit into from
May 23, 2024
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
1 change: 1 addition & 0 deletions src/mono/mono/sgen/sgen-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "mono/sgen/sgen-gc.h"
#include "mono/utils/lock-free-alloc.h"
#include "mono/utils/options.h"
#include "mono/sgen/sgen-memory-governor.h"
#include "mono/sgen/sgen-client.h"

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/utils/lock-free-alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static unsigned long
prot_flags_for_activate (int activate)
{
unsigned long prot_flags = activate? MONO_MMAP_READ|MONO_MMAP_WRITE: MONO_MMAP_NONE;
return prot_flags | MONO_MMAP_PRIVATE | MONO_MMAP_ANON;
return prot_flags | MONO_MMAP_PRIVATE | MONO_MMAP_ANON | MONO_MMAP_NOZERO;
}

static gpointer
Expand Down
5 changes: 4 additions & 1 deletion src/mono/mono/utils/lock-free-alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ typedef struct {
MonoMemAccountType account_type;
} MonoLockFreeAllocator;

// FIXME: On WASM the page size is 64KB, so this isn't enough.
#ifdef HOST_WASM
#define LOCK_FREE_ALLOC_SB_MAX_SIZE (mono_opt_wasm_mmap ? 65536 : 16384)
#else
#define LOCK_FREE_ALLOC_SB_MAX_SIZE 16384
#endif
#define LOCK_FREE_ALLOC_SB_HEADER_SIZE (sizeof (gpointer))
#define LOCK_FREE_ALLOC_SB_USABLE_SIZE(block_size) ((block_size) - LOCK_FREE_ALLOC_SB_HEADER_SIZE)

Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/utils/mono-mmap-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ valloc_impl (void *addr, size_t size, int flags, MonoMemAccountType type)
if ((flags & MONO_MMAP_FIXED) && addr)
return NULL;

ptr = mwpm_alloc_range (size, 1);
ptr = mwpm_alloc_range (size, (flags & MONO_MMAP_NOZERO) == 0);
if (!ptr)
return NULL;
} else
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/utils/mono-mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum {
MONO_MMAP_FIXED = 1 << 7,
MONO_MMAP_32BIT = 1 << 8,
MONO_MMAP_JIT = 1 << 9,
/* do not zero the new pages */
MONO_MMAP_NOZERO = 1 << 10,
};

Expand Down
Loading