Address two problems with sendfile(..., SF_NOCACHE) and apply one
authoralc <alc@FreeBSD.org>
Fri, 13 Oct 2017 16:31:50 +0000 (16:31 +0000)
committeralc <alc@FreeBSD.org>
Fri, 13 Oct 2017 16:31:50 +0000 (16:31 +0000)
commite64f2e093061f03616ea484880e36113d8bcfde7
tree576a513fc9ccedbc2076e4ef691a1cc049edecad
parent7f820352770e424585fc5422f0117dbe6c5c98d8
Address two problems with sendfile(..., SF_NOCACHE) and apply one
"optimization".  First, sendfile(..., SF_NOCACHE) frees pages without
checking whether those pages are mapped.  This can leave the system
with mappings to free or repurposed pages.  Second, a page can be
busied between the time of the current busy test and acquiring the
object lock.  Essentially, the test performed before the object lock
is acquired can only be regarded as an optimization to short-circuit
further work on the page.  It cannot, however, be relied upon to prove
that it is safe to free the page.  Third, when sendfile(..., SF_NOCACHE)
was originally implemented, vm_page_deactivate_noreuse() did not yet
exist.  Use vm_page_deactivate_noreuse() instead of vm_page_deactivate(),
because it comes closer to freeing the page.

In collaboration with: glebius
Discussed with: gallatin, kib, markj
X-MFC after: r324448
sys/kern/kern_sendfile.c