Why is Linux NFS server implemented in the kernel as opposed to userspace?
unfs3
is dead as far as I know; Ganesha is the most active userspace NFS server project right now, though it is not completely mature.
Although it serves different protocols, Samba is an example of a successful file server that operates in userspace.
I haven't seen a recent performance comparison.
Some other issues:
- Ordinary applications look files up by pathname, but
nfsd
needs to be able to look them up by filehandle. This is tricky and requires support from the filesystem (and not all filesystems can support it). In the past it was not possible to do this from userspace, but more recent kernels have addedname_to_handle_at(2)
andopen_by_handle_at(2)
system calls. - I seem to recall blocking file-locking calls being a problem; I'm not sure how userspace servers handle them these days. (Do you tie up a server thread waiting on the lock, or do you poll?)
- Newer file system semantics (change attributes, delegations, share locks) may be implemented more easily in kernel first (in theory--they mostly haven't been yet).
- You don't want to have to check permissions, quotas, etc., by hand--instead
you want to change your uid and rely on the common kernel vfs code to do
that. And Linux has a system call (
setfsuid(2)
) that should do that. For reasons I forget, I think that's proved more complicated to use in servers than it should be.
In general, a kernel server's strengths are closer integration with the vfs and the exported filesystem. We can make up for that by providing more kernel interfaces (such as the filehandle system calls), but that's not easy. On the other hand, some of the filesystems people want to export these days (like gluster) actually live mainly in userspace. Those can be exported by the kernel nfsd using FUSE--but again extensions to the FUSE interfaces may be required for newer features, and there may be performance issues.
Short version: good question!
Olaf Kirch originally developed both the user space and kernel based version of the NFS server. In his year 2000 book, "Linux Network Administration" he says:
The 2.2.0 kernel supports an experimental kernel-based NFS server developed by Olaf Kirch and further developed by H.J. Lu, G. Allan Morris, and Trond Myklebust. The kernel-based NFS support provides a significant boost in server performance.
I think that once the NFS server got moved into the kernel to improve performance, no-one saw any reason to take it out again.
Starnamer is correct (I was one of the beta testers).
Putting it in the kernel was an attempt to improve abysmal performance (mainly to PCNFS clients) and once that issue was solved noone looked at it much again.
There are a number of deficiencies with having NFS in the kernel, not least of which is that it doesn't play nicely with anything else touching the same filesystem (there are seriously nasty corruption risks) but back then (1993-4) we didn't realise that it would turn out to be an issue.
We were younger and more foolish, etc etc.