-
Notifications
You must be signed in to change notification settings - Fork 119
Mac M1 fix proposal. #278
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
Mac M1 fix proposal. #278
Conversation
davidchisnall
left a comment
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.
Thanks for working on this, a couple of comments inline.
src/pal/pal_apple.h
Outdated
| template<bool page_aligned = false> | ||
| static void zero(void* p, size_t size) noexcept | ||
| { | ||
| ::bzero(p, size); |
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.
If this is required only on AArch64 (is it only AArch64 macOS, or iOS derivatives as well?) then can we guard it on a constexpr if check that the AAL is for AArch64, not x86?
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.
fair enough. yes Mac M1 is "only" a super iOs device anyway.
src/pal/pal_apple.h
Outdated
| static void notify_not_using(void* p, size_t size) noexcept | ||
| { | ||
| SNMALLOC_ASSERT(is_aligned_block<PALBSD::page_size>(p, size)); | ||
| while (madvise(p, size, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) |
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 don't believe this is correct. MADV_FREE_REUSABLE is completely undocumented (and therefore Apple reserves the right to remove it or modify its semantics in minor version updates) but the comments in Apple's open-source libmalloc indicate that you must madvise with MADV_FREE_REUSE before reuse. We would need a notify_using implementation that does this. I don't know what the performance differences are between MADV_FREE and the pair of MADV_FREE_REUSEABLE + MADV_FREE_REUSE, if it's significant then we might want to provide both options to allow users to tune for lower memory or higher performance.
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.
Yes this doesd even appear on the man page. however it s not related at all to performance (it s mostly the same) but memory accounting "faithfulness" but fair point I can give up this part.
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.
From what I can tell, it's not just about accounting, it has different semantics. The traditional MADV_FREE has to track the dirty bit to tell whether you've used the page and so can require an IPI and TLB shoot-down to make the page read-only in the map before it's actually removed. This version can reclaim the page immediately but requires a system call (which explicitly synchronises any thread that might be about to use the page) before it can be reused.
It looks like it's a good fit for snmalloc, but we do need the corresponding notify_using function in the PAL.
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.
Might be better in another PR as here it s mainly to fix some unit tests crashing whereas this is improvement.
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.
Sounds good, thanks!
The actual code works fine on the usual mac Intel however, some failures occurs with some unit tests on the ARM h/w when zero'ing page ranges.
e3c68ce to
4810079
Compare
The actual code works fine on the usual Mac Intel however, some failures
occurs with some unit tests on the ARM h/w when zero'ing page range.
While at it, using MADV_FREE_REUSABLE which is Darwin's specific but helps
command line tools to report better memory accounting.