Skip to content

About

SLM Kernel - Small Language Model Enabled Linux Kernel

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

SLM Kernel - Small Language Model Enabled Linux Kernel

Version: 1.0
License: GPL v2
Status: Experimental


Overview

SLM Kernel is a production-ready architecture that integrates a Small Language Model (SLM) directly into a custom Linux Kernel ecosystem to perform real-time autonomic system management.

Key Features

  • Real-time Detection - Identify kernel-level errors (MCEs, OOM kills, I/O bottlenecks) with sub-millisecond latency
  • Intelligent Analysis - Use ML inference with sub-10ms latency for root-cause analysis
  • Safe Remediation - Execute autonomous actions through a deterministic guardrail mechanism
  • Zero Interference - Ensure SLM workload never impacts standard system operations

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                         LINUX KERNEL STACK                          │
├─────────────────────────────────────────────────────────────────────┤
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────────────┐   |
│  │  Tracepoints │  │   eBPF       │  │   k_slm_bridge Module    │   |
│  │  (MCE, OOM)  │──│  Programs    │──│  (Ring Buffer Producer)  │   |
│  └──────────────┘  └──────────────┘  └────────────┬─────────────┘   │
│                                                    │                │ 
│  ┌────────────────────────────────────────────────▼───────────────┐ │
│  │          BPF_MAP_TYPE_RINGBUF (Zero-copy IPC)                  │ │
│  └────────────────────────────────────────────────┬───────────────┘ │
└───────────────────────────────────────────────────┼─────────────────┘
                                                    │
┌──────────────────────────────────────────────────▼─────────────────┐
│                         USER SPACE                                 │
├────────────────────────────────────────────────────────────────────┤
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────────────────┐  │
│  │    slmd      │  │  Guardrail   │  │     SLM Inference        │  │
│  │   Daemon     │──│   Layer      │──│  (llama.cpp / ONNX RT)   │  │
│  └──────────────┘  └──────────────┘  └──────────────────────────┘  │
└────────────────────────────────────────────────────────────────────┘

Components

Component Description Location
k_slm_bridge Kernel module for telemetry ingestion & IPC kernel_module/
slm-ebpf-telemetry eBPF programs for tracepoint hooking ebpf/
slmd User-space daemon for inference & remediation daemon/
slm-guardrail Deterministic output validation layer daemon/
slm_model Quantized SLM weights (INT4, <3B params) models/

Quick Start

Prerequisites

  • Linux kernel 5.8+ (for BPF ringbuf support)
  • clang >= 10.0 with BPF support
  • Python 3.8+
  • 4+ CPU cores for SLM isolation
  • 4+ GB RAM for model

Build & Install

# 1. Build kernel modules
cd kernel_module
make KDIR=/lib/modules/$(uname -r)/build
sudo make KDIR=/lib/modules/$(uname -r)/build modules_install

# 2. Load kernel modules
sudo insmod k_slm_bridge.ko
sudo insmod k_slm_reserve.ko

# 3. Build eBPF programs
cd ../ebpf
make
sudo make load

# 4. Setup CPU isolation
sudo ../config/setup_slm_cpuset.sh --setup

# 5. Install Python dependencies
cd ../daemon
pip3 install -r requirements.txt

# 6. Run daemon
sudo python3 slmd.py --verbose

Systemd Service

sudo cp config/slmd.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable slmd
sudo systemctl start slmd

Configuration

CPU Isolation

The SLM daemon requires dedicated CPU cores for inference. Configure with:

sudo ./config/setup_slm_cpuset.sh --setup

Default: CPU 8-15

Memory Locking

SLM model weights must never be swapped. The daemon locks memory automatically:

ulimit -l unlimited

Safe Sysctl Settings

Apply recommended sysctl settings:

sudo cp config/sysctl-safe.conf /etc/sysctl.d/99-slm-safe.conf
sudo sysctl --system

Usage

Command Line Options

slmd.py [-h] [--model MODEL] [--device {cpu,cuda,metal}]
         [--cpus CPU [CPU ...]] [--max-latency MAX_LATENCY]
         [--dry-run] [--verbose]

Examples

# Run with default settings (mock inference)
sudo python3 slmd.py --verbose

# Run with real model
sudo python3 slmd.py \
    --model /var/lib/slm/models/phi-3-mini-q4.gguf \
    --cpus 8 9 10 11 \
    --verbose

# Dry run (simulate actions without executing)
sudo python3 slmd.py --dry-run --verbose

Testing

Run Tests

cd tests
python3 -m pytest test_guardrail.py -v
python3 -m pytest test_ooda.py -v
python3 -m pytest test_integration.py -v

Integration Tests

python3 test_integration.py

Documentation

Document Description
ARCHITECTURE.md Detailed system architecture
QUICKSTART.md Step-by-step setup guide
TROUBLESHOOTING.md Common issues and solutions

Supported Events

Event Type Severity Action
Machine Check Exception MCE CRITICAL Log & alert
Out-of-Memory Kill OOM_KILL CRITICAL Adjust memory settings
Hung Task HUNG_TASK WARNING Monitor & log
I/O Error IO_ERROR ERROR Log & alert
Hard Lockup HARDLOCKUP CRITICAL Log & alert
Page Fault PAGE_FAULT INFO Track patterns
CPU Stall CPU_STALL WARNING Monitor & log

Supported Actions

Action Risk Level Examples
log SAFE Log events for analysis
sysctl MODERATE Adjust vm.swappiness
cgroup MODERATE Modify cgroup settings
restart RISKY Restart services
kill DANGEROUS Terminate processes
memory_offline DANGEROUS Offline memory nodes

Security

Guardrail

All model-generated actions pass through a deterministic guardrail that:

  • Validates action type against whitelist
  • Checks targets against protected resources
  • Enforces confidence thresholds
  • Blocks injection attempts

Protected Resources

  • PIDs 0-2: Cannot be killed
  • Critical services: Cannot be restarted
  • System files: Cannot be modified

Performance

Latency Budget

Stage Target Maximum
Event capture < 1 μs 10 μs
IPC transfer < 1 μs 10 μs
Model inference < 5 ms 8 ms
Guardrail validation < 1 ms 2 ms
Total < 10 ms 20 ms

Resource Requirements

Resource Requirement
CPU cores 4 dedicated
RAM 4 GB locked
NUMA node 1 dedicated

License

Copyright (c) 2026 SLM Kernel Team

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.


Contributing

Contributions are welcome! Please see our contributing guidelines.


Support


Last Updated: 2026-07-02

About

SLM Kernel - Small Language Model Enabled Linux Kernel

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages