-
Notifications
You must be signed in to change notification settings - Fork 404
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
Clean fallback from memory management errors #188
Comments
Is there any reasonable clean fallback we can take if this happens? So many os host conbos. Is it a legit concern? |
@baconpaul: I think it is important just to recognize the problem at this point. Not something that there is a "quick fix". Changing |
Ooh malloc and new are different on purpose. I guess my view is “if you are out of memory you will crash”. That’s not ok in the kernel but in Logic Pro i don’t think there’s anything smart a plug-in can do! |
Can you point me to a call site where the use of |
When you deal with memory errors, it will make you to do more well informed choices by other angels too when you write new code (like dealing with other types of errors). And it gives a good baseline to scale this project down towards smaller devices. And it is a bug class and I just don't see how it could be OK just let a bug class let be in the code base. Easy to way start would be to get rid of mallocs. And maybe GUI could have a top level hander to show a dialog when |
Not from my phone! But I haven’t read all the dsp code and there’s lots of stuff in there with memory and alignment which seems purposeful so I think a swap would require a very careful understanding of the code which I don’t have. |
Also I never quite understood what to put in the block If( ! Malloc ) or similarly what to do in a std bad alloc handler which would improve the users experience reliably But I’m not that bothered by it! Just trying to make sure we are super careful making changes |
@baconpaul, at least consistent behavior would be nice at this point i.e. have an exception thrown. Then the plugin always exists cleanly, never crashes. We would close this issue with that. I can make more localized proposals but that would be good step to take with its own set commits. Even using the default handler for There is nothing special in the DSP code that is connected to the use of |
Ok cool! Appreciate the thoughtfulness. And happy new year. |
@baconpaul, happy new year to you too :) |
I will fix this and #171 with the same PR. |
When the fallback path is an exception and not a random crash, it will also improve the debugging experience. You can run gdb and do something like |
@baconpaul, yeah, and I like this surprising amount of diversity among people who work on this :) Have to from time to time reconsider how I view some problems. Kind of good form of distraction. |
Almost untested WiP code https://github.com/jsakkine/surge/tree/malloc. This will be also pull branch for #171. |
So it seems _aligned_malloc( -, 16 ) Does something different than new. Namely it aligns on 16 byte boundaries which is required for sse. I’m not an expert here but did I miss where we decided it was a noop change? On windows it seems it will change behavior but I could have missed the convo where we deciddd it didn’t |
Commented the other issue. Point is that using the new-operator already gives always clean exit whereas malloc() without error check causes random crash if it fails. With an overloaded new operator we could possibly even spawn an error dialog inside the new operator. |
@baconpaul, @kurasu: updated the description. Closing the other issue. Doesn't that look like a plan for this issue? |
@baconpaul: I think that you can take design required tag away. It does not solve everything related to mm but I think it is enough for the scope of one issue. After implementing that we have more clean platform to make more detailed choices on memory management. |
Visual Studio 15.5 is fairly old: https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.5. I think it should be safe to just take this feature into use with the compilation flags described above. |
Removed that tag. When I put it on, design was required! Now it seems the design is in place; namely tag everything with alignas() and test. (The reason to test, of course, isn't to make sure it is aligned; it is to make sure we don't miss any classes getting the alignas() flag). |
Every possible Linux distribution uses at least GCC 7.3 because it is the oldest GCC version carrying retpoline support, which is a feature providing Spectre mitigation. If we ever need to do larger alignments in future than 16-bytes, we can then add -faligned-new for Linux and macOS targets without major concerns. |
Did a sanity check that this actually gets inherited to sub-classes:
When I run this:
Looks good. |
Great, the approach works. Now it is only just matter of using the same pattern to the rest of the allocations. |
Extending a scope of this issue a bit. With user interaction functions we can implement an error message when running out of memory (catch |
The remaining uses of aligned_malloc():
For SurgeVoice, I have a pending PR #333. It works on every other DAW I've tried except both Windows and macOS versions of Bitwig Studio. @baconpaul has provided a screenshot showing the error. @kurasu, we have absolutely zero idea what could be the cause and effect on this one. Since you know Bitwig internals better than us, does anything come to mind that could somehow connect to this? |
We can close this after doing this also in "init" of VST3 and AU:
|
I could work on equivalent infrastructure for VST3 that I've done for VST2 after I've finished with the Linux resource manager. |
I think it is good enough for the time being now. We can do smaller scale issues when we actually want to start doing something for some useful reasons. |
Problem
Currently we need to use
_aligned_alloc()
together with thenew
-operator in order to allocate 16-byte aligned memory for use with the SSE2 instructions. For Linux and macOS this function is substituted tomalloc()
, which is always gives 16-byte aligned on these platforms.It'd be better to use the
new
-operator for all allocations because this will causestd::bad_alloc
to be thrown when allocations fail, which means that we always get a clean exit instead ofcrashing with a null pointer dereference.
Solution
C++17 provides language level support for allocations for over-aligned data [1].
Example program:
If I compile with
-faligned-new
:Compiler support:
/Zc:alignedNew
). Not sure how recent this is.[1] https://www.bfilipek.com/2017/06/cpp17-details-clarifications.html#dynamic-memory-allocation-for-over-aligned-data
[2] https://www.gnu.org/software/gcc/projects/cxx-status.html
[3] https://clang.llvm.org/cxx_status.html
[4] https://docs.microsoft.com/en-us/cpp/build/reference/zc-alignednew?view=vs-2017
The text was updated successfully, but these errors were encountered: