-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add an unsafe method that allows the user to recover the allocator from the memory. #34
base: master
Are you sure you want to change the base?
Conversation
Hello, thanks for reaching out, I'm happy to support this but I'd like to do so a little differently if possible. My main concerns are a. API usability when combined with multiple arenas. This function will cause a lot of strange behavior and then crash if someone uses the wrong Getting around all this seems doable to me, depending on your constraints. To get a feel for what solutions are viable to you:
Overall, I like the idea. In my mental model of what I'd personally like to use talc for, this has a clear use case. However I'd like to try get this to a point where it's very clear how to use this API correctly even if you're using other features of talc. Let me know what would and wouldn't work for you. Aside, I'm working on an overhaul to talc, for a bunch of reasons. Depending on how this feature is implemented, this might force that overhaul to become a separate crate. I'm not against that, but being able to carry over whatever recovery API/mechanism we decide on may be ideal regardless. Just something on my mind; it shouldn't affect what we decide here. |
@Determinant I see you've dropped a 👍 on my comment. I'm blocked on a lack of knowledge about what your intentions/constraints are, just in case it wasn't clear. If you still intend to get back to me though, no rush. |
Sorry I'm afk over the weekend and because you asked a bunch of great questions, I'd like to address them properly, so I thumbed up and very much appreciated the responsiveness! |
a/b. This is also my fear and not surprised if this PR needs more work. I feel currently I use talc in the simplest way (single arena, as in my case that suffices).
Thanks for being open on this discussion. talc is a great library to use from my perspective and it looks like the devs behind it are even better. :) I don't have any strong opinion as for how this could be eventually implemented as this is just a humble use case that we need to make it usable in our system. I'm happy to try persisting/laying out the Talc struct directly to see if that works. Previously my fear is about the guarantee (static size, etc.) but if that part is in good care, I actually prefer this solution. |
Cool. Talc has a few practical limitations that mean saving the bytes should be fine if you know what OomHandler is being used:
So unless the OomHandler holds OS resource handles or something like that, it should be fine. The Here's my thinking when it comes to OomHandlers:
And I don't think forcing all OomHandler implementation to be session-independent is a great idea.
(I'm much more against this idea now, because it means Talc needs to force all OomHandlers to permit this.) However, I also feel like making people maintain their own versions of pre-made OomHandlers just because I (or another contributor) might break something is not ideal... And we'd need to guarantee Talc's (OomHandler-dependent) session-independence anyway. (I'm happy to commit to that indefinitely, I think. Talc itself is supposed to be very independent. No std, no OS, no platform dependency, etc. I see no reason why Talc should couple itself with session-lifetime state.) Ensuring WasmHandler is permanently session-independent is another matter though. I'm nervous about
One thing I'm thinking about it making a type alias I've still got some fuzzy lingering concerns... I want to think about this more, but not tonight. I've got a few alternative ideas but none of them seem significantly better... Ah well. I'll keep thinking about it and get back to you. |
I'm a bit swamped at the moment. Feel free to copy the talc bytes and transmute it back for now. It will (should) work. I'm currently planning to document the properties that allow for this and test it. There might be a few API changes, but nothing that will be procedurally distinct from getting some data T. That must be used to re-instate it. (Same as transmuting bytes.) I'll leave this issue open and get back to you if there are any changes to make once I commit to something, but in the meantime I'll look after the correctness of transmuting the bytes. Everything will be in the Talc struct or the Talc heap(s). I'd like to avoid committing to anything until V5 is done, though I plan to keep this feature a possibility on WebAssembly without any major procedural differences to save the state of Talc. (If all goes to plan, I'll make it easier to make this guarantee.) |
I went through the detailed thoughts and have a better idea of what's tricky in this case. Fortunately, for our current use case, OOM handler is not an issue because we tend to use a very simple one that's pretty independent (currently, just error because we initially already give abundant memory space to Talc so if the user goes beyond that, it should be an error in our case anyway). As one step further, I'm putting Talc to a special reserved portion of the persistent memory, so in this case, it requires even less promise as for its byte encoding. Appreciate the help and effort! |
Hi team, we're a startup working on a platform which relies on a software-defined persistent (non-volatile) memory. So that means a program (in our case a piece of WASM code) always has its memory persisted. Talc currently is a perfect fit because it is lightweight and can help us manage the allocation for these "magical" variables. But in order to get this to work, we added a method called
recover_from_existing_heap
that reconstructs the state of Talc based on the same span of the memory it previously worked on.We feel this could be an interesting and general feature to talc, especially for the non-volatile memory use case. Would like to see if you're interested in merging the code.