Skip to content

Instantly share code, notes, and snippets.

@othyn
Last active December 25, 2024 17:49
Show Gist options
  • Save othyn/4554c1f409f34d1674ba2095acf441ee to your computer and use it in GitHub Desktop.
Save othyn/4554c1f409f34d1674ba2095acf441ee to your computer and use it in GitHub Desktop.
Fix horrendously bad macOS (12.3.1 tested) SMB (Samba) performance on Unraid

Intro

Out of the box, my SMB performance on macOS 12.3.1 would top out at around 20MB/s in short ~5 second bursts, which was absolutely horrendous, slow to navigate in Finder and slugish to interact with.

Since making these changes, I now get sustained ~80-100MB/s+ and instant Finder navigation which is superb and how things should be out-of-the-box (OOTB)!

May 2023 update: As of Ventura, the SMB issues were just horribly inconsistent and hard to maintain. Something in the combination of Unraid, macOS and SMB just doesn't play nice. I ended up binning NFS/SMB all together and heading to a locally hosted Nextcloud instance for file syncing, then using SFTP/Ansible Git flow for editing files within appdata.

Sources

  1. Apple - Disable local SMB directory enumeration caching
  2. Apple - Adjust SMB browsing behavior in macOS
  3. 45Drives - KB450114 – MacOS Samba Optimization
  4. Unraid Forum - Maxrad Post (the absolute legend)

Guide

macOS Changes

  1. Prevent macOS writing ._DS_Store files to SMB shares (Source #2), just enter the following into your mac's terminal:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
  1. Configure macOS to disable directory caching (Source #1) and request signing/verification (Source #3), the following should be the contents of the existing /etc/nsmb.conf file if you have it, or create it if you don't (may require sudo):
[default]
dir_cache_max_cnt=0
signing_required=no
  1. After a reboot, run $ smbutil statshares -a in a terminal window in macOS whilst connected to your SMB shares. The commands output should NOT contain SIGNING_ON TRUE (Source #3).

Unraid / SMB (Samba) Changes

  1. On your Unraid box, login to the web GUI and stop your array.

  2. Head to: Settings > SMB > SMB Extras > Samba Extra Configuration.

  3. Paste the following into the text field (Source #4), making sure to edit "MY_SHARE" to be the name of your share and cloning that block for any more shares that you may have, in this case also renaming or removing "MY_OTHER_SHARE" to meet your needs.

#unassigned_devices_start
#Unassigned devices share includes
   include = /tmp/unassigned.devices/smb-settings.conf
#unassigned_devices_end

[global]
   vfs objects = catia fruit streams_xattr
   fruit:nfs_aces = no
   fruit:zero_file_id = yes
   fruit:metadata = stream
   fruit:encoding = native
   spotlight backend = tracker

[MY_SHARE]
   path = /mnt/user/MY_SHARE
   veto files = /._*/.DS_Store/
   delete veto files = yes
   spotlight = yes

[MY_OTHER_SHARE]
   path = /mnt/user/MY_OTHER_SHARE
   veto files = /._*/.DS_Store/
   delete veto files = yes
   spotlight = yes
  1. Hit Apply once done in which Unraid will then apply the SMB configuration.

  2. Before starting the array again, run $ testparm -s in the Unraid web GUI terminal or via SSH'ing onto your Unraid box, this is to ensure that all is working and Samba has accepted the configuration. It should look something like the following, just with your share names instead of the example ones and should have no errors:

Load smb config files from /etc/samba/smb.conf
lpcfg_do_global_parameter: WARNING: The "null passwords" option is deprecated
Loaded services file OK.
Weak crypto is allowed

Server role: ROLE_STANDALONE

# Global parameters
[global]
	disable netbios = Yes
	disable spoolss = Yes
	load printers = No
	logging = syslog@0
	map to guest = Bad User
	multicast dns register = No
	ntlm auth = ntlmv1-permitted
	null passwords = Yes
	passdb backend = smbpasswd
	printcap name = /dev/null
	security = USER
	server min protocol = SMB2
	server string = Network Attached Storage
	show add printer wizard = No
	unix extensions = No
	fruit:zero_file_id = yes
	fruit:nfs_aces = no
	fruit:encoding = native
	fruit:locking = none
	fruit:metadata = stream
	fruit:resource = file
	fruit:aapl = yes
	idmap config * : range = 3000-7999
	idmap config * : backend = tdb
	acl allow execute always = Yes
	aio read size = 0
	aio write size = 0
	create mask = 0777
	directory mask = 0777
	hide dot files = No
	include = /tmp/unassigned.devices/smb-settings.conf
	invalid users = root
	map archive = No
	map readonly = yes
	spotlight backend = tracker
	use sendfile = Yes
	vfs objects = catia fruit streams_xattr
	wide links = Yes


[MY_SHARE]
	delete veto files = Yes
	path = /mnt/user/MY_SHARE
	spotlight = Yes
	veto files = /._*/.DS_Store/

[MY_OTHER_SHARE]
	delete veto files = Yes
	path = /mnt/user/MY_OTHER_SHARE
	spotlight = Yes
	veto files = /._*/.DS_Store/
  1. Start the array and connect the macOS client to the SMB share and test that its working nicely, maybe do some test copies and check that the performance is what you expect.

  2. Done!

@denizdogan
Copy link

Any ideas when it comes to macOS Ventura 13.3, combined with UnRAID 6.11.5? I haven't been able to get SMB shares to work well since UnRAID 6.10.x.

@othyn
Copy link
Author

othyn commented May 6, 2023

I gave up with SMB on macOS with Unraid, I could never get it working right, despite the best efforts on the Unraid forum/reddit to come up with solutions. No idea what the particular issues are between Unraid, macOS and SMB but something about that combination just isn't right or reliable.

I ended up using NFS for a while before switching completely to setting up a Nextcloud instance and share within Unraid for it to run off, then disabling NFS/SMB all together. This worked better for my use case anyway, as having a private iCloud style sync mechanism was good. Then for things like editing the appdata share, I just SFTP files across with a client like CyberDuck or just using scp.

@denizdogan
Copy link

@othyn Thanks, I appreciate it. I will look into Nextcloud, good idea.

@othyn
Copy link
Author

othyn commented May 6, 2023

@denizdogan glad to help! I ended up finding the most success with the LinuxServer image for Nextcloud:

https://github.com/linuxserver/docker-nextcloud

@thomasbertok
Copy link

After a minor update it panicked all the time, ventura only.
I managed to get it working by commenting out all vfs settings for the shares. Ventura, 13.3.1 and natively installed samba on a linuxmint20. probably temporary solution.

@ylallemant
Copy link

ylallemant commented Aug 6, 2023

thanks for your gist...
adding protocol_vers_map=6 fixed the issue for me on a 2023 M2 with Ventura

here my complete /etc/nsmb.conf file content :

[default]
protocol_vers_map=6
dir_cache_max_cnt=0
signing_required=no

@superKoder
Copy link

superKoder commented Aug 15, 2023

August 2023 on macOS Ventura 13.5 and Unraid 6.12.3

I tried everything in @othyn's original post, as well as @ylallemant's valuable addition. But it was still not great. Then I noticed:

$ smbutil multichannel -a
...
Server NIC:
	name: NA, idx: 1, type:    NA, speed 1.0 Gb, state connected
		ip_addr: ##redacted###

Client NIC:
	name: en0, idx: 15, type: wireless, speed 73.9 Mb, state connected
		ip_addr: ##redacted##

Notice that "73.9 Mb" on the client connection! I thinks my WiFi 6E connection is that bad. But what is worse, I should be connected over wired ethernet!

Simply adding an additional mc_prefer_wired=yes to the /etc/nsmb.conf did the trick for me! 🥳

So my entire /etc/nsmb.conf now looks like:

[default]
protocol_vers_map=6
dir_cache_max_cnt=0
signing_required=no
mc_prefer_wired=yes

And while I still have @othyn's changes on my Unraid as well, I don't think I need those anymore. Because I only have it on one of my shares, and all shares now perform equally better as far as I can tell.

Thanks to everyone above for leading me to this!

@asmaier
Copy link

asmaier commented Nov 28, 2023

I found a a nsmb.conf that really worked for me: https://gist.github.com/jbfriedrich/49b186473486ac72c4fe194af01288be . The most important option turned out to be dir_cache_off=yes .

@eliu9395
Copy link

eliu9395 commented Sep 2, 2024

@superKoder what is your speed after you did that? I added those settings to nsmb.conf but I still see the same speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment