{"id":48651329,"url":"https://github.com/lof310/kcr-subsystem","last_synced_at":"2026-04-10T08:42:42.371Z","repository":{"id":347489390,"uuid":"1194230220","full_name":"lof310/kcr-subsystem","owner":"lof310","description":"A Linux kernel subsystem for transparent, memoization of deterministic computations.","archived":false,"fork":false,"pushed_at":"2026-03-28T04:42:19.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-28T09:41:47.108Z","etag":null,"topics":["cpu","cpu-scheduling","kernel-development","kernel-memory","kernel-programming","linux-kernel","memoization"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lof310.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-28T04:29:08.000Z","updated_at":"2026-03-28T04:42:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/lof310/kcr-subsystem","commit_stats":null,"previous_names":["lof310/kcr-subsystem"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/lof310/kcr-subsystem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lof310%2Fkcr-subsystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lof310%2Fkcr-subsystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lof310%2Fkcr-subsystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lof310%2Fkcr-subsystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lof310","download_url":"https://codeload.github.com/lof310/kcr-subsystem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lof310%2Fkcr-subsystem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31635962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T07:40:12.752Z","status":"ssl_error","status_checked_at":"2026-04-10T07:40:11.664Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","cpu-scheduling","kernel-development","kernel-memory","kernel-programming","linux-kernel","memoization"],"created_at":"2026-04-10T08:42:41.884Z","updated_at":"2026-04-10T08:42:42.361Z","avatar_url":"https://github.com/lof310.png","language":null,"readme":"# Kernel Computation Reuse (KCR) Module\n\nA Linux kernel module for transparent computation reuse through adaptive lookup acceleration.\n\n\u003e **CURRENTLY JUST A LIBRARY, NOT FUNCTIONAL YET BECAUSE IT REQUIRES DIRECT CHANGES TO THE KERNEL CODE**\n\n## Overview\n\nKCR 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.\n\n## Features\n\n- **Two-tier cache hierarchy**: Per-CPU L2 (512 entries) and per-socket L3 (4096 entries)\n- **Zero-copy shared memory**: memfd-based region visible to both kernel and user space\n- **Hardware-enforced security**: Leverages SMAP/SMEP/IOMMU for isolation\n- **IOMMU-based invalidation**: 100% coverage for DMA writes and memory modifications\n- **Determinism learning**: Automatic verification before caching\n- **Debugfs interface**: Statistics and configuration at `/sys/kernel/debug/kcr/`\n\n## Architecture\n\n```\nUser Space          Kernel Space        DMA Devices\n    │                    │                   │\n    └────────────────────┼───────────────────┘\n                         │\n              ┌──────────▼──────────┐\n              │  memfd Shared Memory│\n              │     (16 MB default) │\n              └──────────┬──────────┘\n                         │\n              ┌──────────▼──────────┐\n              │   L2/L3 Cache       │\n              │   (Per-CPU/Socket)  │\n              └─────────────────────┘\n```\n\n## Building\n\n### Prerequisites\n\n- Linux kernel headers for your running kernel\n- GCC with kernel module support\n\n### Compile\n\n```bash\ncd drivers/kcr\nmake\n```\n\n### Install\n\n```bash\nsudo make install\nsudo modprobe kcr\n```\n\n### Load/Unload\n\n```bash\n# Load module\nsudo insmod kcr.ko\n\n# Load with KCR disabled\nsudo insmod kcr.ko kcr_enable=0\n\n# Unload module\nsudo rmmod kcr\n```\n\n## Debugfs Interface\n\nAfter loading the module, statistics and configuration are available:\n\n```bash\n# View statistics\ncat /sys/kernel/debug/kcr/stats\n\n# View configuration\ncat /sys/kernel/debug/kcr/config\n```\n\n## API Reference\n\n### Core Functions\n\n```c\n// Initialize KCR subsystem\nint kcr_init(void);\n\n// Shutdown KCR subsystem\nvoid kcr_exit(void);\n\n// Check if KCR is enabled\nbool kcr_is_enabled(void);\n```\n\n### Cache Operations\n\n```c\n// Lookup cached result\nstruct kcr_entry *lookup_unified(u64 fingerprint, struct mm_struct *mm);\n\n// Store result in cache\nint store_result(u64 fingerprint, const void *data, u32 len, struct mm_struct *mm);\n\n// Invalidate cache entries for memory range\nvoid invalidate_range(struct mm_struct *mm, unsigned long start, unsigned long end);\n```\n\n### Fingerprint Computation\n\n```c\n// Compute xxHash64 fingerprint\nu64 compute_fingerprint(const void *data, size_t len, u64 seed);\n\n// Compute crypto operation fingerprint\nu64 crypto_compute_fingerprint(struct skcipher_request *req);\n```\n\n### Determinism Verification\n\n```c\n// Verify function produces deterministic results\nbool verify_deterministic(struct vma_metadata *meta, u64 current_result);\n\n// Check if VMA should be cached\nbool should_cache(struct vm_area_struct *vma);\n```\n\n## Configuration\n\n### Module Parameters\n\n| Parameter | Type | Default | Description |\n|-----------|------|---------|-------------|\n| `kcr_enable` | bool | true | Enable/disable KCR subsystem |\n\n### Build-time Options\n\n| Option | Description |\n|--------|-------------|\n| `CONFIG_KCR` | Enable KCR subsystem support |\n\n## Performance\n\n### Overhead\n\n- **Inactive path**: \u003c0.02% overhead when KCR is disabled\n- **Fingerprint computation**: ~25 cycles (xxHash64)\n- **L2 cache hit**: 15-25 cycles\n- **L3 cache hit**: 50-100 cycles\n- **SMAP/SMEP**: 0 cycles (hardware-enforced)\n\n### Subsystem Benefits\n\n| Subsystem | Operation | Savings |\n|-----------|-----------|---------|\n| Crypto | AES encrypt | 25× |\n| Crypto | SHA-256 | 40× |\n| Network | csum_partial | 5× |\n| Memory | copy_from_user | 2.5× |\n\n## Security\n\nKCR leverages hardware features for isolation:\n\n- **SMAP**: Prevents kernel from accessing user memory without explicit override\n- **SMEP**: Prevents kernel from executing user code pages\n- **IOMMU**: Isolates DMA device memory access\n- **Optional encryption**: Per-process AES-NI encryption (5-10 cycles overhead)\n\n## Limitations\n\n1. **Hardware requirements**: Requires Intel Sandy Bridge+ or AMD Bulldozer+ for SMAP/SMEP\n2. **Memory overhead**: 16 MB shared region per system\n3. **Determinism requirement**: Functions must be deterministic (verified by learning mode)\n4. **DMA support**: Some legacy drivers may lack IOMMU notification support\n\n## File Structure\n\n```\n.\n├── include/linux/\n│   ├── kcr.h           # Main header with data structures\n│   ├── kcr_types.h     # Type extensions\n│   ├── kcr_flags.h     # VM flag definitions\n│   └── kcr_task.h      # Task struct extensions\n├── drivers/kcr/\n│   ├── Makefile\n│   ├── kcr_main.c      # Module initialization\n│   ├── kcr_mem.c       # Memory management\n│   ├── kcr_cache.c     # Cache implementation\n│   └── kcr_debugfs.c   # Debugfs interface\n├── kernel/kcr/\n│   ├── kcr_core.c      # Core logic (fingerprint, injection)\n│   └── kcr_determinism.c # Determinism verification\n└── drivers/iommu/\n    └── kcr_iommu.c     # IOMMU integration\n```\n\n## License\n\nGPL-2.0\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flof310%2Fkcr-subsystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flof310%2Fkcr-subsystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flof310%2Fkcr-subsystem/lists"}