Make Samba Go Faster

Make Samba Go Faster

After installing a wired gigabit network in my house I tested the performance in the network using shares (Windows – samba installed centos 7). I got around 500-600MBit/sec in read speeds and about 600-700MBit/sec in write speeds. But why ?

After looking at the samba configuration file I saw that Async IO (AIO) was not enabled by default. What AIO does is that it let’s Samba handle several file operations asynchronously. This can, at the expense of some CPU cycles, increase the performance quite a lot.

I increased the read speed to 500-600+MBit/sec by enabling AIO and saw Samba using around 1-4% CPU on a Intel Pentium G (Haswell).

 

Enable AIO

To enable AIO an you can add the following to the global section of your /etc/samba/smb.conf file

Text
​socket options=SO_RCVBUF=131072 SO_SNDBUF=131072 TCP_NODELAY min receivefile size = 16384 use sendfile = true aio read size = 16384 aio write size = 16384 aio write behind = true 

This is only an example but you can tweak all the options to fit your environment and needs. Bellow are an explanation of the options used above. More information can be found at http://www.samba.org

 

 

Options Explained

min receivefile size

This option changes the behavior of Samba when processing SMBwriteX calls. Any incoming SMBwriteX call on a non-signed SMB/CIFS connection greater than this value will not be processed in the normal way but will be passed to any underlying kernel recvfile or splice system call (if there is no such call Samba will emulate in user space). This allows zero-copy writes directly from network socket buffers into the filesystem buffer cache, if available. It may improve performance but user testing is recommended. If set to zero Samba processes SMBwriteX calls in the normal way. To enable POSIX large write support (SMB/CIFS writes up to 16Mb) this option must be nonzero. The maximum value is 128k. Values greater than 128k will be silently set to 128k.

use sendfile

If this parameter is yes, and the sendfile() system call is supported by the underlying operating system, then some SMB read calls (mainly ReadAndX and ReadRaw) will use the more efficient sendfile system call for files that are exclusively oplocked. This may make more efficient use of the system CPU’s and cause Samba to be faster. Samba automatically turns this off for clients that use protocol levels lower than NT LM 0.12 and when it detects a client is Windows 9x (using sendfile from Linux will cause these clients to fail).

socket options

This option allows you to set socket options to be used when talking with the client.

Socket options are controls on the networking layer of the operating systems which allow the connection to be tuned.

This option will typically be used to tune your Samba server for optimal performance for your local network. There is no way that Samba can know what the optimal parameters are for your net, so you must experiment and choose them yourself. We strongly suggest you read the appropriate documentation for your operating system first (perhaps man setsockopt will help).

Any of the supported socket options may be combined in any way you like, as long as your OS allows it.

This is the list of socket options currently settable using this option:

  • SO_KEEPALIVE
  • SO_REUSEADDR
  • SO_BROADCAST
  • TCP_NODELAY
  • IPTOS_LOWDELAY
  • IPTOS_THROUGHPUT
  • SO_SNDBUF *
  • SO_RCVBUF *
  • SO_SNDLOWAT *
  • SO_RCVLOWAT *

Those marked with a ‘*’ take an integer argument. The others can optionally take a 1 or 0 argument to enable or disable the option, by default they will be enabled if you don’t specify 1 or 0.

To specify an argument use the syntax SOME_OPTION = VALUE for example SO_SNDBUF = 8192. Note that you must not have any spaces before or after the = sign.

If you are on a local network then a sensible option might be:

Text
​socket options = IPTOS_LOWDELAY​

If you have a local network then you could try:

Text
​socket options = IPTOS_LOWDELAY TCP_NODELAY​

If you are on a wide area network then perhaps try setting IPTOS_THROUGHPUT.

Note that several of the options may cause your Samba server to fail completely. Use these options with caution!

aio read size

Samba will read from file asynchronously when size of request is bigger than this value. Note that it happens only for non-chained and non-chaining reads and when not using write cache.

aio write size

Samba will write to file asynchronously when size of request is bigger than this value. Note that it happens only for non-chained and non-chaining reads and when not using write cache.

aio write behind

Samba will not wait until write requests are finished before returning the result to the client for files listed in this parameter. Instead, Samba will immediately return that the write request has been finished successfully, no matter if the operation will succeed or not. This might speed up clients without aio support, but is really dangerous, because data could be lost and files could be damaged.