Description
What is the problem you are having with rclone?
I started experiencing performance issues after running an rclone sync. I noticed that carefully cached content in RAM is forcibly expunged after the rclone sync completes. This behavior was implemented in the following commit: f396550.
As a result, rclone is now behaving as if it is the only user of the data and assumes that the data won't be needed again, which is a mistaken assumption. Rclone is NOT the owner of the data that is synced and therefore should NOT decide to expunge it from the RAM just because it doesn't need it anymore!
Please remove the fadvise(POSIX_FADV_DONTNEED) calls from rclone. Alternatively, if anyone finds this "feature" useful (which is unlikely), make it optional, with the default setting being not to interfere with memory management.
The Linux kernel memory management subsystem is quite capable of freeing unused memory, especially if data has been read only once. In such cases, the data is in the inactive page cache list and is immediately freeable as soon as it is needed for something else.
Observed under rclone v1.66.0, Linux OS, 64 bit
How to use GitHub
- Please use the 👍 reaction to show that you are affected by the same issue.
- Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
- Subscribe to receive notifications on status change and new comments.
Activity
ncw commentedon Jun 3, 2024
In the case of doing transfers where the total file size is greater than the page cache I can't see an advantage in overwriting the page cache with data which is unlikely to be used again.
The patch you referenced fixed a real pain point for rclone users.
Maybe you could write more about your specific problem - perhaps we should make the fadvise calls optional on a flag?
zcalusic commentedon Jun 3, 2024
Yes, as I wrote in my original report, you can make fadvise() calls optional, and it works for me. The important thing is that such an aggressive method of clearing RAM can be and is turned off by default.
Imagine a database that is larger than the available RAM. Like most databases, it typically has a working set (hot data) that is smaller and can fit in a much smaller RAM, thereby minimizing disk accesses (think slow HDD). This approach works very well in practice. Since the database is append-only (think LevelDB), running rclone sync on a live database to create a backup can be problematic. Rclone decides to expunge all cached content as if it is the sole user of the data. This forces the database to spend a lot of time fetching data back from the disk, only to have it expunged again during the next rclone sync run.
Initially, many backup software developers thought using POSIX_FADV_DONTNEED would be beneficial. However, from what I know, they have since abandoned it. One such case, which I also reported, demonstrates this shift. After a brief discussion, common sense prevailed, and fadvise() was removed. You can check the details here: restic/restic#666.
The most important point is that rclone is almost always working on data belonging to another service or process. Why is it deciding on its own that the other service certainly won't need a lot of data cached in RAM? In most cases, this is the wrong decision.
Rclone: using POSIX_FADV_DONTNEED is not good practice
ncw commentedon Jun 6, 2024
The argument here is quite persuasive
restic/restic#666 (comment)
I can measure the Active and Inactive cache levels like this
So if I can do a large transfer without the POSIX_FADV_DONTNEED and it only increase the
Inactive(file)value then we can lose the POSIX_FADV_DONTNEED permanently - would you agree?Do you fancy doing a test to demonstrate that?
zcalusic commentedon Jun 6, 2024
Dear @ncw,
Until now, I haven't properly addressed how great the product rclone is, and I want to thank you for all the hard work you have invested. This is the most important thing!
You are right - stuff that is read only once will end up in the inactive queue. If there's no other user and the pages are not modified (meaning nobody reads or changes them), they are easily replaced by the kernel, which you referred to as "overwriting them." This is the whole idea behind having two queues: one that protects what is important (the active one), and the other as a scratchpad where pages enter and leave to make space for other pages.
However, I have to be honest: I really don't have enough time these days to do any proper testing or benchmarking of this. Partly, it's because I'm convinced that expunging memory pages of another process is fundamentally wrong. Somehow, I'm always the one to detect this misbehavior - wondering why this process occasionally suffers, why it suddenly sits on disk... ah, rclone sync killed it again. But why? Because it used DONTNEED, and it's not up to rclone to do that since it's not the sole user of the pages. It's just a very useful and versatile backup utility.
Historically, there were Linux kernels that were too eager to swap under heavy I/O transfers. Maybe someone needed a "hack" like this 10 or 15 years ago, but today, if anyone has issues that are fixed or worked around by DONTNEED, I'd say either the system is not properly tuned, or it's a genuine kernel bug.
ncw commentedon Jun 7, 2024
Thank you for the praise for rclone :-)
According to ChatGPT
So these changes have been in the kernel for a while now! The commit which added the POSIX_FADV_DONTNEED was from 2018 and even RedHat Enterprise 6 was up to 2.6.32 by then.
The original commit mentions the pcstat tool which measures whether any given file is in the cache or not. This makes no distinction between Active and Inactive cache though and I suspect that is the problem - when adding that code we thought being in the cache was bad, but it looks like that statement should be modified to if rclone brings files it is transferring into the Active cache that is bad.
I did a little test with a modified rclone which doesn't call POSIX_FADV_DONTNEED on a directory of 38GB of images and you can see from the below that neither this, nor the stock rclone seems to bump up the
Active(file)cache indicating that the POSIX_FADV_DONTNEED isn't doing anything and is likely slowing things down.I don't see any adverse affects from POSIX_FADV_DONTNEED though - it is as if the kernel just ignores it. Do you?
zcalusic commentedon Jun 7, 2024
I believe I've explained multiple times in this ticket that I do see very adverse effects of rclone using DONTNEED. It definitely clears memory of useful cached data, causing apps to hit the disk again and reload data into RAM. This is very suboptimal.
There's an old Linux adage: unused RAM is wasted RAM. As it is set up right now, rclone is wasting RAM. :(
ncw commentedon Jun 7, 2024
I'd love to see some evidence for this so I can replicate it myself - thank you.
glenn-elliott commentedon Jan 14, 2025
Drive-by comment from a random developer: I work in the robotics domain, and we recently noticed that
rclonecallsfadvise()due to long periods of uninterruptible sleep. We've observed thatfadvise()can result in a call to the kernel's__lru_add_drain_all(), which loops over all CPUs, with each CPU executing work on akworkerthread. The for-loop is essentially an N-way remote procedure call to each CPU, where N is the number of CPUs. Thefadvise()-calling thread accumulates a long period of uninterruptible sleep if real-time work prevents any one of the per-CPUkworkerthreads from making progress.I don't expect
rclonedevelopers to spare a thought for real-time workloads (why should they?), but I think our experience supports the sentiment thatrclonedoesn't know enough about the host system to prescribe a single fixed policy. A measure of configurability could be useful.ncw commentedon Jan 14, 2025
If someone would like to have a go at making this configurable then I would merge it. I think we should keep the default as-is for the moment but get as many people as we can to do testing with the new flag with the view to changing the default.
vitorog commentedon Aug 3, 2025
I gave it a try and added a new flag ("--disable-fadvise") to disable it: #8723
Was that what you had in mind? Let me know what you think.
local: remove fadvise calls that cause spinlock contention
ncw commentedon Mar 24, 2026
I've merged a fix for this (thank you @paf0186 and thank you @vitorog for the first version) to master now which means it will be in the latest beta in 15-30 minutes and released in v1.74
local: remove fadvise calls that cause spinlock contention
paf0186 commentedon Mar 24, 2026
Great, thank you! Quick question:
Briefly, how does the rclone release process work? When might we expect 1.74?
spacelama commentedon Apr 27, 2026
This issue has been closed so my comment probably won't be noticed, but the removal probably shouldn't have been done (or at least the next release shouldn't be made) until #9283 is also addressed.
Contrary to zcalusic's opinion, cache behaviour should be decided by admin, not operating system. I've been using these kinds of hacks to reduce cache usage for 20 years now, because Linux's VMM has always been crap at deciding what's important and what's not, and the statement that unused memory is wasted memory is asinine in a many places, such as a VM environment (or my desktop, for that matter). Do a second clone because it's part of a regular backup job and now all that data is in Active. I don't give a flying how long a backup takes. I care about the applications I'm using not being swapped out while I go for lunch, and then taking 20 minutes to come back in when I come back. The operating system can't know this was my intention without me setting hints that have now been removed. Obviously the code was introduced in f396550 in 2019 for a reason, and I haven't seen any remarkable improvements to the kernel's cache behaviour since then.
sinyb commentedon Jun 27, 2026
+1 here for not removing FADV_DONTNEED on write, or giving an option to enable it, because rclone's primary function is backup, and backup is usually not read after write (OK, OK, some might read it for verification, but not immediately after write, and even for verification it is better not to read it from cache but from physical medium).
My use case is millions of files in thousands of directories, mostly not changing, only new added every day. Every rclone run has to re-read entire directory structure, which works very fast when it is cached, but after addition of a few gigabytes of new files, directory cache gets overwritten by file cache which wouldn't be used (hopefully) never again, so on next run entire directory structure has to be read again taking hours instead of minutes...
Btw, I came to rclone exactly because it used to have correct fadvise, unlike rsync which doesn't and has no intention of implementing it.
local: remove fadvise calls that cause spinlock contention
local: remove fadvise calls that cause spinlock contention