在树莓派4上用利用usb3的移动硬盘搭建好samba共享后,发现读取速度只有40M左右,写入速度只有30M左右,这比我预期的速度慢了许多,后面在samba官网文档看到了write cache size选项,开启后读取速度飙升到110M+,基本达到了千兆网络极限,虽然写入速度变化不大,对我来说也是很满意的。

在官方文档上,是这么介绍这个选项的:

If this integer parameter is set to non-zero value, Samba will create an in-memory cache for each oplocked file (it does not do this for non-oplocked files). All writes that the client does not request to be flushed directly to disk will be stored in this cache if possible. The cache is flushed onto disk when a write comes in whose offset would not fit into the cache or when the file is closed by the client. Reads for the file are also served from this cache if the data is stored within it.
    
This cache allows Samba to batch client writes into a more efficient write size for RAID disks (i.e. writes may be tuned to be the RAID stripe size) and can improve performance on systems where the disk subsystem is a bottleneck but there is free memory for userspace programs.
    
The integer parameter specifies the size of this cache (per oplocked file) in bytes.
    
Note that the write cache won’t be used for file handles with a smb2 write lease.
  
Default: write cache size = 0
    
Example: write cache size = 262144 # for a 256k cache size per file

大概就是说先在内存中缓存,到了指定大小再一次写入,以此提高samba性能,这个功能默认是关闭的,如果要开启的话需要在[global]节点下开启,比如write cache size = 262144,即设定缓存大小为256k。开启后读取效果提升显著。至于写入速度没有什么提升,我估计是树莓派或外接硬盘物理限制,尝试一些设置后依然如此,故此放弃。