Coder Social home page Coder Social logo

Use lock-free heap allocator about theseus HOT 4 OPEN

theseus-os avatar theseus-os commented on May 18, 2024
Use lock-free heap allocator

from theseus.

Comments (4)

kevinaboos avatar kevinaboos commented on May 18, 2024 3

Instead of a lock-free allocator, which is likely impossible, I think a better solution is to use a separate allocator for allocations that occur in interrupt contexts. This is now possible with Rust's new allocator_api feature that allows you to allocate something using a specific allocator rather than just the global default.
rust-lang/rust#32838

For example, we can use Box::new_in(object, InterruptSafeAllocator) instead of just Box::new(obj). See this: https://doc.rust-lang.org/alloc/boxed/struct.Box.html#method.new_in

from theseus.

kevinaboos avatar kevinaboos commented on May 18, 2024

another allocator here: https://github.com/gz/rust-slabmalloc

from theseus.

kevinaboos avatar kevinaboos commented on May 18, 2024

https://crates.io/crates/buddy_system_allocator

from theseus.

amab8901 avatar amab8901 commented on May 18, 2024

Instead of a lock-free allocator, which is likely impossible,

why is lock-free allocator likely impossible?

Heap allocations are horribly expensive right now because the Heap acquires an Irq-safe Mutex lock, which disables interrupts for the duration of a heap allocation.

The root issue we're trying to solve is to make the heap allocations use resources more efficiently. Can we break down the resource usage of the heap allocations into all the different cases/categories? Perhaps doing so may help us identify bottlenecks

IRQ safety (disabling interrupts) exists for a reason: it prevent race conditions in case two interrupt handlers try to access the same resource. This kind of memory safety is one of the main reasons we're introducing TheseusOS as a better alternative to OS:es based on C/C++. Ideally, we should identify when the interrupt disabling is needed and when it's not needed. That way, we can apply the interrupt disabling in cases where it's needed to prevent race conditions, while avoiding unnecessary resource waste outside of those cases (the number of interrupt handlers able to access CPU can be viewed as a resource).

The key question we need to answer is:

  • When does IRQ-unsafe heap allocation risk race conditions?

from theseus.

Related Issues (20)

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.