Support fallible malloc attempts without OOM handling#43
Support fallible malloc attempts without OOM handling#43hcsch wants to merge 2 commits intoSFBdragon:masterfrom
Conversation
Hash all empty spans to the same value to align with the `PartialEq` implementation. The derived `Hash` was causing clippy to throw an error. See https://rust-lang.github.io/rust-clippy/master/index.html#derived_hash_with_manual_eq
|
Hey, thanks for the PR!
Both of these changes seem good to me. I'll likely merge them soon and port them forward to the next relelase I've been working on.
I was wondering: instead of scanning for decreasing powers of two, it's possible for Talc to quickly find it's largest available chunk and allocate it. There just isn't an API or implementation for it, but it could be easily added. Though Talc can reject requests for sizes considerably larger than it has very quickly (handful of instructions... iirc, been a while since I worked on V4).
Would this fit your needs better?
…-------- Original Message --------
On 2025/08/27 20:50, Hans Christian Schmitz wrote:
When allocating with Talc for a balloon device allocations should be
multiples of 4KiB in size and must be aligned to 4KiB.
To reduce per-allocation overhead we want to group such allocations as
much as possible into large chunks.
Allocation of such almost as large as possible chunks below a maximum size
can be accomplished by attempting allocations in decreasing powers of
two below the maximum size.
These allocation attempts would however trigger the OOM handler which is
undesirable. The balloon driver is also responsible for OOM handling in
my case and since we are already within balloon driver code, making
these allocation attempts, the driver is already locked. The OOM handler
therefore cannot (and should not) deflate the balloon, because the
driver state is locked.
Thus we want to be able to make allocation attempts without triggering
the OOM handler.
This includes a drive-by fix for the derived Hash impl conflicting with the explicit PartialEq implementation of Span. They differed on equality for empty Spans AFAICT.
---------------------------------------------------------------
You can view, comment on, or merge this pull request online at:
#43
Commit Summary
- [b3c0312](b3c0312) Fix derived `Hash` for type with custom `PartialEq`
- [df18c6c](df18c6c) Support fallible malloc attempts without OOM handling
File Changes
([2 files](https://github.com/SFBdragon/talc/pull/43/files))
- M [talc/src/span.rs](https://github.com/SFBdragon/talc/pull/43/files#diff-6cbdd489cd12405390eb955c5f2ba0f924858eebc2fe663a0286978f4752a4dc) (23)
- M [talc/src/talc.rs](https://github.com/SFBdragon/talc/pull/43/files#diff-2473adf2aa35ff5879a705f9508f930e4b1d1b0c225400b8702ef419ffcd1ac4) (30)
Patch Links:
- https://github.com/SFBdragon/talc/pull/43.patch
- https://github.com/SFBdragon/talc/pull/43.diff
—
Reply to this email directly, [view it on GitHub](#43), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/ALAPHRZL5CA4YQO7PP5MS233PX4Y3AVCNFSM6AAAAACE7CUSOSVHI2DSMVQWIX3LMV43ASLTON2WKOZTGM3DANJQG42DQNY).
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
|
Hey, thanks for the positive response :D Being able to query Talc for the largest still possible contiguous allocation would be great as well, and IMO even feels a bit cleaner. I wrote this change to Talc in the process of my bachelor's thesis so I was a bit limited in time for delving into how talc does things, which is why I picked the current approach. |
When allocating with Talc for a balloon device allocations should be multiples of 4KiB in size and must be aligned to 4KiB. To reduce per-allocation overhead we want to group such allocations as much as possible into large chunks. Allocation of such almost as large as possible chunks below a maximum size can be accomplished by attempting allocations in decreasing powers of two below the maximum size. These allocation attempts would however trigger the OOM handler which is undesirable. The balloon driver is also responsible for OOM handling in my case and since we are already within balloon driver code, making these allocation attempts, the driver is already locked. The OOM handler therefore cannot (and should not) deflate the balloon, because the driver state is locked. Thus we want to be able to make allocation attempts without triggering the OOM handler.
df18c6c to
be81838
Compare
|
Just noticed that I still had the old |
Talc previously did not support allocations without attempting to use the OOM handler to recover. For the balloon device to allocate pages for the balloon however we want to just probe for and then allocate a chunk of pages. If the allocation fails we don't want to recover old memory, we just want to allocate a smaller chunk (since recovery with the balloon will be shrinking the balloon, causing us to uselessly shuffle around pages, possibly even failing). See SFBdragon/talc#43 which is the PR for merging this modification upstream. Another API function may be added for querying the current largest possible new allocation in the future. In that case the balloon driver code should be changed to use that instead of probing allocatable size in powers of two.
|
I haven't implemented a function to get one/iterate available chunk sizes from the top down though yet. Should be easy to implement, and I'm happy to do it if it's still desirable. Leaving this open for now. |
When allocating with Talc for a balloon device allocations should be
multiples of 4KiB in size and must be aligned to 4KiB.
To reduce per-allocation overhead we want to group such allocations as
much as possible into large chunks.
Allocation of such almost as large as possible chunks below a maximum size
can be accomplished by attempting allocations in decreasing powers of
two below the maximum size.
These allocation attempts would however trigger the OOM handler which is
undesirable. The balloon driver is also responsible for OOM handling in
my case and since we are already within balloon driver code, making
these allocation attempts, the driver is already locked. The OOM handler
therefore cannot (and should not) deflate the balloon, because the
driver state is locked.
Thus we want to be able to make allocation attempts without triggering
the OOM handler.
This includes a drive-by fix for the derived
Hashimpl conflicting with the explicitPartialEqimplementation ofSpan. They differed on equality for emptySpans AFAICT.