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
Allocator traits and std::heap #32838
Comments
|
I unfortunately wasn't paying close enough attention to mention this in the RFC discussion, but I think that
Note that these can be added backwards-compatibly next to For consistency, |
|
Additionally, I think that the default implementations of This makes it easier to produce a high-performance implementation of |
…sakis `#[may_dangle]` attribute `#[may_dangle]` attribute Second step of rust-lang#34761. Last big hurdle before we can work in earnest towards Allocator integration (rust-lang#32838) Note: I am not clear if this is *also* a syntax-breaking change that needs to be part of a breaking-batch.
…sakis `#[may_dangle]` attribute `#[may_dangle]` attribute Second step of rust-lang#34761. Last big hurdle before we can work in earnest towards Allocator integration (rust-lang#32838) Note: I am not clear if this is *also* a syntax-breaking change that needs to be part of a breaking-batch.
…sakis `#[may_dangle]` attribute `#[may_dangle]` attribute Second step of rust-lang#34761. Last big hurdle before we can work in earnest towards Allocator integration (rust-lang#32838) Note: I am not clear if this is *also* a syntax-breaking change that needs to be part of a breaking-batch.
|
Another issue: The doc for To me this implies that it must check that the alignment of the given address matches any constraint implied by However, I don't think the spec for the underlying
So, should the implementation of |
|
@gereeter you make good points; I will add them to the check list I am accumulating in the issue description. |
|
(at this point I am waiting for |
|
I'm new to Rust, so forgive me if this has been discussed elsewhere. Is there any thought on how to support object-specific allocators? Some allocators such as slab allocators and magazine allocators are bound to a particular type, and do the work of constructing new objects, caching constructed objects which have been "freed" (rather than actually dropping them), returning already-constructed cached objects, and dropping objects before freeing the underlying memory to an underlying allocator when required. Currently, this proposal doesn't include anything along the lines of Where would an object allocator type or trait fit into this proposal? Would it be left for a future RFC? Something else? |
|
I don't think this has been discussed yet. You could write your own Future work would be modifying collections to use your trait for their nodes, instead of plain ole' (generic) allocators directly. |
I guess this has happened? |
|
@Ericson2314 Yeah, writing my own is definitely an option for experimental purposes, but I think there'd be much more benefit to it being standardized in terms of interoperability (for example, I plan on also implementing a slab allocator, but it would be nice if a third-party user of my code could use somebody else's slab allocator with my magazine caching layer). My question is simply whether an |
Yes, it would be another RFC.
that depends on the scope of the RFC itself, which is decided by the person who writes it, and then feedback is given by everyone. But really, as this is a tracking issue for this already-accepted RFC, thinking about extensions and design changes isn't really for this thread; you should open a new one over on the RFCs repo. |
|
@joshlf Ah, I thought @steveklabnik yeah now discussion would be better elsewhere. But @joshlf was also raising the issue lest it expose a hitherto unforeseen flaw in the accepted but unimplemented API design. In that sense it matches the earlier posts in this thread. |
|
@Ericson2314 Yeah, I thought that was what you meant. I think we're on the same page :) @steveklabnik Sounds good; I'll poke around with my own implementation and submit an RFC if it ends up seeming like a good idea. |
|
@joshlf I don't any reason why custom allocators would go into the compiler or standard library. Once this RFC lands, you could easily publish your own crate that does an arbitrary sort of allocation (even a fully-fledged allocator like jemalloc could be custom-implemented!). |
|
@alexreg This isn't about a particular custom allocator, but rather a trait that specifies the type of all allocators which are parametric on a particular type. So just like RFC 1398 defines a trait ( |
|
@alexreg See my early point about using standard library collections with custom object-specific allocators. |
|
Sure, but I’m not sure that would belong in the standard library. Could easily go into another crate, with no loss of functionality or usability.
… On 4 Jan 2017, at 21:59, Joshua Liebow-Feeser ***@***.***> wrote:
@alexreg <https://github.com/alexreg> This isn't about a particular custom allocator, but rather a trait that specifies the type of all allocators which are parametric on a particular type. So just like RFC 1398 defines a trait (Allocator) that is the type of any low-level allocator, I'm asking about a trait (ObjectAllocator<T>) that is the type of any allocator which can allocate/deallocate and construct/drop objects of type T.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#32838 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAEF3IhyyPhFgu1EGHr_GM_Evsr0SRzIks5rPBZGgaJpZM4IDYUN>.
|
|
I think you’d want to use standard-library collections (any heap-allocated value) with an *arbitrary* custom allocator; i.e. not limited to object-specific ones.
… On 4 Jan 2017, at 22:01, John Ericson ***@***.***> wrote:
@alexreg <https://github.com/alexreg> See my early point about using standard library collections with custom object-specific allocators.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#32838 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAEF3CrjYIXqcv8Aqvb4VTyPcajJozICks5rPBbOgaJpZM4IDYUN>.
|
Yes but you probably want some standard library functionality to rely on it (such as what @Ericson2314 suggested).
Ideally you'd want both - to accept either type of allocator. There are very significant benefits to using object-specific caching; for example, both slab allocation and magazine caching give very significant performance benefits - take a look at the papers I linked to above if you're curious. |
|
But the object allocator trait could simply be a subtrait of the general allocator trait. It’s as simple as that, as far as I’m concerned. Sure, certain types of allocators can be more efficient than general-purpose allocators, but neither the compiler nor the standard really need to (or indeed should) know about this.
… On 4 Jan 2017, at 22:13, Joshua Liebow-Feeser ***@***.***> wrote:
Sure, but I’m not sure that would belong in the standard library. Could easily go into another crate, with no loss of functionality or usability.
Yes but you probably want some standard library functionality to rely on it (such as what @Ericson2314 <https://github.com/Ericson2314> suggested).
I think you’d want to use standard-library collections (any heap-allocated value) with an arbitrary custom allocator; i.e. not limited to object-specific ones.
Ideally you'd want both - to accept either type of allocator. There are very significant benefits to using object-specific caching; for example, both slab allocation and magazine caching give very significant performance benefits - take a look at the papers I linked to above if you're curious.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#32838 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAEF3L9F9r_0T5evOtt7Es92vw6gBxR9ks5rPBl9gaJpZM4IDYUN>.
|
Ah, so the problem is that the semantics are different. This is not compatible with |
|
Figured I would put this in here. I ran into a compiler bug when using the allocator_api feature with Box: #90911 |
…llocator-api-in-tuple, r=davidtwco Suggestion to wrap inner types using 'allocator_api' in tuple This PR provides a suggestion to wrap the inner types in tuple when being along with 'allocator_api'. Closes rust-lang#83250 ```rust fn main() { let _vec: Vec<u8, _> = vec![]; //~ ERROR use of unstable library feature 'allocator_api' } ``` ```diff error[E0658]: use of unstable library feature 'allocator_api' --> $DIR/suggest-vec-allocator-api.rs:2:23 | LL | let _vec: Vec<u8, _> = vec![]; - | ^ + | ----^ + | | + | help: consider wrapping the inner types in tuple: `(u8, _)` | = note: see issue rust-lang#32838 <rust-lang#32838> for more information = help: add `#![feature(allocator_api)]` to the crate attributes to enable ```
In fact this feature is littered with ICEs. That's because it fits quite badly with MIR and the MIR-consuming parts of the compiler -- codegen, Miri all need to do lots of special-casing for |
|
|
|
I have a lot of concerns about the current API -- t's not a good fit for existing allocators leading to perf losses, and it's story is quite poor when used with dynamic dispatch (a common use case for allocators). It's a bit surprising that this apparently has finished FCP with merge disposition, but IMO there's more than just the issue around |
|
I'd also prefer if we had at least a solid plan for how to properly solve the problems arising from Box being both a primitive type (for purposes like noalias and align attributes) and having arbitrary user-defined data inside it. It looks like for now the ICE wack-a-mole slowed down but architecturally in the compiler it is still somewhat messy.
Things did get a lot better since my previous message thanks to the new "derefer" MIR pass, but there are a bunch of remaining rough edges.
|
|
I'd also chime in that there was, fairly recently, discussion on zulip about a storages proposal. Stabilizing the current API would likely render implementing such a proposal in a backwards-compatible way impossible. I personally would like to at least have time for such a proposal to be made and decided on before stabilizing allocators as-is |
|
the FCP labels should probably be removed since they appear to be out of date |
The remainder of this post is no longer an accurate summary of the current state; see that dedicated working group instead.
Old content
Original Post:
FCP proposal: #32838 (comment)
FCP checkboxes: #32838 (comment)
Tracking issue for rust-lang/rfcs#1398 and the
std::heapmodule.struct Layout,trait Allocator, and default implementations inalloccrate (Allocator integration #42313)alloccrate, butLayout/Allocatorcould be inlibcore...) (Allocator integration #42313)Layoutfor overflow errors, (potentially switching to overflowing_add and overflowing_mul as necessary).realloc_in_placeshould be replaced withgrow_in_placeandshrink_in_place(comment) (Allocator integration #42313)fn dealloc. (See discussion on allocator rfc and global allocator rfc and traitAllocPR.)alignthat you allocate with? Concerns have been raised that allocators like jemalloc don't require this, and it's difficult to envision an allocator that does require this. (more discussion). @ruuda and @rkruppe look like they've got the most thoughts so far on this.AllocErrbeErrorinstead? (comment)usable_sizebusiness we may wish to allow, for example, that you if you allocate with(size, align)you must deallocate with a size somewhere in the range ofsize...usable_size(size, align). It appears that jemalloc is totally ok with this (doesn't require you to deallocate with a precisesizeyou allocate with) and this would also allowVecto naturally take advantage of the excess capacity jemalloc gives it when it does an allocation. (although actually doing this is also somewhat orthogonal to this decision, we're just empoweringVec). So far @gankro has most of the thoughts on this. (@alexcrichton believes this was settled in Allocator integration #42313 due to the definition of "fits")alloc_systemis buggy on huge alignments (e.g. an align of1 << 32) if huge requested align, alloc_system heap::allocate on OS X returns unaligned values #30170 Add precondition toLayoutthat thealignfit in a u32. #43217Layoutprovide afn stride(&self)method? (See also Separate size and stride for types rfcs#1397, Collapse trailing padding #17027 )Allocator::ownsas a method? Alloc: Add owns method #44302State of
std::heapafter #42313:The text was updated successfully, but these errors were encountered: