kernel change notify = yes

Status
Not open for further replies.

SFoskett

Dabbler
Joined
Jul 28, 2016
Messages
37
I've had a bit of an issue with CIFS shares not updating as new files are added. For example, if I SCP a video file from one machine to another, it will not show up in clients connected via SMB/Samba (what FreeNAS still calls CIFS). The same is true if I ssh to the FreeNAS machine and move or remove a file, or if I update a directory with rsync.

Essentially, Samba isn't getting the message that the underlying filesystem has changed outside its domain. And it never gets the message unless I log out and back in. I literally have days-old file ghosts sitting there.

This is a long-standing issue with Samba (I've been using it since the 1990's!) since it maintains its own cache of directory contents. There are a number of options to tune its behavior, including the classic "refresh = 1" flag which is set by default in FreeNAS. This does not fix my issue, however.

Recent releases of Samba have a new option: "kernel change notify = yes". This allows the kernel to notify Samba when directory contents have changed. This should completely resolve this issue, but there are instances of it causing problems in FreeBSD, including high CPU usage for smbd and general instability.

"kernel change notify = no" is the default in FreeNAS. To see if it would help, I changed this to "yes" on my system. It immediately cured my issue, with moves and copies showing up almost instantly. However, I am concerned about leaving it on, since my FreeNAS hasn't been all that stable to begin with.

There are client-side tweaks that are often recommended, but these are not acceptable for me. First, most eliminate the inherent caching benefits added to SMB2.0, which is quite inelegant. Second, I'm all-Mac, so those tweaks don't exist.

Any thoughts on kernel change notify?
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
I've had a bit of an issue with CIFS shares not updating as new files are added. For example, if I SCP a video file from one machine to another, it will not show up in clients connected via SMB/Samba (what FreeNAS still calls CIFS). The same is true if I ssh to the FreeNAS machine and move or remove a file, or if I update a directory with rsync.

Essentially, Samba isn't getting the message that the underlying filesystem has changed outside its domain. And it never gets the message unless I log out and back in. I literally have days-old file ghosts sitting there.

This is a long-standing issue with Samba (I've been using it since the 1990's!) since it maintains its own cache of directory contents. There are a number of options to tune its behavior, including the classic "refresh = 1" flag which is set by default in FreeNAS. This does not fix my issue, however.

Recent releases of Samba have a new option: "kernel change notify = yes". This allows the kernel to notify Samba when directory contents have changed. This should completely resolve this issue, but there are instances of it causing problems in FreeBSD, including high CPU usage for smbd and general instability.

"kernel change notify = no" is the default in FreeNAS. To see if it would help, I changed this to "yes" on my system. It immediately cured my issue, with moves and copies showing up almost instantly. However, I am concerned about leaving it on, since my FreeNAS hasn't been all that stable to begin with.

There are client-side tweaks that are often recommended, but these are not acceptable for me. First, most eliminate the inherent caching benefits added to SMB2.0, which is quite inelegant. Second, I'm all-Mac, so those tweaks don't exist.

Any thoughts on kernel change notify?

kernel change notify is set to "no" because in 9.2.1.3 it was causing smbd processes to spool up to 100% and consume all available system resources eventually resulting in the server crashing and requiring pressing the physical reset button.

That said, you shouldn't need that parameter for files to become visible. I routinely copy files to samba shares via SCP. Perhaps try hitting "F5" in your client?
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
There are client-side tweaks that are often recommended, but these are not acceptable for me. First, most eliminate the inherent caching benefits added to SMB2.0, which is quite inelegant.

smb2 leases are experimental and disabled by default in the version of Samba that ships with FreeNAS. They were only enabled by default in samba's master branch (I believe Samba 4.5) less than a month ago - https://github.com/samba-team/samba/commit/dd10c820aab1c04f079c0d0f41dc176fdd5545c4.

I am also fairly certain that "kernel change notify" will not allow other Unix processes to take advantage of smb2 leases. In fact, "smb2leases=yes" requires "kernel oplocks=no", which implies less compatibility between samba and other Unix processes than is achievable when just using older SMB1-style oplocks.
 

SFoskett

Dabbler
Joined
Jul 28, 2016
Messages
37
That said, you shouldn't need that parameter for files to become visible. I routinely copy files to samba shares via SCP. Perhaps try hitting "F5" in your client?

Is there a Mac OS X equivalent of "F5"? Apparently not, and this issue has been reported by other El Capitan users with Samba. There are workarounds, though, including a script and third-party tool. Perhaps this is an Apple issue then.

Note that the next version of OS X will be SMB2-primary, with AFP deprecated. So this might be more of a problem in the future.
 

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
Is there a Mac OS X equivalent of "F5"? Apparently not, and this issue has been reported by other El Capitan users with Samba. There are workarounds, though, including a script and third-party tool. Perhaps this is an Apple issue then.
Wow, I am not a MAC User but if I was I would find that very annoying. What about just navigating one folder up or down and then back again? Would that essentially refresh the contents?
 

SFoskett

Dabbler
Joined
Jul 28, 2016
Messages
37
Wow, I am not a MAC User but if I was I would find that very annoying. What about just navigating one folder up or down and then back again? Would that essentially refresh the contents?
Alas, this does not generally refresh a shared directory. The common "solutions" are to log out and back in to the file server or restart Finder. Neither of these are particularly user-friendly.
  • The "official" answer is that Finder will refresh the share view when you move out and back into a folder as you suggest. But this often does not work.
  • Another common suggestion is to add or delete an item from the folder, which is obviously sub-optimal.
  • Here's an AppleScript that can force a single-window refresh (and can be added to Finder as a button): http://apple.stackexchange.com/questions/49543/is-there-a-way-to-refresh-a-finder-file-listing
  • There are also a few third-party applications which do it, but I'm not linking to those from here.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Are you running 10.11.6? Apple claims to have fixed some SMB issues in 10.11.6.
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
For more information regarding "kernel change notify" / inotify see here: https://bugzilla.samba.org/show_bug.cgi?id=11063

It's an issue with FreeBSD's kqueue not providing sufficient events when watching a directory. Only file rename or delete within a directory trigger notifications, but not file modifications. Therefor libinotify, which provides the inotify compatible API on FreeBSD and which uses the kernel kqueue facility, additionally adds monitors to every file in a monitored directory.

As an alternative to inotify API based libinotify, you could check whether Samba can be built with FAM/gamin support on FreeBSD instead. Possibly gamin does this differently then libinotify. If not, either gamin or libinotify could be tweaked to provide some sort of inotify API extension that request only FILE_CREATED, FILE_DELETED, FILE_RENAMED events when monitoring a directory.

By setting "kernel change notify = no" Samba will still distribute file events done by smbd processes, but you won't get notification for local changes, NFS or other protocols.

So in principle there is a way to fix this. Any takers? :D
 

Metis IT

Dabbler
Joined
Oct 10, 2016
Messages
11
anyone any update on "kernel change notify" with 11.2 being out? Should it still be disabled?
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
anyone any update on "kernel change notify" with 11.2 being out? Should it still be disabled?
This is probably an example of why I should have closed out this account when I started working for iX (these posts were pre-iX and when I was a quite a bit more ignorant). :)

Yes. It should still be disabled. Samba will still distribute file events done by smbd processes. You just lose out on notifications for changes outside of Samba, but I'm happy to look into it if it's something you need for something in particular. Just file a feature request with an explanation of use-case here: https://redmine.ixsystems.com/
 
Last edited:
Status
Not open for further replies.
Top