Skip to content

Rclone sync behaving badly, forcibly clearing RAM cache #7886

Closed

Description

@zcalusic

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

  1. ncw commented on Jun 3, 2024

    @ncw
    Member

    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?

  2. zcalusic commented on Jun 3, 2024

    @zcalusic
    Author

    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.

  3. ncw commented on Jun 6, 2024

    @ncw
    Member

    The argument here is quite persuasive

    restic/restic#666 (comment)

    I can measure the Active and Inactive cache levels like this

    $ cat /proc/meminfo | grep -P '(Ina|A)ctive.file'
    Active(file):   11883000 kB
    Inactive(file):  4361756 kB
    

    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?

  4. zcalusic commented on Jun 6, 2024

    @zcalusic
    Author

    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.

  5. ncw commented on Jun 7, 2024

    @ncw
    Member

    Thank you for the praise for rclone :-)

    According to ChatGPT

    The "Active(file)" and "Inactive(file)" entries were introduced to the /proc/meminfo file in the Linux kernel with the release of version 2.6.28.

    The changes were committed on August 19, 2008, by Johannes Weiner and included in the Linux 2.6.28 release, which officially came out on December 24, 2008. The commit message and patch details can be found in the kernel mailing list archives and the git history of the Linux kernel source code.

    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?

    $ sudo su -c 'echo 3 > /proc/sys/vm/drop_caches'
    [sudo] password for ncw: 
    $ cat /proc/meminfo | grep -P '(Ina|A)ctive.file'
    Active(file):     791584 kB
    Inactive(file):    35056 kB
    $ rclone copy -P /home/files/Images/xmas2016 /tmp/xmas2016
    Transferred:       38.471 GiB / 38.471 GiB, 100%, 428.496 MiB/s, ETA 0s
    Transferred:         3251 / 3251, 100%
    Elapsed time:      1m29.9s
    $ cat /proc/meminfo | grep -P '(Ina|A)ctive.file'
    Active(file):     832960 kB
    Inactive(file): 20955816 kB
    
    $ rm -rf /tmp/xmas2016/
    $ sudo su -c 'echo 3 > /proc/sys/vm/drop_caches'
    $ cat /proc/meminfo | grep -P '(Ina|A)ctive.file'
    Active(file):     760372 kB
    Inactive(file):    37396 kB
    $ rclone-v1.65.2 copy -P /home/files/Images/xmas2016 /tmp/xmas2016
    Transferred:       38.471 GiB / 38.471 GiB, 100%, 336.815 MiB/s, ETA 0s
    Transferred:         3251 / 3251, 100%
    Elapsed time:      1m40.2s
    $ cat /proc/meminfo | grep -P '(Ina|A)ctive.file'
    Active(file):     827564 kB
    Inactive(file): 20531528 kB
    $ 
    
  6. zcalusic commented on Jun 7, 2024

    @zcalusic
    Author

    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. :(

  7. ncw commented on Jun 7, 2024

    @ncw
    Member

    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.

    I'd love to see some evidence for this so I can replicate it myself - thank you.

  8. glenn-elliott commented on Jan 14, 2025

    @glenn-elliott

    Drive-by comment from a random developer: I work in the robotics domain, and we recently noticed that rclone calls fadvise() due to long periods of uninterruptible sleep. We've observed that fadvise() can result in a call to the kernel's __lru_add_drain_all(), which loops over all CPUs, with each CPU executing work on a kworker thread. The for-loop is essentially an N-way remote procedure call to each CPU, where N is the number of CPUs. The fadvise()-calling thread accumulates a long period of uninterruptible sleep if real-time work prevents any one of the per-CPU kworker threads from making progress.

    I don't expect rclone developers to spare a thought for real-time workloads (why should they?), but I think our experience supports the sentiment that rclone doesn't know enough about the host system to prescribe a single fixed policy. A measure of configurability could be useful.

  9. ncw commented on Jan 14, 2025

    @ncw
    Member

    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.

  10. vitorog commented on Aug 3, 2025

    @vitorog

    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.

  11. added a commit that references this issue on Mar 23, 2026
    095a4ef
  12. ncw commented on Mar 24, 2026

    @ncw
    Member

    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

  13. added a commit that references this issue on Mar 24, 2026
    7ca667d
  14. paf0186 commented on Mar 24, 2026

    @paf0186
    Contributor

    Great, thank you! Quick question:
    Briefly, how does the rclone release process work? When might we expect 1.74?

  15. spacelama commented on Apr 27, 2026

    @spacelama

    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.

  16. sinyb commented on Jun 27, 2026

    @sinyb

    +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.

  17. added a commit that references this issue on Jul 20, 2026
    44c06c4
  18. added a commit that references this issue on Oct 6, 2026
    daccf5a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions