Linux: single-file copy from SMB share capped at ~190 MB/s (1 MiB serial read/write loop, reproduced with dd)

Get help for specific problems
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Setup: FreeFileSync 14.13 (Linux), CachyOS, kernel 7.3. Source: QNAP TS-451+ share on a USB drive, kernel CIFS mount (SMB 3.0). Destination: local NVMe (btrfs). Network: 2.5 GbE. Files: 19–36 GB FOG image backups (bigger than the NAS's 16 GB RAM).

Problem: copying these files, FreeFileSync on Linux holds at ~190 MB/s. Other tools on the same machine get ~280 MB/s, as does FreeFileSync on Windows 11. Fail-safe copy and verify are off; a single file is enough to show it.

Measurements (same file, page cache dropped before each run):
FreeFileSync 14.13 (Linux)    ~190 MB/s
dd bs=1048576                 ~190 MB/s
dd bs=16M                     ~280 MB/s
Dolphin (KDE)                 ~280 MB/s
pv file > dest                ~282 MB/s
Cause: stat -c %o on the file returns 1048576. In the 14.13 source:

FileBase::getBlockSize() (zen/file_io.cpp) uses st_blksize, so 1 MiB on this CIFS mount.
zen::copyNewFile() (zen/file_access.cpp) passes that to unbufferedStreamCopy() (zen/serialize.h).
unbufferedStreamCopy() is a serial read() → write() loop, one 1 MiB block at a time.

dd with the same 1 MiB block gives the same ~190 MB/s; with 16 MiB blocks it gets the full ~280. On CIFS, a large read is split into several SMB requests in flight at once, hiding the source's latency. 1 MiB reads can't do that.

Suggested fix: a minimum of 8–16 MiB for the copy read size (untested sketch):
// zen/file_access.cpp, copyNewFile()
constexpr size_t copyBlockSizeMin = 16 * 1024 * 1024;
unbufferedStreamCopy(tryRead, std::max(fileIn.getBlockSize(), copyBlockSizeMin),
                     tryWrite, fileOut.getBlockSize(), notifyUnbufferedIO);
Overlapping reads and writes, or copy_file_range() (already mentioned in a comment in file_access.cpp), would also help. Happy to test a build. Chart attached.
You do not have the required permissions to view the files attached to this post.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Update: confirmed on the official 14.13 binary.

strace during a copy shows the loop: read(fd, ..., 1048576) followed by four write(..., 262144), repeated, single thread.

I then ran the unmodified official build with a small LD_PRELOAD shim that services FreeFileSync's 1 MiB read() calls from 16 MiB reads on CIFS files (nothing else changed). The same copy went from ~190 MB/s to ~280 MB/s, matching dd bs=16M, pv and Dolphin.

So a larger read size for network sources (or overlapped read/write) fixes this. Happy to share the shim source or test a build.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Update 2: with parallel reads it now saturates the link.

Note: There is a typo in Update 1: It should read:
"I then ran the unmodified official build with a small LD_PRELOAD shim that services FreeFileSync's 1 MiB read() calls from 16 MiB reads on CIFS files (nothing else changed). The same copy went from ~190 MB/s to ~254 MB/s, almost matching dd bs=16M, pv and Dolphin."

Same unmodified official 14.13 binary, same 35 GB file, cold cache, via an LD_PRELOAD shim on CIFS files only:
FreeFileSync as-is (1 MiB serial read/write)      ~190 MB/s
+ 16 MiB reads                                    ~245 MB/s
+ read-ahead thread (overlap read and write)      ~250-290 MB/s
+ 2 reads in flight at different offsets          ~293-297 MB/s
(pv on the same file: 279 MiB/s average)
(3 reads in flight gives the same ~295 MB/s, so 2 is enough to saturate 2.5 GbE here.)
thread state during the copy showed the copy thread waiting on the reader, and the reader in netfs_wait_for_in_progress, i.e. the network idling between serial reads. Keeping 2+ large reads in flight removes the gaps. Happy to share the shim source.

Graph.png
You do not have the required permissions to view the files attached to this post.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Patches against the 14.13 source, both tested here:

1) ffs-parallel-read.patch (zen/file_access.cpp only) - the copy fix. For files >= 64 MB on CIFS/SMB/NFS, two reader threads pread() consecutive 16 MiB chunks into a 4-slot ring while the copy thread writes them in order. Progress/cancel callbacks stay on the calling thread, read errors surface as the usual FileError, and the existing loop is unchanged for local and small files.

I built 14.13 from source with this patch (against wxWidgets 3.3.5, exceptions disabled) and it copies the same 35 GB file at ~293-297 MB/s vs ~190 with the official build, matching the LD_PRELOAD shim results.

2) ffs-linux-build-fixes.patch - what it took to build the published source with GCC on Arch/CachyOS:
[*]Makefile: missing "\" after -Wno-deprecated-enum-enum-conversion (the -O3 -DNDEBUG line is otherwise a syntax error), and $(shell arch) -> $(shell uname -m) since not every distro ships "arch"
[*]zen/argon2.cpp line 42 and xBRZ/src/xbrz.cpp line 85: "#if  def __GNUC__" -> "#ifdef __GNUC__"
[*]::g_free(), ::g_object_unref() etc. fail with newer glib, where these are macros - dropped the leading ::
[*]libssh2_wrap.h: guarded LIBSSH2_ERROR_STORE_OVERFLOW / MAC_FAILURE / HASH_INIT / HASH_CALC with #ifdef, and added fallbacks for MAX_SFTP_READ_SIZE / MAX_SFTP_OUTGOING_SIZE (30000) for stock libssh2
Not included: wx+/darkmode.cpp needs wxColorHook/refGlobalColorHook() from your patched wxWidgets; I just #ifdef'd it out locally.
You do not have the required permissions to view the files attached to this post.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

Very interesting findings!

thread state during the copy showed the copy thread waiting on the reader, and the reader in netfs_wait_for_in_progress
Before changing the buffer size, I'd like to test what impact prefetching has on the copy performance. FreeFileSync is using POSIX_FADV_SEQUENTIAL, so the OS should do some amount of prefetching.

Do you get faster performance with the following version which applies a dedicated prefetching thread?
https://www.mediafire.com/file/8phqzhrraw9duwy/FreeFileSync_14.14_beta_Linux_x86_64.tar.gz

dd with the same 1 MiB block gives the same ~190 MB/s; with 16 MiB blocks it gets the full ~280.
Yes, bigger buffer sizes is probably the way to go!

What f_bsize and st_blksize values do you get for files on your network share?
stat -c 'st_blksize=%o' /path/to/file
stat -f -c 'f_bsize=%s' /path/to/file

Update 2: with parallel reads it now saturates the link.
Hopefully parallel threads per file copy can be avoided. FreeFileSync already supports copying multiple files in parallel by using multiple threads. I think link saturation should be achievable via a sufficiently large read buffer size, which then spawns many SMB packages.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Very interesting findings!
Zenju, 20 Nov 2026, 18:21
Hold on final reply. After more testing

Control re-run first: the beta with no shim, cold cache, still ~190 MB/s. So the
numbers below are really the read size changing.

stat values for a file on the share (kernel CIFS mount, SMB 3.0):
st_blksize = 1048576
f_bsize    = 1024
14.14 beta with the prefetching thread, unmodified: no change, ~190 MB/s.

strace shows why - the reads are still 1 MiB:
   8561  read(..., 1048576)
    148  read(...,  262144)
The prefetch thread is prefetching in 1 MiB units. On CIFS the read size decides how
many SMB requests are in flight at once, so 1 MiB reads hit the same latency wall
whether a second thread issues them or not.

But the prefetch thread does work once it has something to work with. I used the
LD_PRELOAD shim purely to change the read size (its own read-ahead disabled), so the
beta's prefetching is the only threading involved. Same 35 GB file, page cache dropped
before every run:
beta as shipped (1 MiB reads)   ~190 MB/s
beta + 4 MiB reads              ~290 MB/s
beta + 8 MiB reads              ~290 MB/s
beta + 16 MiB reads             ~295 MB/s
beta + 32 MiB reads             ~290 MB/s
beta + 64 MiB reads             ~290 MB/s
(pv on the same file: 279 MiB/s, dd bs=16M: ~280 MB/s)
4 MiB is already enough with the prefetch thread. For comparison, on 14.13 with no
prefetching the same shim at 16 MiB only reached ~245 MB/s, and it took overlapped or
parallel reads to pass 290.

So the combination is what matters, and parallel reads per file do look avoidable:
keep the prefetch thread, but give it reads of at least a few MiB rather than
st_blksize. Caveat on my earlier numbers - this test is very sensitive to page cache
state. A run started with the cache still full from the previous copy read ~100 MB/s
low until I started dropping caches before every run.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

4 MiB is already enough with the prefetch thread. ciggy, 20 Nov 2026, 19:02
Awesome results! I suspected that OS prefetching might not be optimal. The large buffer sizes seemed to compensate for the system prefetcher being partially idle while waiting for the file output to be written, instead of using the time to fetch more data.
A dedicated prefetching thread allows more control:
/*  prefetch buffer size:
     1. slow reader => buffer mostly empty => >= blockSizeIn (continue reading without delays)
     2. slow writer => buffer mostly full => >= blockSizeOut (write full block sizes)
     3. fluctuating read/write speeds => N x buffer size                                    */
In the beta above I've used 2 * max(blockSizeIn, blockSizeOut)

With the beta, the prefetcher is now 100% busy, but latency + system call overhead is still an issue. The 1MB st_blksize as reported by fstat is way too small! Linux is unfortunately missing statfs::f_iosize, which on macOS would be about 7MB for a network share!
Maybe we need to develop a heuristic.

Out of curiosity, which perf do you get for the beta + your shim with "2 MiB reads"?
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Thanks, this is fun AF!.

2 MiB reads: ~293 MB/s. That run was 2 files totalling 64.4 GB in 3:40, so it held link speed across the whole copy - the instantaneous readout drifted between 287 and 293 but the average came out at ~293, same as the larger sizes.

Full table, beta + shim, page cache dropped before every run:
beta as shipped (1 MiB reads)   ~190 MB/s
beta + 2 MiB reads              ~293 MB/s  (64.4 GB / 2 files / 3:40)
beta + 4 MiB reads              ~293-297 MB/s
beta + 8 MiB reads              ~293-297 MB/s
beta + 16 MiB reads             ~293-297 MB/s
beta + 32 MiB reads             ~293-297 MB/s
beta + 64 MiB reads             ~293-297 MB/s
(pv on the same file: 279 MiB/s, dd bs=16M: ~280 MB/s)
So the entire cliff is between 1 and 2 MiB, and nothing above 2 MiB adds anything measurable on this link. Worth noting: 4 MiB with your prefetch thread gives the same ~293-297 as my patch did with two parallel 16 MiB reads in flight, so on this mount the parallel reads buy nothing that doubling the read size does not.

That means your existing 2 * max(blockSizeIn, blockSizeOut) already lands in the right place - it just needs to govern the read size as well as the prefetch buffer. On this mount that is 2 MiB and it saturates. A larger multiplier would give margin on higher-latency links without costing anything here, but I have no data to say whether that margin is needed.

On the heuristic question: neither value the kernel reports here is much help. st_blksize is 1048576 and f_bsize is 1024, so the filesystem is not hinting at anything close to a useful read size. A multiplier on st_blksize, or a plain floor of a few MiB for network sources, looks more dependable than anything derivable from statfs on Linux.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

2 MiB reads: ~293 MB/s.ciggy, 20 Nov 2026, 19:48
What a nice surprise! FreeFileSync can easily use "2 * st_blksize" which is still conservative. With upper/lower limits of 256kB and 32MB. Incidentally a factor of 2 is also near-optimal for f_iosize on macOS. A factor of 4 OTOH needs some more consideration and probably code optimization as we don't want to blow up RAM usage when st_blksize happens to be large while 10 parallel threads are using multiple file copy buffers each (e.g. the prefetching thread is adding two, but thats a current QOI issue, not inherent).

Here's a beta using the prefetcher thread and "2 * st_blksize":
https://www.mediafire.com/file/1gv7brockkwi6bf/FreeFileSync_14.14_beta2_Linux_x86_64.tar.gz
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Thanks for the beta 2!

Ugh, so sorry. Correction to my last post, I have to walk back the main conclusion.

The shim flag I was using to "disable prefetching" (FFS_BIGREAD_NOAHEAD) didn't exist in the version I was actually running. It was silently ignored, so every one of those runs used the shim's default 2 reader threads with 4 buffered chunks. They weren't read-size-only tests at all - which means "4 MiB is enough" and "parallel reads look avoidable" were both wrong, and that's what sent you down the 2 * st_blksize path. My fault.

Re-ran forcing a single reader thread. Same files, cache dropped before each run:
14.14 beta2 as shipped (2 MiB reads)   ~196 MB/s
shim 2 MiB,  1 thread                  ~197 MB/s
shim 16 MiB, 1 thread                  ~252-264 MB/s
shim 64 MiB, 1 thread                  ~210-230, unstable (swings to ~300)
shim 2 MiB,  2 reads in flight         ~293 MB/s
shim 4-64 MiB, 2 reads in flight       ~293-297 MB/s
(pv on the same file: 279 MiB/s, dd bs=16M: ~280 MB/s)
So read size alone does help, but only up to a point: single-threaded peaks around 16 MiB at ~258 and gets worse and erratic beyond that - at 64 MiB a single read takes ~220 ms, so reader and writer alternate in long bursts instead of overlapping. Meanwhile two 2 MiB reads in flight hit ~293 with 8x less buffer than the best single-threaded case.

The strace on beta2 shows the same thing from the other side. All reads come from one thread, and the gaps alternate:
04:26:22.009085 read(7, ..., 2097152) = 2097152
04:26:22.016737 read(7, ..., 2097152) = 2097152   +7.7 ms
04:26:22.030680 read(7, ..., 2097152) = 2097152   +13.9 ms
04:26:22.038444 read(7, ..., 2097152) = 2097152   +7.8 ms
04:26:22.053405 read(7, ..., 2097152) = 2097152   +15.0 ms
04:26:22.061381 read(7, ..., 2097152) = 2097152   +8.0 ms
Two reads ~8 ms apart, then a ~14 ms gap, repeating for the whole capture. 4 MiB per 22 ms is ~190 MB/s. A 2 MiB read at link speed takes ~7 ms, so the 8 ms gaps are reads running flat out and the 14 ms gaps are the reader blocked waiting on the writer. The link is idle roughly a third of the time.

Attaching the shim source in case it's useful for comparison. It's a small LD_PRELOAD library; the relevant part is a ring of N chunks with T reads in flight via pread().
You do not have the required permissions to view the files attached to this post.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

They weren't read-size-only tests at all - which means "4 MiB is enough" and "parallel reads look avoidable" were both wrong ciggy, 21 Nov 2026, 09:47
At least that's more realistic; in tests on macOS SMB network I needed 32 MB buffer size for link saturation (which is roughly 4 x f_iosize), while 16 MB got 95% of the speed. However a single thread was sufficient.

The strace on beta2 shows the same thing from the other side. All reads come from one thread, and the gaps alternate:
04:26:22.009085 read(7, ..., 2097152) = 2097152
04:26:22.016737 read(7, ..., 2097152) = 2097152   +7.7 ms
04:26:22.030680 read(7, ..., 2097152) = 2097152   +13.9 ms
04:26:22.038444 read(7, ..., 2097152) = 2097152   +7.8 ms
04:26:22.053405 read(7, ..., 2097152) = 2097152   +15.0 ms
04:26:22.061381 read(7, ..., 2097152) = 2097152   +8.0 ms
ciggy, 21 Nov 2026, 09:47
2097152 bytes at 7.7 ms is 272 MB/s, which is already near the link capacity. The alternating pattern is peculiar. Maybe the fluctuations are caused by the writer flushing buffers. In this case, increasing the prefetch buffer size should help. What speed do you get when using double the prefetch buffer of beta2 (4 MB)?
https://www.mediafire.com/file/76ou27dkrj1zzjh/FreeFileSync_14.14_prefetch_4x.tar.gz

But also for a single read 270 MB/s is not yet at link capcity. What speed do you get when only doubling the input block size compared to beta2 to 4 MB:
https://www.mediafire.com/file/wqka2dqxfmiiarm/FreeFileSync_14.14_blocksize_4x.tar.gz

In both cases it would be helpful to see the strace numbers for comparison.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Both builds land on ~199-201 MB/s sustained. Neither the deeper prefetch buffer nor the larger block size moved it.

The strace shows why they come out identical. Steady state, same 35 GB file, cache dropped first:

prefetch_4x - 2 MiB reads, two back to back then a gap:
04:39:50.964935 read(12, ..., 2097152)
04:39:50.978646 read(12, ..., 2097152)   +13.7 ms
04:39:50.986335 read(12, ..., 2097152)    +7.7 ms
04:39:51.000233 read(12, ..., 2097152)   +13.9 ms
04:39:51.008010 read(12, ..., 2097152)    +7.8 ms
4 MiB per 21.7 ms = 193 MB/s

blocksize_4x - 4 MiB reads, evenly spaced:
04:54:25.021142 read(12, ..., 4194304)
04:54:25.042022 read(12, ..., 4194304)   +20.9 ms
04:54:25.063669 read(12, ..., 4194304)   +21.7 ms
04:54:25.084943 read(12, ..., 4194304)   +21.3 ms
04:54:25.105763 read(12, ..., 4194304)   +20.8 ms
4 MiB per 21.0 ms = 199.7 MB/s

It looks like both configurations move 4 MiB per ~21 ms cycle. The 7.7 ms and 15.4 ms figures are the reads themselves running at ~272 MB/s, which matches your arithmetic. The remaining ~6 ms per cycle is the reader idle.

That ~6 ms stall per 4 MiB appears to be fixed - it doesn't change whether the 4 MiB arrives as one read or two, and doubling the buffer behind it doesn't help either. One observation I can't fully account for: runs sometimes start around ~270 MB/s for the first ~20 seconds before settling to ~200. I saw it on both the clean prefetch_4x run and under strace, but I didn't catch it consistently on every run, so take it as an aside rather than a finding.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

prefetch_4x - 2 MiB reads, two back to back then a gap:
04:39:50.964935 read(12, ..., 2097152)
04:39:50.978646 read(12, ..., 2097152)   +13.7 ms
04:39:50.986335 read(12, ..., 2097152)    +7.7 ms
04:39:51.000233 read(12, ..., 2097152)   +13.9 ms
04:39:51.008010 read(12, ..., 2097152)    +7.8 ms
4 MiB per 21.7 ms = 193 MB/s

blocksize_4x - 4 MiB reads, evenly spaced:
04:54:25.021142 read(12, ..., 4194304)
04:54:25.042022 read(12, ..., 4194304)   +20.9 ms
04:54:25.063669 read(12, ..., 4194304)   +21.7 ms
04:54:25.084943 read(12, ..., 4194304)   +21.3 ms
04:54:25.105763 read(12, ..., 4194304)   +20.8 ms
4 MiB per 21.0 ms = 199.7 MB/s ciggy, 23 Nov 2026, 10:09
Interesting, the speed alternation is on the read() side, which probably makes sense: The NVME is not adding any delay. But why does it alternate??

The strace shows why they come out identical. Steady state, same 35 GB file, cache dropped first: ciggy, 23 Nov 2026, 10:09
Strange, but maybe a measurement fluke, as speed should increase with larger read buffer size.

What speed do you see with 8MiB and 16 MiB read buffers:
https://www.mediafire.com/file/p7owxuwnqkpq55b/FreeFileSync_14.14_blocksize_8.tar.gz
https://www.mediafire.com/file/mybvhdkqnb5e6n6/FreeFileSync_14.14_blocksize_16.tar.gz

One observation I can't fully account for: runs sometimes start around ~270 MB/s for the first ~20 seconds before settling to ~200. ciggy, 23 Nov 2026, 10:09
Is this the speed as shown in the FreeFileSync progress window?
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

On more thing worth testing: Maybe the issue is that the system prefetcher (POSIX_FADV_SEQUENTIAL) is working against the FFS prefetcher because it's using a different (smaller?) buffer size. Could explain the alternating pattern.

Here's FFS with 2 MB read buffer (like beta2) but with POSIX_FADV_SEQUENTIAL disabled:
https://www.mediafire.com/file/fcosbg9eir8o24a/FreeFileSync_14.14_blocksize_2_FADV_RANDOM.tar.gz.gz
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

On more thing worth testing: Maybe the issue is that the system prefetcher (POSIX_FADV_SEQUENTIAL) is working against the FFS prefetcher because it's using a different (smaller?) buffer size. Could explain the alternating pattern.

Here's FFS with 2 MB read buffer (like beta2) but with POSIX_FADV_SEQUENTIAL disabled:
https://www.mediafire.com/file/fcosbg9eir8o24a/FreeFileSync_14.14_blocksize_2_FADV_RANDOM.tar.gz.gz Zenju, 23 Nov 2026, 15:03
It seems FADV_RANDOM makes no difference on its own: ~195-198 MB/s, same as the others.

But I traced writes alongside reads on that build, and it changes the picture.

Two threads: 24660 reads (fd 12), 24659 writes (fd 17) in batches of 8 x 256 KiB = 2 MiB.
24660 15:39:11.516297 read(12 <unfinished ...>
24659 15:39:11.516343 write(17, ..., 262144)    +46 us
24659 15:39:11.516733 write(17, ..., 262144)    8th write, batch done in 390 us
24660 15:39:11.530136 read(12 <unfinished ...>  +13.8 ms
24659 15:39:11.530189 write(17, ..., 262144)    +53 us
24659 15:39:11.530682 write(17, ..., 262144)    batch done in 493 us
24660 15:39:11.537857 read(12 <unfinished ...>   +7.7 ms
24659 15:39:11.537912 write(17, ..., 262144)    +55 us
The writer fires 46-55 us after every read entry, without exception. It can only write data a read has already returned, so each read entry is effectively the completion of the previous read. That means there's no idle gap - I had that wrong in my earlier post. The reads themselves alternate in duration:
2 MiB in  7.7 ms = 272 MB/s
2 MiB in 13.8 ms = 152 MB/s
Every second read takes nearly twice as long for the same 2 MiB. And since this is the FADV_RANDOM build, it isn't the kernel readahead hint causing it - the alternation is still there with POSIX_FADV_SEQUENTIAL disabled.

The writes are definitely not the constraint: 2 MiB lands in 0.4-0.5 ms, roughly 5 GB/s into the local NVMe page cache. The writer thread is busy about 2% of the time.

This also unifies all four builds. Whatever the chunking, reading 4 MiB from this share with one thread takes ~21 ms:
beta2         2 MiB x2   7.7 + 14.0 = 21.7 ms per 4 MiB = 193 MB/s
prefetch_4x   2 MiB x2   7.7 + 14.0 = 21.7 ms per 4 MiB = 193 MB/s
blocksize_4x  4 MiB x1          21.0 = 21.0 ms per 4 MiB = 200 MB/s
FADV_RANDOM   2 MiB x2   7.7 + 13.4 = 21.1 ms per 4 MiB = 199 MB/s
So a single reader on this mount tops out near 199 MB/s, and none of block size, buffer depth or the fadvise hint shifts it. The alternating durations look like something in the CIFS client working at ~4 MiB granularity - one read served from what it already has, the next waiting on the wire.

That fits with two reads in flight reaching ~293 MB/s here: the second reader covers the slow read while the first covers the fast one.


Testing the other 2 now. Will have more shortly
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

8 MiB and 16 MiB both help. Numbers from the FreeFileSync progress window, cache dropped before each run:
blocksize_2   ~196-199 MB/s
blocksize_4   ~199-201 MB/s
blocksize_8   ~230 MB/s   (ranged 230-282, settled ~230)
blocksize_16  ~250 MB/s   (ranged 248-289, settled ~250)
The strace backs that up. 8 MiB - uniform 36 ms per read, no alternation at all:
15:49:23.736636 <... read resumed>, ..., 8388608) = 8388608
15:49:23.772870 <... read resumed>, ..., 8388608) = 8388608   +36.2 ms
15:49:23.809080 <... read resumed>, ..., 8388608) = 8388608   +36.2 ms
15:49:23.845330 <... read resumed>, ..., 8388608) = 8388608   +36.3 ms
15:49:23.881462 <... read resumed>, ..., 8388608) = 8388608   +36.1 ms
8 MiB / 36 ms = 233 MB/s

16 MiB - uniform ~66 ms:
15:56:00.855503 <... read resumed>, ..., 16777216) = 16777216
15:56:00.919883 <... read resumed>, ..., 16777216) = 16777216   +64.4 ms
15:56:00.987300 <... read resumed>, ..., 16777216) = 16777216   +67.4 ms
15:56:01.053451 <... read resumed>, ..., 16777216) = 16777216   +66.2 ms
15:56:01.119959 <... read resumed>, ..., 16777216) = 16777216   +66.5 ms
16 MiB / 65.9 ms = 255 MB/s

Normalised to time per 4 MiB, the trend is clear and the alternation only exists at small sizes:
 2 MiB   21.1 ms per 4 MiB   199 MB/s   alternating 7.7 / 13.8
 4 MiB   21.0 ms per 4 MiB   200 MB/s   uniform
 8 MiB   18.0 ms per 4 MiB   233 MB/s   uniform
16 MiB   16.5 ms per 4 MiB   255 MB/s   uniform
So you were right that larger buffers help - 4 MiB was the odd one out, giving nothing over 2 MiB. Worth noting 255 at 16 MiB matches what my LD_PRELOAD shim measured single-threaded at the same size (252-264), so the two methods agree.

Still short of the ~293 MB/s that two reads in flight reach here, and the larger sizes get noticeably more variable run to run. Happy to test 32 MiB if you want to see where it tops out, given you needed 32 MB on macOS.

And yes - the ~270 figure was the speed shown in the FreeFileSync progress window.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

Yes, a test with 32 MB would be great. This was the optimal buffer size in my SMB tests:
https://www.mediafire.com/file/aew1gisik3v7ymf/FreeFileSync_14.14_blocksize_32.tar.gz

With regards to the strange alternating pattern on read, perhaps it helps to get an strace for a reduced 1MB buffer size:
https://www.mediafire.com/file/y7mlovlkvdp5jgd/FreeFileSync_14.14_blocksize_1.tar.gz

Also, in the initial post you wrote you'd get 280 MB/sec with "dd" and 16 MiB buffer size. Since this is single-threaded, I'd expect at least the same performance from FreeFileSync. The following version removes the prefetching thread, i.e. basically FFS 14.13 but with 16 MiB input buffer:
https://www.mediafire.com/file/qnmg3l71wkdvwxu/FreeFileSync_14.14_blocksize_16_nothreads.tar.gz
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

All three builds, plus I think I've worked out what's behind the alternation. Build numbers are all on the default mount (rsize=4194304), cache dropped before each run.

blocksize_16_nothreads: ~250 MB/s, uniform 66.3 ms per read.
03:56:28.112727 read(..., 16777216)
03:56:28.179476 read(..., 16777216)   +66.7 ms
03:56:28.244505 read(..., 16777216)   +65.0 ms
03:56:28.310823 read(..., 16777216)   +66.3 ms
03:56:28.377324 read(..., 16777216)   +66.5 ms
blocksize_16 *with* the prefetch thread was 65.9 ms / 255 MB/s. Identical within noise, so the prefetching thread isn't buying anything on this path.

blocksize_32: ~218 MB/s, averaging 148.6 ms per read but ranging 137-170 ms. A regression from 16 MiB and noticeably less stable, so 32 MiB is past the optimum here even though it was the sweet spot on macOS.

blocksize_1: 190-192 MB/s, and this is the one that answers the alternation question. Three fast reads then one slow, repeating every four reads:
+4.06  +4.02  +4.04   +9.16
+4.04  +4.02  +3.99   +9.74
+3.94  +3.91  +3.89   +9.73
+3.92  +3.90  +3.91  +11.72
Four reads = 4 MiB per 21.5 ms = 195 MB/s, matching the measured rate. That 4 MiB period holds at every buffer size - at 2 MiB it was one fast and one slow alternating, at 4 MiB every read took the full time so it looked uniform.

Everything so far, normalised to time per 4 MiB:
 1 MiB             21.5 ms   195 MB/s
 2 MiB             21.1 ms   199 MB/s
 4 MiB             21.0 ms   200 MB/s
 8 MiB             18.0 ms   233 MB/s
16 MiB             16.5 ms   255 MB/s
16 MiB no threads  16.6 ms   253 MB/s
32 MiB             18.6 ms   226 MB/s
4 MiB is exactly the rsize on this mount, so I remounted with rsize=16777216 and tested with plain dd:
dd bs=1M, rsize=4M     189 MB/s   3 fast + 1 slow, every 4 MiB
dd bs=1M, rsize=16M    262 MB/s   uniform 4.0 ms gaps, no periodicity
I also ran dd writing to the real destination rather than /dev/null, in case the writing was causing the stall: 258 MB/s, still uniform. So it isn't the writing, and at a large enough rsize the stall disappears entirely even with 1 MiB reads.

But FreeFileSync on that same mount with the same 1 MiB buffer doesn't behave like dd. It oscillates: ~190 MB/s for the first 20 seconds, up to ~268 around the 50 second mark, then back to ~190 for the rest of the run. strace during a slow phase shows the 4 MiB period is back:
04:27:28.898196 read(..., 1048576)
04:27:28.902083 read(..., 1048576)   +3.89 ms
04:27:28.905979 read(..., 1048576)   +3.90 ms
04:27:28.915667 read(..., 1048576)   +9.69 ms
04:27:28.919603 read(..., 1048576)   +3.94 ms
04:27:28.923493 read(..., 1048576)   +3.89 ms
04:27:28.927411 read(..., 1048576)   +3.92 ms
04:27:28.938266 read(..., 1048576)  +10.86 ms
So with the mount, the read size and the destination all identical, dd holds 262 MB/s steadily while FreeFileSync keeps collapsing into the slow pattern and climbing back out.

The difference between them is how the reads are issued: dd reads sequentially on one thread, FFS reads on the prefetch thread with writes going out on another fd. That looks like it disturbs the kernel's sequential readahead detection, which then has to re-ramp - which would explain the sawtooth rather than a steady rate. It also fits the buffer-size results, since the bigger the read the fewer chances there are for that reset, which is why 8 and 16 MiB looked better on the default rsize.

One last thing that ties it together. My patched build with two pread() threads at different offsets holds ~293-297 MB/s steadily, at any chunk size from 2 MiB up - 2 MiB with two readers gives the same as 64 MiB with two readers. That makes sense if the parallel version isn't avoiding the stall but covering it: when one reader hits the slow path the other is already on the wire, so the link never goes idle. Single-threaded there's nothing to cover it, so the only lever is a bigger buffer, which just makes the stalls rarer relative to the bytes moved.

Practical note for anyone else hitting this: remounting with a larger rsize took dd from 189 to 262 MB/s on this share by itself, with no change to FreeFileSync at all.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Ugh. Correction to my last post - the rsize finding was wrong, please disregard it.
I'm still fine tuning the benchmark process.


I retested properly and rsize makes no difference. Same mount point, same file, dd bs=1M, only rsize changing, and this time reading untouched regions of the file so neither run could be served from the NAS's cache:
rsize=16M, offset 20 GB    183 MB/s
rsize=4M,  offset 25 GB    187 MB/s
Identical within noise.

What went wrong the first time: both of those earlier dd runs read the first 300 MB of the file, which I'd already read repeatedly during the session, and the NAS has 16 GB of RAM. So the 262 MB/s run was being served from the server's cache rather than off the USB disk. That also explains why the periodic stall disappeared in it - cached reads have no disk fetch to stall on. Two symptoms, one cause, and nothing to do with rsize.

So the 4 MiB period matching the rsize value looks like coincidence, and the mount option suggestion at the end of that post should be ignored.

The rest of that post stands - the build comparisons were all full 35 GB file copies, well beyond the NAS's RAM, so those aren't cache artifacts. Same for the ~293-297 MB/s from the two-reader patched build, which holds across full files and a 64 GB multi-file run, with pv getting 279 MiB/s on the same file.

Apologies for the noise. Lesson learned on 300 MB samples against a NAS with that much RAM.
User avatar
Site Admin
Posts: 7588
Joined: 9 Dec 2007

Zenju

rsize=16M, offset 20 GB    183 MB/s
rsize=4M,  offset 25 GB    187 MB/s
ciggy, 24 Nov 2026, 10:50
These perf numbers look like the "FreeFileSync 14.13 (Linux)" measurement in the initial post. I'm wondering if the "faster" test cases were perhaps just cases of the NAS having the file in its buffer:
Measurements (same file, page cache dropped before each run):
dd bs=16M                     ~280 MB/s
Dolphin (KDE)                 ~280 MB/s
pv file > dest                ~282 MB/s
ciggy, 19 Nov 2026, 09:01
Maybe the real bottleneck all this time was not the network, but the USB storage. But why would multiple threads improve access speed? Is QNAP TS-451+ able to serve multiple read requests in parallel!? IOW does it implement some kind of RAID 0?

In any case, the minimum goal for FreeFileSync should be - if not already the case - to match the speed of single-threaded "dd" or "cp" commands.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Good question, and I owe you a clear answer on the cache issue, since I raised it.

What I meant before: in my correction I put the earlier 262 MB/s dd result down to the NAS serving data from its RAM. That run re-read the first 300 MB of a file I'd read many times, and the NAS has 16 GB of RAM, so I assumed those blocks came from the NAS's cache instead of the drive. I didn't verify it at the time. The NAS does cache recently read data (see below), so that's plausible, but a cold dd bs=16M also gets ~262, so I can't say now which it was. Either way, rsize made no difference (183 vs 187 MB/s at the same block size).

To settle it, I ran a cold-cache test:

- File: 36.8 GiB disk image on the share (NVMe SSD in a USB 3.1 enclosure on the NAS's USB 3.1 port).
- Before every run, I dropped the page cache on both the client and the NAS (echo 3 > /proc/sys/vm/drop_caches on each, the NAS via ssh).
- NAS memory from free -m, in MB:
                          total   used   free  shared  buffers  cached
test 1, before flush      15898   2478  13420     319       17     674
test 1, after flush       15898   2411  13487     319        7     619
test 2, before flush      15898   8681   7216     319       26    6880
test 2, after flush       15898   2357  13541     319        4     577
The 6880 MB before test 2 is the data test 1 had just read, so the NAS does cache file data.

- Each run read 7 GiB to /dev/null. For the two-reader case, two dd processes ran at the same time on separate 3 GiB regions (24 and 28 GiB), and I'm reporting their combined throughput.
- Test 2 repeated test 1 with the regions rotated, to rule out the file position affecting the result. Two passes each. dd's decimal MB/s:
                           test 1 (offset)    pass 1  pass 2   test 2 (offset)    pass 1  pass 2
dd bs=128K                 0 GiB                 158     158   8 GiB                 159     159
dd bs=1M                   8 GiB                 198     197   16 GiB                197     197
dd bs=16M                  16 GiB                263     262   0 GiB                 261     263
2x dd bs=1M (concurrent)   24 + 28 GiB           286     287   24 + 28 GiB           286     286

FFS 14.13 stock (1 MiB reads, full 35 GB copy): 190-195
Answers to your points:

1. You're right that the numbers look like FFS. Single-threaded dd with 1 MiB reads gets 197-198 MB/s, the same as FFS. So FFS already matches dd at the same read size. dd is only faster with larger reads.

2. It isn't the NAS cache. Every run above was cold on both ends, and the results repeat within 2 MB/s across passes and region rotation.

3. It isn't the USB storage either. The same drive delivers 262 MB/s to one 16 MiB stream and 286 MB/s to two 1 MiB streams. A single stream at 1 MiB leaves most of that unused.

4. No RAID. It's a single NVMe drive. My reading is that a single reader is limited by per-request latency (network round trip plus SMB processing on the NAS): larger application reads, or a second reader running at the same time, keep more data moving while each request waits. I haven't captured the actual SMB traffic, so this is an interpretation that fits the numbers, not a measurement.

One correction to my 19 Nov post: the ~280 MB/s figures there (dd bs=16M, Dolphin, pv) were not measured with the NAS cache flushed. Cold, dd bs=16M gets ~262 MB/s here. I didn't retest Dolphin or pv.

For your minimum goal of matching single-threaded dd/cp: FFS matches dd at 1 MiB. To match dd's best single-stream result, FFS would need larger reads on network filesystems. A 16 MiB single-reader FFS build got 250-258 MB/s on full-file copies, close to dd's 262. Going beyond that needs more than one read in flight. I'm happy to test any build you want.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

The two code tables in my last post didn't line up in the forum, so here are the same numbers as a chart:
cold-cache-tests.png
Part 1 is the NAS cache ("cached" column of free -m) before and after the flush for each test. Part 2 is every dd run: two tests, two passes each, with test 2 reading from rotated file offsets. All four runs for each block size are within 2 MB/s of each other.
You do not have the required permissions to view the files attached to this post.
User avatar
Posts: 18
Joined: 11 Sep 2024

ciggy

Follow-up with a comparison that changes the picture. I copied the same 36.8 GiB image to a share on the NAS's internal RAID 0 array (3 x 2 TB WD spinning drives) and ran the identical cold-cache script against it: client and NAS cache dropped before every run, two passes, then again with the regions rotated. I also copied the full file from the RAID 0 share to local NVMe with stock FreeFileSync 14.13 Donation Edition (1 MiB reads), both caches dropped first: 39.5 GB in 2:20 = 282 MB/s. Same file from the USB share: 190-195 MB/s.
usb-vs-raid0-all.png
So you were right that the storage matters, and I need to correct my point 3. FFS already matches single-threaded dd on normal storage. On the RAID 0 share a single 1 MiB reader reaches ~285 MB/s, about what 2.5 GbE carries, so the client, network and Samba handle 1 MiB reads fine. The ~195 MB/s limit is specific to the USB-attached share. Notably, three spinning disks behind the NAS's internal controller beat an NVMe SSD behind its USB port for a single 1 MiB reader, which points at the USB path rather than the drive itself.

I also straced FFS for 10 s during the RAID 0 copy: 2,811 reads of 1 MiB. About 2,330 returned in 0.1-0.6 ms; the rest waited ~14 ms, ~28 ms or ~42 ms, and each ~14 ms of waiting accounts for 4 MiB (the totals add up to the 2,811 MiB read). 14 ms is the 2.5 GbE wire time for 4 MiB. So the "3 fast + 1 slow per 4 MiB" pattern I reported earlier on the USB share also happens on RAID 0. It isn't a stall: the client fetches 4 MiB at a time and FFS waits for each chunk. On RAID 0 the wait is just wire time; on the USB share each chunk takes longer to arrive, so the wait grows. The USB share's bandwidth isn't the limit (262 MB/s with 16 MiB reads, 286 with two readers), so it looks like high per-request latency that larger reads or a second reader hide. That's an interpretation; I haven't measured it on the NAS side.

The remaining question is whether it's worth larger reads or a second read in flight on network shares, to cover slow-per-request backends like USB disks behind a NAS. My patched build does the second, and it gets 293-297 MB/s from the USB share.

One oddity: in the rotated run, 128K reads from the 8 GiB region of the RAID 0 copy got 238-244 MB/s instead of 287-288, while 1M reads from that region were full speed. I don't know why; it doesn't change the above.
You do not have the required permissions to view the files attached to this post.