Why does Apache recommend against using sendfile() with NFS on Linux

Viewed 3383

The Apache documentation includes this statement for EnableSendfile:

With a network-mounted DocumentRoot (e.g., NFS, SMB, CIFS, FUSE), the kernel may be unable to serve the network file through its own cache.[1]

The default configuration for Apache 2.4 and Nginx disables sendfile().

I'm trying to find something concrete that describes what the exact problem is when using sendfile() with NFS filesystems on Linux. Running a minimal test program on kernel 3.10.0-327.36.3 (CentOS 7) verifies that sendfile() does work when the source is on NFS, and it does read from the page cache (first time run is slow, subsequently fast, drop_caches to make it slow again, i.e. re-read from source). I tried with file sizes up to 1G and everything seemed to work OK. I'm assuming there must be some set of circumstances that reveals buggy behaviour, but I'd like to know exactly what that is.

For comparison, there's some documentation out there about the problems VirtualBox volumes have with sendfile()[2], but I can't find something similar covering Apache, or how to replicate a problematic configuration.

2 Answers

I think that I see where some confusion may arise with Nginx.

The Nginx documentation says the following at https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/:

"By default, NGINX handles file transmission itself and copies the file into the buffer before sending it. Enabling the sendfile directive eliminates the step of copying the data into the buffer and enables direct copying data from one file descriptor to another."

This makes it sound like Nginx doesn't use sendfile by default.

However, as noted in this answer, the default configuration file for Nginx explicitly turns on sendfile support for the out-of-the-box HTTP server as seen at https://github.com/nginx/nginx/blob/master/conf/nginx.conf.

Related