Closed Bug 1514122 Opened 6 years ago Closed 6 years ago

Make rust code use mozjemalloc directly on Windows

Categories

(Core :: Memory Allocator, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla66
Tracking Status
firefox66 --- fixed

People

(Reporter: glandium, Assigned: glandium)

References

Details

Attachments

(1 file)

Until rust 1.28, there was no stable way to change the allocator used by rust code. In bug 1280578, we hooked HeadAlloc/HeapFree/HeapRealloc, that the default rust system allocator uses. On other platforms, rust code just ended up using malloc/free/realloc like everything else. As of rust 1.28, though, it is now possible to use the GlobalAlloc trait and the #[global_allocator] attribute to set an allocator. On Windows, this can allow us to hook mozjemalloc directly, rather than using an indirection through HeapAlloc/etc. (which require an extra call to GetProcessHeap), so let's do this.
So, this raises something interesting, where a *lot* of code seems to be requiring memalign (which we're not exposing on windows, so that caused linking problems on my first attempt). That would indicate either some optimization problems in rust, where it can't figure out those branches are never going to be taken, or that means we have a lot of things that either require a large alignment or an alignment larger than the size of the allocation. If it's not an optimization problem, then there might be something fishy with plenty of types.
Component: General → Memory Allocator
Product: Toolkit → Core
Until rust 1.28, there was no stable way to change the allocator used by rust code. In bug 1280578, we hooked HeadAlloc/HeapFree/HeapRealloc, that the default rust system allocator uses. On other platforms, rust code just ended up using malloc/free/realloc like everything else. As of rust 1.28, though, it is now possible to use the GlobalAlloc trait and the #[global_allocator] attribute to set an allocator. On Windows, this can allow us to hook mozjemalloc directly, rather than using an indirection through HeapAlloc/etc. (which require an extra call to GetProcessHeap), so let's do this. On other platforms, this just ends up doing the same thing as the default rust system allocator (except for the memalign limit on 32-bits platforms). We still need the HeapAlloc/etc. hooks for some C++ code using it, though. Another benefit is that the HeapAlloc GlobalAlloc implementation needs to do its own memalign, which it does by overallocating and aligning manually. We obviously don't need to do this when we using memalign/_aligned_malloc directly.
Pushed by mh@glandium.org: https://hg.mozilla.org/integration/autoland/rev/f626107995b5 Make rust code use mozjemalloc directly. r=froydnj
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla66
Blocks: 1884054
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: