rickyyx / ParNVM

NVM research project @MSRA
0 stars 1 forks source link

Customized allocator for containers #7

Open rickyyx opened 6 years ago

rickyyx commented 6 years ago

Customized allocator for standard collections This will be a rather exciting feature for us if it can land.

Use case

A std lib's data structure can then obtain a memory pointer from the persistent memory allocator directly, For example, a Persistent Box PBox can be a wrapper over Box<T, A=PersistentAlloc> This will make the library much more coherent with the standard library. In addition,PBox will have interface that allows controlled persistence methods: such as flush and persist, or even log.

pub struct PBox<T> {
   type PAlloc = PersistentAllocator 
   box_ : Box<T, PAlloc> 
}

impl<T> PBox<T> {
        pub fn persist(&self){};

        pub fn flush(&self){};
}

Even better with GAT #3 feature, transaction can be generics as well.

pub trait PWrapper {
    type Inner<T, A>
    fn persist(&self);
    fn flush(&self);
    fn log(&self); 
    ....
}

pub struct PBox {}

impl PWrapper for PBox {
   type Inner<T,A> = Box<T, A> 
   ...
}

Tracking issue

rickyyx commented 6 years ago

Alternative AVAILABLE option:

🤙 [global_allocator] attribute

Another possible option which is to the `global_allocator' to have a persistent memory allocator altogether: https://doc.rust-lang.org/1.23.0/unstable-book/language-features/global-allocator.html

Potential Drawbacks:

  1. Only one global_allocator in the whole crate graph
  2. All memory must go through the persistent memory.

🤙 Wrap over a chunk

This is currently what the TBox did. it gets a pointer from the persistent memory allocator, and copys the data to the pointer.

Potential Drawbacks:

  1. This doesn't work with more complicated data structures that have pointer indirection, like hashmap because it does not allocate memory as chunk, but is a container over a RawTable in rust. In order to make the keys and values of the map persistent, need to be able to control the memory allocation of RawTable. (Which is not exposed by Rust...)