aboutsummaryrefslogtreecommitdiff
path: root/sys/fs
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2015-12-16 21:30:45 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2015-12-16 21:30:45 +0000
commitb0cd20172d854584c67cd47461a77e98b43cbcd8 (patch)
treea77a93a364690da41fe0224812a20390e61cd88a /sys/fs
parentbd6c93e8bd5d442c75110e038db9d0d2ad36e37f (diff)
downloadsrc-b0cd20172d854584c67cd47461a77e98b43cbcd8.tar.gz
src-b0cd20172d854584c67cd47461a77e98b43cbcd8.zip
A change to KPI of vm_pager_get_pages() and underlying VOP_GETPAGES().
o With new KPI consumers can request contiguous ranges of pages, and unlike before, all pages will be kept busied on return, like it was done before with the 'reqpage' only. Now the reqpage goes away. With new interface it is easier to implement code protected from race conditions. Such arrayed requests for now should be preceeded by a call to vm_pager_haspage() to make sure that request is possible. This could be improved later, making vm_pager_haspage() obsolete. Strenghtening the promises on the business of the array of pages allows us to remove such hacks as swp_pager_free_nrpage() and vm_pager_free_nonreq(). o New KPI accepts two integer pointers that may optionally point at values for read ahead and read behind, that a pager may do, if it can. These pages are completely owned by pager, and not controlled by the caller. This shifts the UFS-specific readahead logic from vm_fault.c, which should be file system agnostic, into vnode_pager.c. It also removes one VOP_BMAP() request per hard fault. Discussed with: kib, alc, jeff, scottl Sponsored by: Nginx, Inc. Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=292373
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/fuse/fuse_vnops.c46
-rw-r--r--sys/fs/nfsclient/nfs_clbio.c22
-rw-r--r--sys/fs/smbfs/smbfs_io.c40
-rw-r--r--sys/fs/tmpfs/tmpfs_subr.c3
4 files changed, 46 insertions, 65 deletions
diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c
index 12b97781dd07..50318647a2f5 100644
--- a/sys/fs/fuse/fuse_vnops.c
+++ b/sys/fs/fuse/fuse_vnops.c
@@ -1753,6 +1753,10 @@ fuse_vnop_getpages(struct vop_getpages_args *ap)
cred = curthread->td_ucred; /* XXX */
pages = ap->a_m;
count = ap->a_count;
+ if (ap->a_rbehind)
+ *ap->a_rbehind = 0;
+ if (ap->a_rahead)
+ *ap->a_rahead = 0;
if (!fsess_opt_mmap(vnode_mount(vp))) {
FS_DEBUG("called on non-cacheable vnode??\n");
@@ -1761,26 +1765,21 @@ fuse_vnop_getpages(struct vop_getpages_args *ap)
npages = btoc(count);
/*
- * If the requested page is partially valid, just return it and
- * allow the pager to zero-out the blanks. Partially valid pages
- * can only occur at the file EOF.
+ * If the last page is partially valid, just return it and allow
+ * the pager to zero-out the blanks. Partially valid pages can
+ * only occur at the file EOF.
+ *
+ * XXXGL: is that true for FUSE, which is a local filesystem,
+ * but still somewhat disconnected from the kernel?
*/
-
VM_OBJECT_WLOCK(vp->v_object);
- fuse_vm_page_lock_queues();
- if (pages[ap->a_reqpage]->valid != 0) {
- for (i = 0; i < npages; ++i) {
- if (i != ap->a_reqpage) {
- fuse_vm_page_lock(pages[i]);
- vm_page_free(pages[i]);
- fuse_vm_page_unlock(pages[i]);
- }
+ if (pages[npages - 1]->valid != 0) {
+ if (--npages == 0) {
+ VM_OBJECT_WUNLOCK(vp->v_object);
+ return (VM_PAGER_OK);
}
- fuse_vm_page_unlock_queues();
- VM_OBJECT_WUNLOCK(vp->v_object);
- return 0;
- }
- fuse_vm_page_unlock_queues();
+ count = npages << PAGE_SHIFT;
+ }
VM_OBJECT_WUNLOCK(vp->v_object);
/*
@@ -1811,17 +1810,6 @@ fuse_vnop_getpages(struct vop_getpages_args *ap)
if (error && (uio.uio_resid == count)) {
FS_DEBUG("error %d\n", error);
- VM_OBJECT_WLOCK(vp->v_object);
- fuse_vm_page_lock_queues();
- for (i = 0; i < npages; ++i) {
- if (i != ap->a_reqpage) {
- fuse_vm_page_lock(pages[i]);
- vm_page_free(pages[i]);
- fuse_vm_page_unlock(pages[i]);
- }
- }
- fuse_vm_page_unlock_queues();
- VM_OBJECT_WUNLOCK(vp->v_object);
return VM_PAGER_ERROR;
}
/*
@@ -1862,8 +1850,6 @@ fuse_vnop_getpages(struct vop_getpages_args *ap)
*/
;
}
- if (i != ap->a_reqpage)
- vm_page_readahead_finish(m);
}
fuse_vm_page_unlock_queues();
VM_OBJECT_WUNLOCK(vp->v_object);
diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c
index 53ba7efe418f..5647868011ac 100644
--- a/sys/fs/nfsclient/nfs_clbio.c
+++ b/sys/fs/nfsclient/nfs_clbio.c
@@ -101,6 +101,10 @@ ncl_getpages(struct vop_getpages_args *ap)
nmp = VFSTONFS(vp->v_mount);
pages = ap->a_m;
count = ap->a_count;
+ if (ap->a_rbehind)
+ *ap->a_rbehind = 0;
+ if (ap->a_rahead)
+ *ap->a_rahead = 0;
if ((object = vp->v_object) == NULL) {
ncl_printf("nfs_getpages: called with non-merged cache vnode??\n");
@@ -132,12 +136,18 @@ ncl_getpages(struct vop_getpages_args *ap)
* If the requested page is partially valid, just return it and
* allow the pager to zero-out the blanks. Partially valid pages
* can only occur at the file EOF.
+ *
+ * XXXGL: is that true for NFS, where short read can occur???
*/
- if (pages[ap->a_reqpage]->valid != 0) {
- vm_pager_free_nonreq(object, pages, ap->a_reqpage, npages,
- FALSE);
- return (VM_PAGER_OK);
+ VM_OBJECT_WLOCK(object);
+ if (pages[npages - 1]->valid != 0) {
+ if (--npages == 0) {
+ VM_OBJECT_WUNLOCK(object);
+ return (VM_PAGER_OK);
+ }
+ count = npages << PAGE_SHIFT;
}
+ VM_OBJECT_WUNLOCK(object);
/*
* We use only the kva address for the buffer, but this is extremely
@@ -167,8 +177,6 @@ ncl_getpages(struct vop_getpages_args *ap)
if (error && (uio.uio_resid == count)) {
ncl_printf("nfs_getpages: error %d\n", error);
- vm_pager_free_nonreq(object, pages, ap->a_reqpage, npages,
- FALSE);
return (VM_PAGER_ERROR);
}
@@ -212,8 +220,6 @@ ncl_getpages(struct vop_getpages_args *ap)
*/
;
}
- if (i != ap->a_reqpage)
- vm_page_readahead_finish(m);
}
VM_OBJECT_WUNLOCK(object);
return (0);
diff --git a/sys/fs/smbfs/smbfs_io.c b/sys/fs/smbfs/smbfs_io.c
index a567ce6bf19c..5fe6f11dbbf1 100644
--- a/sys/fs/smbfs/smbfs_io.c
+++ b/sys/fs/smbfs/smbfs_io.c
@@ -424,7 +424,7 @@ smbfs_getpages(ap)
#ifdef SMBFS_RWGENERIC
return vop_stdgetpages(ap);
#else
- int i, error, nextoff, size, toff, npages, count, reqpage;
+ int i, error, nextoff, size, toff, npages, count;
struct uio uio;
struct iovec iov;
vm_offset_t kva;
@@ -436,7 +436,7 @@ smbfs_getpages(ap)
struct smbnode *np;
struct smb_cred *scred;
vm_object_t object;
- vm_page_t *pages, m;
+ vm_page_t *pages;
vp = ap->a_vp;
if ((object = vp->v_object) == NULL) {
@@ -451,26 +451,25 @@ smbfs_getpages(ap)
pages = ap->a_m;
count = ap->a_count;
npages = btoc(count);
- reqpage = ap->a_reqpage;
+ if (ap->a_rbehind)
+ *ap->a_rbehind = 0;
+ if (ap->a_rahead)
+ *ap->a_rahead = 0;
/*
* If the requested page is partially valid, just return it and
* allow the pager to zero-out the blanks. Partially valid pages
* can only occur at the file EOF.
+ *
+ * XXXGL: is that true for SMB filesystem?
*/
- m = pages[reqpage];
-
VM_OBJECT_WLOCK(object);
- if (m->valid != 0) {
- for (i = 0; i < npages; ++i) {
- if (i != reqpage) {
- vm_page_lock(pages[i]);
- vm_page_free(pages[i]);
- vm_page_unlock(pages[i]);
- }
+ if (pages[npages - 1]->valid != 0) {
+ if (--npages == 0) {
+ VM_OBJECT_WUNLOCK(object);
+ return (VM_PAGER_OK);
}
- VM_OBJECT_WUNLOCK(object);
- return 0;
+ count = npages << PAGE_SHIFT;
}
VM_OBJECT_WUNLOCK(object);
@@ -500,22 +499,14 @@ smbfs_getpages(ap)
relpbuf(bp, &smbfs_pbuf_freecnt);
- VM_OBJECT_WLOCK(object);
if (error && (uio.uio_resid == count)) {
printf("smbfs_getpages: error %d\n",error);
- for (i = 0; i < npages; i++) {
- if (reqpage != i) {
- vm_page_lock(pages[i]);
- vm_page_free(pages[i]);
- vm_page_unlock(pages[i]);
- }
- }
- VM_OBJECT_WUNLOCK(object);
return VM_PAGER_ERROR;
}
size = count - uio.uio_resid;
+ VM_OBJECT_WLOCK(object);
for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
vm_page_t m;
nextoff = toff + PAGE_SIZE;
@@ -544,9 +535,6 @@ smbfs_getpages(ap)
*/
;
}
-
- if (i != reqpage)
- vm_page_readahead_finish(m);
}
VM_OBJECT_WUNLOCK(object);
return 0;
diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index fa489b2f3842..fcc8782b9dd5 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -1370,7 +1370,8 @@ retry:
VM_OBJECT_WLOCK(uobj);
goto retry;
} else if (m->valid != VM_PAGE_BITS_ALL)
- rv = vm_pager_get_pages(uobj, &m, 1, 0);
+ rv = vm_pager_get_pages(uobj, &m, 1,
+ NULL, NULL);
else
/* A cached page was reactivated. */
rv = VM_PAGER_OK;