rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | //! Fixed-size block allocator (the ACTIVE allocator).
//!
//! Every request is rounded up to one of a few block sizes (8, 16, ... 2048
//! bytes). For each size we keep a linked list of free blocks; the "next"
//! pointer is stored *inside* the free block itself, so the lists need no
//! extra memory. alloc = pop from the list, dealloc = push onto it: O(1).
//! When a list is empty, or a request is bigger than 2048 bytes, we ask the
//! fallback `linked_list_allocator::Heap`.
//! Trade-off: up to ~50% wasted space per block (e.g. 33 bytes -> 64).
use Locked;
use ;
use ;
/// Block sizes. Each is a power of two, so it can double as the alignment.
const BLOCK_SIZES: & = &;
/// Index into BLOCK_SIZES of the smallest block that fits `layout`.
/// A free block. Lives inside the free memory it describes.
// The heap lock is taken with interrupts off: code that runs with
// interrupts off (the scheduler, wait queues, ...) may allocate, and if it
// found the lock held by a thread that was preempted mid-allocation, it
// would spin forever -- that thread can't run again until interrupts are on.
unsafe
|