Index: sys/kern/kern_sendfile.c =================================================================== --- sys/kern/kern_sendfile.c +++ sys/kern/kern_sendfile.c @@ -409,18 +409,11 @@ count = min(a + 1, npages - i); /* - * We should not pagein into a valid page, thus we first trim - * any valid pages off the end of request, and substitute - * to bogus_page those, that are in the middle. + * We should not pagein into a valid page because + * there might be still unfinished write tracked by + * e.g. a buffer, thus we substitute any valid pages + * with the bogus one. */ - for (j = i + count - 1; j > i; j--) { - if (vm_page_is_valid(pa[j], vmoff(j, off) & PAGE_MASK, - xfsize(j, npages, off, len))) { - count--; - rhpages = 0; - } else - break; - } for (j = i + 1; j < i + count - 1; j++) if (vm_page_is_valid(pa[j], vmoff(j, off) & PAGE_MASK, xfsize(j, npages, off, len))) { Index: sys/kern/vfs_bio.c =================================================================== --- sys/kern/vfs_bio.c +++ sys/kern/vfs_bio.c @@ -5154,12 +5154,16 @@ br_flags = (mp != NULL && (mp->mnt_kern_flag & MNTK_UNMAPPED_BUFS) != 0) ? GB_UNMAPPED : 0; again: - for (i = 0; i < count; i++) - vm_page_busy_downgrade(ma[i]); + for (i = 0; i < count; i++) { + if (ma[i] != bogus_page) + vm_page_busy_downgrade(ma[i]); + } lbnp = -1; for (i = 0; i < count; i++) { m = ma[i]; + if (m == bogus_page) + continue; /* * Pages are shared busy and the object lock is not @@ -5228,6 +5232,8 @@ redo = false; for (i = 0; i < count; i++) { + if (ma[i] == bogus_page) + continue; if (vm_page_busy_tryupgrade(ma[i]) == 0) { vm_page_sunbusy(ma[i]); ma[i] = vm_page_grab_unlocked(object, ma[i]->pindex,