| Crates.io | mielin-kernel |
| lib.rs | mielin-kernel |
| version | 0.1.0-rc.1 |
| created_at | 2026-01-18 01:48:30.349665+00 |
| updated_at | 2026-01-18 01:48:30.349665+00 |
| description | Core unikernel implementation providing the foundation for agent execution across heterogeneous hardware platforms |
| homepage | |
| repository | https://github.com/cool-japan/mielin |
| max_upload_size | |
| id | 2051570 |
| size | 809,427 |
The Myelin Sheath - Core Unikernel (Layer 1)
A lightweight no_std unikernel providing the foundation for autonomous agent execution across heterogeneous hardware platforms—from microcontrollers to cloud servers.
The MielinOS kernel is a minimalist unikernel designed for extreme efficiency and portability. It eliminates traditional kernel-space/user-space boundaries, operating in a single memory address space to provide essential OS services (memory management, task scheduling, tensor awareness) without the overhead of traditional operating systems.
Current Status: v0.1.0-rc.1 "Oligodendrocyte" (Released 2026-01-18)
no_std Environment: Runs on bare metal without standard library dependenciesMielinOS kernel provides Layer 1 of the 5-layer neural architecture:
┌─────────────────────────────────────────────────────────────┐
│ Layer 1: MielinOS Core (The Myelin Sheath) │
│ • Memory Manager (Page-based allocator) │
│ • Task Scheduler (Async cooperative) │
│ • TensorLogic (AI-aware scheduling) │
│ • Syscall Interface (Capability-based) │
└─────────────────────────────────────────────────────────────┘
mielin-kernel/
├── src/
│ ├── boot.rs # Boot sequence initialization
│ ├── memory.rs # Page-based memory allocator
│ ├── scheduler.rs # Cooperative task scheduler
│ ├── tensor.rs # TensorLogic context management
│ └── lib.rs # Kernel entry points and error types
└── Cargo.toml
Manages physical memory using a page-based allocation scheme optimized for agent migration.
use mielin_kernel::memory;
// Initialize memory subsystem
memory::init()?;
// Allocate a 4KB page
let page_addr = memory::allocate_page().expect("Out of memory");
// Free the page when done
memory::free_page(page_addr)?;
Characteristics:
Priority-based cooperative scheduler for concurrent agent execution with async/await support.
use mielin_kernel::scheduler;
// Initialize scheduler
scheduler::init()?;
// Spawn a task with priority 10
let task_id = scheduler::spawn_task(10)?;
// Schedule next task (returns task index)
let next_task = scheduler::schedule();
// Yield current task back to ready queue
scheduler::yield_current();
Characteristics:
Kernel-level tensor operation management for AI workloads, enabling intelligent resource allocation.
use mielin_kernel::tensor::TensorContext;
// Create tensor context with memory budget
let ctx = TensorContext::new(1024 * 1024); // 1MB budget
// Context provides:
// - Memory allocation tracking for tensor ops
// - Resource limits enforcement
// - Priority scheduling hints
Features:
Install required tools:
# Install Rust nightly (required for bootimage)
rustup default nightly
# Install bootimage tool
cargo install bootimage
# Install QEMU (for x86_64)
# Ubuntu/Debian:
sudo apt install qemu-system-x86
# macOS:
brew install qemu
# Windows:
# Download from https://www.qemu.org/download/
Run MielinOS in QEMU:
# From project root
./scripts/run-qemu.sh
Or with graphical display:
./scripts/run-qemu-gui.sh
# Build the bootable kernel image
cargo bootimage --target x86_64-unknown-none
# Run in QEMU
qemu-system-x86_64 -drive format=raw,file=target/x86_64-unknown-none/debug/bootimage-mielin-kernel.bin
Ctrl+A then X (in terminal mode)Ctrl+A then CCtrl+A then SRun with GDB support:
# Terminal 1: Start QEMU with GDB server
qemu-system-x86_64 \
-drive format=raw,file=target/x86_64-unknown-none/debug/bootimage-mielin-kernel.bin \
-s -S
# Terminal 2: Connect GDB
gdb target/x86_64-unknown-none/debug/mielin-kernel
(gdb) target remote :1234
(gdb) continue
View serial output:
qemu-system-x86_64 \
-drive format=raw,file=target/x86_64-unknown-none/debug/bootimage-mielin-kernel.bin \
-serial mon:stdio
Add to your Cargo.toml:
[dependencies]
mielin-kernel = { path = "../mielin-kernel" }
#![no_std]
#![no_main]
use bootloader::{BootInfo, entry_point};
use mielin_kernel;
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! {
// Initialize kernel subsystems
if let Err(e) = mielin_kernel::kernel_init(boot_info) {
panic!("Kernel init failed: {:?}", e);
}
// Your application code here
loop {
// Main event loop
// Agents execute here
}
}
The kernel can be configured at compile time:
// In memory.rs
const PAGE_SIZE: usize = 4096; // Page size in bytes
const MAX_PAGES: usize = 1024; // Maximum allocatable pages (4MB)
// In scheduler.rs
const MAX_TASKS: usize = 64; // Maximum concurrent tasks
All kernel operations return Result<T, KernelError>:
pub enum KernelError {
MemoryInitFailed, // Memory subsystem init failed
SchedulerInitFailed, // Scheduler init failed
HardwareNotSupported, // Unsupported hardware platform
OutOfMemory, // No free pages available
InvalidTask, // Task ID invalid
}
Run the comprehensive test suite:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_memory_allocation
Test Coverage:
Benchmarks on x86_64 (3.5 GHz):
| Operation | Time | Notes |
|---|---|---|
| Page allocation | ~50 ns | Worst case O(n) bitmap scan |
| Page deallocation | ~10 ns | O(1) bitmap clear |
| Task spawn | ~100 ns | Includes state setup |
| Task switch | ~80 ns | Cooperative yield |
| TensorContext creation | ~20 ns | Lightweight struct |
Target metrics for v1.0:
The kernel uses unsafe code for:
Safety guarantees:
#![allow(static_mut_refs)] used for necessary global stateCurrent limitations (intentional design choices):
These constraints enable:
See TODO.md for detailed roadmap.
kernel_init() before any other operationsKernelError properlySee CONTRIBUTING.md for guidelines.
Key areas for contribution:
Licensed under either of:
at your option.
MielinOS Kernel - The myelin sheath that enables saltatory conduction of AI agents across the computational nervous system 🧠⚡
Current Version: v0.1.0-rc.1 "Oligodendrocyte" | Released 2026-01-18