Skip to content

feat: add bcache support#1244

Open
caniko wants to merge 1 commit intonix-community:masterfrom
caniko:feat/bcache-support
Open

feat: add bcache support#1244
caniko wants to merge 1 commit intonix-community:masterfrom
caniko:feat/bcache-support

Conversation

@caniko
Copy link
Copy Markdown

@caniko caniko commented Apr 1, 2026

Summary

Adds Linux bcache (block-layer cache) support to disko via three new types:

  • bcache_cache — partition content type for cache devices (SSD, eMMC)
  • bcache_backing — partition content type for backing devices (HDD, SD card)
  • bcache — top-level aggregator (like mdadm) that runs make-bcache, attaches cache to backing, sets cache mode, and delegates to nested content for filesystem creation

Motivation

bcache lets a fast device (SSD/eMMC) act as a transparent block-layer cache for a slower device (HDD/SD card). This is useful for:

  • SBCs with eMMC + SD card (e.g., RockPro64) where NixOS store writes are bottlenecked by SD speed
  • Servers with SSD cache in front of HDD arrays
  • Any setup where adding a cache tier to existing storage is needed without changing filesystems

Design

Follows the established disko multi-device patterns:

  • bcache_cache and bcache_backing register devices to $disko_devices_dir (like mdraid/bcachefs backing types)
  • bcache aggregator reads from temp dir, creates the bcache set, and manages content (like mdadm/lvm_vg)
  • Device discovery uses sysfs backing_dev_name matching for robustness
  • Generates boot.bcache.enable = true in NixOS config

Example usage

disko.devices = {
  disk = {
    cache-disk = {
      device = "/dev/sda";
      content.type = "gpt";
      content.partitions.cache = {
        size = "100%";
        content = { type = "bcache_cache"; set = "main"; };
      };
    };
    backing-disk = {
      device = "/dev/sdb";
      content.type = "gpt";
      content.partitions.backing = {
        size = "100%";
        content = { type = "bcache_backing"; set = "main"; };
      };
    };
  };
  bcache.main = {
    type = "bcache";
    device = "/dev/bcache0";
    cacheMode = "writeback";
    content = { type = "filesystem"; format = "ext4"; mountpoint = "/"; };
  };
};

Limitations (can be addressed in follow-up PRs)

  • Single-backing device per bcache set (covers ~90% of use cases)
  • Device path defaults to /dev/bcache0 — users with multiple bcache sets need to specify explicitly
  • Multi-backing would need udev rules for stable device naming

Test plan

  • nix flake check --no-build passes (packages, modules, doc generation evaluate cleanly)
  • nix build .#tests.bcache — NixOS VM test that verifies bcache device creation, mount, and cache mode
  • Real hardware test on RockPro64 (eMMC cache + SD card backing)

@caniko caniko force-pushed the feat/bcache-support branch 9 times, most recently from 820dd7d to 3234728 Compare April 2, 2026 07:59
Add three new disko types for Linux bcache block-layer caching:
- bcache_cache: partition content type for cache devices (SSD/eMMC)
- bcache_backing: partition content type for backing devices (HDD/SD)
- bcache: top-level aggregator that creates the bcache set,
  attaches cache to backing, and manages nested content

This enables declarative bcache configurations where a fast device
(SSD, eMMC) caches a slower device (HDD, SD card), significantly
improving I/O performance for the backing device.
@caniko caniko force-pushed the feat/bcache-support branch from 3234728 to 028b6d3 Compare April 2, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant