Skip to content

Instantly share code, notes, and snippets.

@joaomlneto
Last active July 13, 2023 06:29
Show Gist options
  • Save joaomlneto/74338ef17f3591f04ee20413b5b4a57e to your computer and use it in GitHub Desktop.
Save joaomlneto/74338ef17f3591f04ee20413b5b4a57e to your computer and use it in GitHub Desktop.
Fast NFS volume on macOS
#!/usr/bin/env bash
# mount /home/joaomlneto @ linux-vm
mkdir -p /Users/joaomlneto/nfs/linux-vm
mount -t nfs -o nolocks,locallocks,rw,soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp \
linux-vm:/home/joaomlneto \
/Users/joaomlneto/nfs/linux-vm
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/home/joaomlneto 192.168.25.0/24(rw,sync,no_subtree_check,insecure,no_root_squash,all_squash,anonuid=1000)
@joaomlneto
Copy link
Author

However, there is a huge problem with this: OS X does a phenominal amount of file locking (some would say, needlessly so) and has always been really sensitive to the configuration of locking on the NFS servers. So much so that if you randomly pick an NFS server in a large enterprise, true success is pretty unlikely. It'll succeed, but you'll keep getting messages indicating that the lock server is down, followed quickly by another message that the lock server is back up again. Even if you do get the NFS server tuned precisely the way that OS X wants it, performance sucks because of all the lock/unlock protocol requests that fly across the network. They clearly did something in Snow Leopard to aggravate this problem: it's now nasty enough to make NFS almost useless for me.

Fortunately, there is a fix: just turn off network locking. You can do it by adding the "nolocks,locallocks" options in the advanced options field of the Disk Utility NFS mounting UI, but this is painful if you do a lot of them, and doesn't help at all with /net. You can edit /etc/auto_master to add these options to the /net entry, but it doesn't affect other mounts - however I do recommend deleting the hidefromfinder option in auto_master. If you want to fix every automount, edit /etc/autofs.conf and search for the line that starts with AUTOMOUNTD_MNTOPTS=. These options get applied on every mount. Add nolocks,locallocks and your world will be faster and happier after you reboot.

https://forums.macrumors.com/threads/browsing-nfs-shares-extremely-slow-and-hang-finder.1518545/

@l2ysho
Copy link

l2ysho commented Nov 7, 2021

what is your OS version? I am on 11.6 and nolocks,locallocks arguments throws Invalid argument error.

@joaomlneto
Copy link
Author

@l2ysho At the time I wrote this, the latest macOS release was Mojave (10.14).
I haven't used this code since Catalina, so I'm not sure how to help you at this point :(

@faitno
Copy link

faitno commented Nov 24, 2021

Perfect!

@joaomlneto
Copy link
Author

@faitno what macOS version are you using? Does it work for you? :)

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