-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
jl_gc_calloc_aligned and friends: obtaining aligned zero initialized memory efficiently #42704
base: master
Are you sure you want to change the base?
Conversation
commit 927da5f067f51700c1d5ffb22304382710b1643b Author: Mark Kittisopikul <[email protected]> Date: Tue Oct 19 05:52:50 2021 -0400 Export jl_gc_*_aligned, jl_gc_managed_calloc commit ce011a82cba044f88a962b6da24a02bd105fed3e Author: Mark Kittisopikul <[email protected]> Date: Mon Oct 18 13:13:09 2021 -0400 Simplify, reduce diff versus master commit af4cf94520cc2c9fd5008b929c6e4ef2cd55bca3 Author: Mark Kittisopikul <[email protected]> Date: Mon Oct 18 03:40:07 2021 -0400 Mixed and working Fix JuliaLang#42673 by checking for unsigned integer wrapping for jl_*calloc* Reused former isaligned tagged bit for howtofree tagged bit Retained all existing functions jl_gc_*_aligned defaults to jl_* since macOS guarantees page alignment offset alignment to hold original (void *) p0, and size_t align commit 842bf06e785d3be97558083abe181505c6840549 Author: Mark Kittisopikul <[email protected]> Date: Sun Oct 17 02:20:11 2021 -0400 Undo renaming of jl_calloc, jl_free, and jl_realloc commit 9594400d207a9f8baac832af5dd0830165d1192e Author: Daniel Matz <[email protected]> Date: Fri Nov 11 18:31:54 2016 -0600 Remove the isaligned array flag commit 4bb083a5f6b44766632dd394397257ebafc91726 Author: Daniel Matz <[email protected]> Date: Fri Nov 4 08:59:43 2016 -0500 Disambiguate jl_malloc from jl_malloc_aligned Add gc counted, aligned malloc
Perhaps @yuyichao could also review? |
// TODO add special casing for macOS, where there is guarantee of alignment | ||
// - DONE, just use jl_malloc, jl_calloc, jl_realloc, jl_free since always aligned | ||
// TODO add special casing for 64 bit systems when 16 byte alignment is requested | ||
// TODO add checks on align? | ||
// - Enforce posix_memalign reqs of power of 2 multiple of sizeof(void *)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO add special casing for macOS, where there is guarantee of alignment | |
// - DONE, just use jl_malloc, jl_calloc, jl_realloc, jl_free since always aligned | |
// TODO add special casing for 64 bit systems when 16 byte alignment is requested | |
// TODO add checks on align? | |
// - Enforce posix_memalign reqs of power of 2 multiple of sizeof(void *)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may have come from previous rounds of review on prior iterations. If you don't mind, I'll keep this around for a bit longer until we have more eyes on this.
Adjust overflow detection condition Co-authored-by: Jameson Nash <[email protected]>
I separated the |
This is a rebase, revision, and squash of #22953. The main objective was to develop an aligned and GC tracked
calloc
to obtain zero initialized memory efficiently. I took out the tagged bit and the renaming of public API functions, and simplified such that the current PR is mainly just adding new code rather than modifying existing code.My main motivation is that a
calloc
basedzeros
improves performances on Windows:https://discourse.julialang.org/t/faster-zeros-with-calloc/69860
The main new contribution here is adding an offset to make space for saving the original pointer and the alignment. This hopefully addresses the issue in #22953 (comment) by @JeffBezanson . I suspect better space usage is possible in retrospect.
This could be used to address #130 or #9147. At the moment though, no actual change is made except to catch a potential overflow situation in
jl_calloc
.An important mechanism is where to put a tagged bit such that arrays created using these new functions can be correctly freed by
jl_gc_free_aligned
fromjl_gc_free_array
. Previously, it was proposed that thealigned
bit injl_array_flags_t
could be removed and possibly reused for this purpose.An alternative approach suggested by stevengj@7c9ab1d#r58133599 is to develop internal
calloc
and/orposix_memalign
implementations based upon musl (MIT License). However, after studying the implementations, I am not sure if they take full advantage of newly zeroed pages from the operating system.I would appreciate any comments and thoughts about future directions.
Demonstration
Squashed Commit Log (edited for what remains)
commit 927da5f067f51700c1d5ffb22304382710b1643b
Author: Mark Kittisopikul [email protected]
Date: Tue Oct 19 05:52:50 2021 -0400
...
Fix #42673 by checking for unsigned integer wrapping for jl_calloc
Reused former isaligned tagged bit for howtofree tagged bit
Retained all existing functions
jl_gc_aligned defaults to jl since macOS guarantees page alignment
offset alignment to hold original (void *) p0, and size_t align
commit 842bf06e785d3be97558083abe181505c6840549
Author: Mark Kittisopikul [email protected]
Date: Sun Oct 17 02:20:11 2021 -0400
commit 4bb083a5f6b44766632dd394397257ebafc91726
Author: Daniel Matz [email protected]
Date: Fri Nov 4 08:59:43 2016 -0500