-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtime] Fix swift_slowAlloc to respect its alignMask parameter. #14375
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
Conversation
Instead of calling malloc, call AlignedAlloc. That calls posix_memalign on platforms where it's available. The man page cautions to use it judiciously, but Apple OSes and Linux implement it to call through to malloc when the alignment is suitable. Presumably/hopefully other OSes do the same. rdar://problem/22975669
@swift-ci please test |
@swift-ci please benchmark |
stdlib/public/runtime/Heap.cpp
Outdated
@@ -23,12 +23,11 @@ | |||
using namespace swift; | |||
|
|||
void *swift::swift_slowAlloc(size_t size, size_t alignMask) { | |||
// FIXME: use posix_memalign if alignMask is larger than the system guarantee. | |||
void *p = malloc(size); | |||
void *p = AlignedAlloc(size, alignMask + 1); |
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.
Is alignMask
guaranteed to be a power-of-two-minus-one?
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.
That should be fine. What is a problem is that posix_memalign
requires that the alignment be no smaller than sizeof(void*)
. We have at least one place that calls swift_slowAlloc(size, 0)
because it needs no alignment constraints.
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.
AlignedAlloc
makes sure the alignment is sufficiently large before calling through to posix_memalign
.
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.
That is unfortunate for performance. It would be better if we could satisfy posix_memalign's constraints directly. That would be a much wider change.
Build comment file:Optimized (O)Regression (2)
Improvement (3)
No Changes (355)
Unoptimized (Onone)Regression (5)
Improvement (24)
No Changes (331)
Hardware Overview
|
…fficiently small. rdar://problem/22975669
Let's see how it does with a direct call to malloc for alignments where that's suitable. |
@swift-ci please benchmark |
Build comment file:Optimized (O)Regression (1)
Improvement (1)
No Changes (358)
Unoptimized (Onone)Regression (6)
Improvement (3)
No Changes (351)
Hardware Overview
|
@swift-ci please test |
Instead of calling malloc, call AlignedAlloc. That calls posix_memalign on platforms where it's available. The man page cautions to use it judiciously, but Apple OSes and Linux implement it to call through to malloc when the alignment is suitable. Presumably/hopefully other OSes do the same.
rdar://problem/22975669