Skip to content

local: remove fadvise calls that cause spinlock contention - #9280

Merged
ncw merged 1 commit into
rclone:masterfrom
paf0186:remove-fadvise-dontneed
Mar 24, 2026
Merged

ncw merged 1 commit into
rclone:masterfrom
paf0186:remove-fadvise-dontneed

Conversation

@paf0186

@paf0186 paf0186 commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Remove all fadvise calls (both POSIX_FADV_DONTNEED and POSIX_FADV_SEQUENTIAL) from the local backend entirely.

The FADV_DONTNEED calls cause severe spinlock contention on parallel file systems and any system with many concurrent rclone transfers. Each DONTNEED call triggers per-page cache teardown under a global lock in the kernel. With many rclone threads calling fadvise in parallel, this becomes a catastrophic bottleneck.

Observed on a 256-core system running rclone with 64 parallel transfers over Lustre:

  • 69% of all CPU cycles spent in kernel spinlock contention from the fadvise→page eviction path
  • rclone consuming 6500% CPU (65 cores), nearly all in kernel spinlock
  • Effective throughput well below hardware capability

The kernel's own page reclaim (kswapd) handles cache eviction more efficiently from a single context rather than every rclone thread fighting over the same lock.

Since rclone does not always read files sequentially (e.g. multipart uploads rewind and re-read blocks), FADV_SEQUENTIAL was also not reliably correct.

This is consistent with the non-Linux behavior (which never called fadvise) and with restic's decision to remove the same code (restic/restic#670).

Supersedes #8723 — that PR added a flag to disable fadvise; this PR removes it outright, as discussed in the comments there.

If reviewers prefer to keep FADV_SEQUENTIAL (the readahead hint) while removing FADV_DONTNEED (the destructive one), I'm happy to adjust — but since the non-Linux path never did either, removing both seemed cleanest.

Fixes #7886

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

Remove the POSIX_FADV_DONTNEED and POSIX_FADV_SEQUENTIAL calls
from the local backend. The DONTNEED calls cause severe spinlock
contention on parallel file systems (and any system with many
concurrent transfers), because each call triggers per-page cache
teardown under a global lock.

Observed on a 256-core system running rclone with 64 parallel
transfers over Lustre: 69% of all CPU cycles were spent in
kernel spinlock contention from the fadvise path, with effective
throughput well below hardware capability.

The kernel's own page reclaim (kswapd) handles eviction more
efficiently from a single context. Since rclone does not always
read files sequentially (e.g. multipart uploads rewind and
re-read blocks), FADV_SEQUENTIAL was also not reliably correct.

This is consistent with the non-Linux behavior (which never
called fadvise) and with restic's decision to remove identical
code (restic/restic#670).

Fixes rclone#7886

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been meaning to do this for ages - thank you :-)

Looks perfect. Will merge now.

@ncw
ncw merged commit 7ca667d into rclone:master Mar 24, 2026
9 checks passed
@zcalusic

Copy link
Copy Markdown

Thank you @paf0186 for this PR, and thank you @ncw for finally fixing this performance regression in rclone. 🥳

zcalusic added a commit to zcalusic/dockerfiles that referenced this pull request Mar 24, 2026
Shouldn't be needed anymore starting with v1.74.0, thanks to
rclone/rclone#9280
@spacelama

Copy link
Copy Markdown

@ncw, please consider #9283 before next release to mitigate this feature removal.

zcalusic added a commit to zcalusic/dockerfiles that referenced this pull request Jun 9, 2026
Shouldn't be needed anymore starting with v1.74.0, thanks to
rclone/rclone#9280
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.

Rclone sync behaving badly, forcibly clearing RAM cache

4 participants