A Linux kernel module for transparent computation reuse through adaptive lookup acceleration.
CURRENTLY JUST A LIBRARY, NOT FUNCTIONAL YET BECAUSE IT REQUIRES DIRECT CHANGES TO THE KERNEL CODE
KCR provides kernel-level memoization services that cache results of deterministic functions and inject them on subsequent identical calls. The system uses a two-tier cache hierarchy with per-CPU L2 and per-socket L3 caches, achieving 15-25 cycle hit latency.
- Two-tier cache hierarchy: Per-CPU L2 (512 entries) and per-socket L3 (4096 entries)
- Zero-copy shared memory: memfd-based region visible to both kernel and user space
- Hardware-enforced security: Leverages SMAP/SMEP/IOMMU for isolation
- IOMMU-based invalidation: 100% coverage for DMA writes and memory modifications
- Determinism learning: Automatic verification before caching
- Debugfs interface: Statistics and configuration at
/sys/kernel/debug/kcr/
User Space Kernel Space DMA Devices
│ │ │
└────────────────────┼───────────────────┘
│
┌──────────▼──────────┐
│ memfd Shared Memory│
│ (16 MB default) │
└──────────┬──────────┘
│
┌──────────▼──────────┐
│ L2/L3 Cache │
│ (Per-CPU/Socket) │
└─────────────────────┘
- Linux kernel headers for your running kernel
- GCC with kernel module support
cd drivers/kcr
makesudo make install
sudo modprobe kcr# Load module
sudo insmod kcr.ko
# Load with KCR disabled
sudo insmod kcr.ko kcr_enable=0
# Unload module
sudo rmmod kcrAfter loading the module, statistics and configuration are available:
# View statistics
cat /sys/kernel/debug/kcr/stats
# View configuration
cat /sys/kernel/debug/kcr/config// Initialize KCR subsystemintkcr_init(void);
// Shutdown KCR subsystemvoidkcr_exit(void);
// Check if KCR is enabledboolkcr_is_enabled(void);// Lookup cached resultstructkcr_entry*lookup_unified(u64fingerprint, structmm_struct*mm);
// Store result in cacheintstore_result(u64fingerprint, constvoid*data, u32len, structmm_struct*mm);
// Invalidate cache entries for memory rangevoidinvalidate_range(structmm_struct*mm, unsigned longstart, unsigned longend);// Compute xxHash64 fingerprintu64compute_fingerprint(constvoid*data, size_tlen, u64seed);
// Compute crypto operation fingerprintu64crypto_compute_fingerprint(structskcipher_request*req);// Verify function produces deterministic resultsboolverify_deterministic(structvma_metadata*meta, u64current_result);
// Check if VMA should be cachedboolshould_cache(structvm_area_struct*vma);| Parameter | Type | Default | Description |
|---|---|---|---|
kcr_enable | bool | true | Enable/disable KCR subsystem |
| Option | Description |
|---|---|
CONFIG_KCR | Enable KCR subsystem support |
- Inactive path: <0.02% overhead when KCR is disabled
- Fingerprint computation: ~25 cycles (xxHash64)
- L2 cache hit: 15-25 cycles
- L3 cache hit: 50-100 cycles
- SMAP/SMEP: 0 cycles (hardware-enforced)
| Subsystem | Operation | Savings |
|---|---|---|
| Crypto | AES encrypt | 25× |
| Crypto | SHA-256 | 40× |
| Network | csum_partial | 5× |
| Memory | copy_from_user | 2.5× |
KCR leverages hardware features for isolation:
- SMAP: Prevents kernel from accessing user memory without explicit override
- SMEP: Prevents kernel from executing user code pages
- IOMMU: Isolates DMA device memory access
- Optional encryption: Per-process AES-NI encryption (5-10 cycles overhead)
- Hardware requirements: Requires Intel Sandy Bridge+ or AMD Bulldozer+ for SMAP/SMEP
- Memory overhead: 16 MB shared region per system
- Determinism requirement: Functions must be deterministic (verified by learning mode)
- DMA support: Some legacy drivers may lack IOMMU notification support
.
├── include/linux/
│ ├── kcr.h # Main header with data structures
│ ├── kcr_types.h # Type extensions
│ ├── kcr_flags.h # VM flag definitions
│ └── kcr_task.h # Task struct extensions
├── drivers/kcr/
│ ├── Makefile
│ ├── kcr_main.c # Module initialization
│ ├── kcr_mem.c # Memory management
│ ├── kcr_cache.c # Cache implementation
│ └── kcr_debugfs.c # Debugfs interface
├── kernel/kcr/
│ ├── kcr_core.c # Core logic (fingerprint, injection)
│ └── kcr_determinism.c # Determinism verification
└── drivers/iommu/
└── kcr_iommu.c # IOMMU integration
GPL-2.0