Backpressure when cache is full

I'm planning to build a "NAS" at my parents' house backed by a remote storage provider via rclone. I want to repurpose old hardware for this:

  • Raspberry Pi 3B+
  • 128GB USB stick as cache

The goal is to leverage remote storage while using a 128GB local cache to reduce reliance on internet connectivity for frequently accessed files. I'm aware of potential data consistency issues with connectivity or hardware failures, but I'd like to focus on a specific issue I've discovered during testing.

My use case assumptions

  • Library size: Larger than cache (potentially multi-TB)
  • Individual file size: Smaller than cache size
  • Local network: 12MB/s (Raspberry Pi Ethernet)
  • Internet upload: ~5MB/s
  • Write pattern: Bulk uploads of new files (faster than upload speed)

The Problem

After reading the rclone documentation, I ran a test to validate the behavior of --vfs-cache-max-size during bulk uploads. I confirmed that it's a soft limit, not a hard limit. During bulk uploads, the cache grows beyond this limit to protect files with pending uploads from eviction. This works well when disk space is unrestricted, but causes write failures when the cache directory hits a hard disk limit.

Test Setup

  • Source data: 444MB
  • --vfs-cache-max-size: 20M
  • Available disk space: 50MB (enforced via btrfs qgroup quota)
  • Copy method: rsync

Configuration

rclone mount b2:infinity-storage /srv/infinity/data \
  --vfs-cache-mode full \
  --vfs-cache-max-age 87600h \
  --vfs-cache-max-size 20M \
  --cache-dir /srv/infinity/cache \
  --vfs-write-back 5s \
  --vfs-write-wait 300s \
  --buffer-size 16M \
  --vfs-read-ahead 256M \
  --log-level INFO \
  --rc \
  --rc-serve \
  --rc-addr localhost:5572

Copy command

rsync -avh --progress /origin/ /srv/infinity/data/

Result

The cache grew beyond 20M as expected (protecting pending uploads), but when it hit the 50MB hard limit, writes failed with I/O errors:

rsync: [receiver] write failed on "/srv/infinity/data/03/IMG_20180306_184218.jpg": Input/output error (5)

Logs

The Question

Would it be feasible to implement some form of backpressure mechanism that slows down or blocks write operations when the cache is approaching disk capacity, rather than failing with I/O errors? I'm curious to hear thoughts on whether this is something that could be addressed in rclone's VFS cache, and what challenges or trade-offs might be involved.

You can just chime in to the existing issue: Rate-limiting FUSE requests when VFS cache is full · Issue #6005 · rclone/rclone · GitHub

Or even better, send a PR for it… :wink:

1 Like

I took it as a challenge for myself - this change worked for my use case: vfs: retry cache operations with backoff when disk quota/space exceeded by JHK · Pull Request #9137 · rclone/rclone · GitHub. Will continue the discussion in the GH issue. Thanks for that!

1 Like

You could try using the deprecated cache backend. It still has some good use-cases