Giter Club home page Giter Club logo

vm-allocator's People

Contributors

alexandrucihodaru avatar andreeaflorescu avatar bchalios avatar dependabot[bot] avatar dm0- avatar jiangliu avatar jonathanwoollett-light avatar roypat avatar shadowcurse avatar studychao avatar voidbuf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vm-allocator's Issues

Bug when creating `RangeInclusive` of size 1

I came across a bug which manifests when allocating with an alignment other than 0.

The problem manifests when we get a candidate range which can fit our allocation, but in order
to respect the alignment properties the allocated range starts one byte after the start of the candidate node.
In this case we try to add back an InnerNode of size 1.

This should work, but the constructor of RangeInclusive fails due to this check which is meant to check
for ranges bigger than u64::MAX + 1.

MRE:

use vm_allocator::{AddressAllocator, AllocPolicy};

fn main() {
    let mut allocator = AddressAllocator::new(1, 1000).unwrap();
    //This should return us range [2,11] 
    let addr = allocator.allocate(10, 2, AllocPolicy::FirstMatch)
    // but it will fail because internally the allocator which will try to
    // create a Node with Range [1,1] which will fail
   .unwrap();
    println!("Allocated address: {}", addr.start());
}

Above will fail with:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidRange(1, 1)', src/main.rs:9:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The Constraint methods have side effects

It is very easy to misuse the Constraint interface because it has side effects. For example, the policy MUST be set before setting the alignment because otherwise the alignment check is wrong.
The Constraint is constructed as a builder, but does not implement the full pattern, which makes it easy to misuse.

This needs to be readjusted as specified in the Rust Builder Pattern documentation: https://rust-unofficial.github.io/patterns/patterns/creational/builder.html

Use std::ops::Range instead of reimplementing the functionality

The Range object already exists in Rust. Instead of reimplementing the functionality, we can just extend such that we can add the needed functionality, which for now is just theoverlaps function.

Also, depending on how the crate is shaped, we will need to use either Range or RangeInclusive, where the latter represents a range that is inclusive on both ends:

vm-allocator requirement and usage discussion

Hi, I'm Chao ๐Ÿ˜„
I would like to initiate the discussion about the requirement and usage of vm-allocator.

The Big Picture

To start with a big picture, we think vm-allocator should be used for managing (allocating + releasing + tracking) guest resource for other components who need guest resource. vm-allocator is responsible for tracking all the resource usage and other components implements methods to access or control resources allocated from vm-allocator.

We think there are 2 main concepts needed clerification in vm-allocator design : resource and allocator

Resource

Resource should be managed by vm-allocator and let vm-allocator keep track of the resource usage.

After skimming through several VMM, resource here could be 3 kinds :

  1. ID resource. e.g. PCI device id
  2. Memory resource. e.g. MMIO, PIO address space
  3. Interrupt resource. e.g. msi irq

We should have an allocator general enough to allocate all those kinds of resource so that we don't need a new struct for every kind of resource.

Allocator

Allocator is used to manage (allocate + release + track) the resource.
Allocator itself should have a range/pool for maximum resource to be allocated.

How to ask for the resource allocation

We think there should be a constraint for other components to ask for resource from vm-allocator.

Constraint should describe the size of the resource it wants, the lower boundary it wants for the resource from the resource pool (optional), the upper boundary(optional) and the alignment(optional)

Once components could clearly describe the constraint for the resource they need, vm-allocator could find the most appropriate resource for them.

How to ask for the resource release

Other components could give the exact resource(e.g. address space range, id number) / device name/device struct to let vm-allocator know which resource to release.

How to allocate, release and track resource

Resource Allocation should follow these rules:

  1. Different allocations should not overlay with each other.
  2. Resource allocations shouldn't pass the lower and upper bound.
  3. Resource allocations should follow the description of the constraint

Resource Release will free the resource range from the resource pool and other allocation could use that range.

Recource Track means vm-allocator should have the ability to query for the resource.

Summary

As the conclusion, the vm-allocator would be made of one allocator for managing resource and constraint for describing the resource needed.

Update documentation for publishing

The public documentation should not have details about internal only structures. For example this is the case with:

/// Internal representation of IdAllocator. Contains the ends of the interval
.

We should scan all the public documentation and see what else is similar, and what we need to extend.

License clarification

I was reviewing crate licenses and encountered three issues here:

  • The allocation_engine files declare SPDX-License-Identifier: Apache-2, but the SPDX ID is Apache-2.0.
  • Both the Cargo.toml file and README says the project is dual licensed (Apache-2.0 or BSD-3-Clause), but the crate includes multiple files that are Apache-2.0-only, e.g. src/lib.rs. Should the crate license be just Apache-2.0 and maybe mention there are some dual-licensed source files in the README?
  • The BSD license text is missing. Can a file LICENSE-BSD-3-Clause be added to the crate?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.