2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: genfs_vnops.c,v 1.167 2008/04/28 20:24:08 martin Exp $ */
|
2008-02-05 17:19:52 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1998-03-01 05:20:01 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
1998-01-05 22:19:41 +03:00
|
|
|
|
2001-11-10 16:33:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-04-29 00:22:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.167 2008/04/28 20:24:08 martin Exp $");
|
1998-06-26 02:15:28 +04:00
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <sys/proc.h>
|
1996-09-02 03:47:48 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/vnode.h>
|
1999-08-04 00:19:16 +04:00
|
|
|
#include <sys/fcntl.h>
|
2006-10-14 13:15:52 +04:00
|
|
|
#include <sys/kmem.h>
|
1996-09-07 16:40:22 +04:00
|
|
|
#include <sys/poll.h>
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
#include <sys/mman.h>
|
2002-10-23 13:10:23 +04:00
|
|
|
#include <sys/file.h>
|
2006-05-15 01:31:52 +04:00
|
|
|
#include <sys/kauth.h>
|
1996-09-02 03:47:48 +04:00
|
|
|
|
|
|
|
#include <miscfs/genfs/genfs.h>
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
#include <miscfs/genfs/genfs_node.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
1996-09-02 03:47:48 +04:00
|
|
|
|
2000-11-27 11:39:39 +03:00
|
|
|
#include <uvm/uvm.h>
|
|
|
|
#include <uvm/uvm_pager.h>
|
|
|
|
|
2003-01-21 03:01:14 +03:00
|
|
|
static void filt_genfsdetach(struct knote *);
|
|
|
|
static int filt_genfsread(struct knote *, long);
|
|
|
|
static int filt_genfsvnode(struct knote *, long);
|
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_poll(void *v)
|
1996-09-02 03:47:48 +04:00
|
|
|
{
|
1996-09-07 16:40:22 +04:00
|
|
|
struct vop_poll_args /* {
|
1996-09-02 03:47:48 +04:00
|
|
|
struct vnode *a_vp;
|
1996-09-07 16:40:22 +04:00
|
|
|
int a_events;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *a_l;
|
1996-09-02 03:47:48 +04:00
|
|
|
} */ *ap = v;
|
|
|
|
|
1996-09-07 16:40:22 +04:00
|
|
|
return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
|
1996-09-02 03:47:48 +04:00
|
|
|
}
|
|
|
|
|
1997-04-12 01:52:00 +04:00
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_seek(void *v)
|
1997-04-12 01:52:00 +04:00
|
|
|
{
|
|
|
|
struct vop_seek_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
off_t a_oldoff;
|
|
|
|
off_t a_newoff;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred;
|
1997-04-12 01:52:00 +04:00
|
|
|
} */ *ap = v;
|
|
|
|
|
|
|
|
if (ap->a_newoff < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_abortop(void *v)
|
1996-09-02 03:47:48 +04:00
|
|
|
{
|
|
|
|
struct vop_abortop_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap = v;
|
2002-04-16 10:00:46 +04:00
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
|
2000-08-04 00:41:05 +04:00
|
|
|
PNBUF_PUT(ap->a_cnp->cn_pnbuf);
|
1996-09-02 03:47:48 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-08-04 00:19:16 +04:00
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_fcntl(void *v)
|
1999-08-04 00:19:16 +04:00
|
|
|
{
|
|
|
|
struct vop_fcntl_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
u_int a_command;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *a_data;
|
1999-08-04 00:19:16 +04:00
|
|
|
int a_fflag;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *a_l;
|
1999-08-04 00:19:16 +04:00
|
|
|
} */ *ap = v;
|
|
|
|
|
|
|
|
if (ap->a_command == F_SETFL)
|
|
|
|
return (0);
|
|
|
|
else
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_badop(void *v)
|
1996-09-02 03:47:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
panic("genfs: bad op");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_nullop(void *v)
|
1996-09-02 03:47:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-08-13 13:59:52 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_einval(void *v)
|
1998-08-13 13:59:52 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
1999-07-08 05:18:59 +04:00
|
|
|
/*
|
2003-04-11 01:34:12 +04:00
|
|
|
* Called when an fs doesn't support a particular vop.
|
|
|
|
* This takes care to vrele, vput, or vunlock passed in vnodes.
|
1999-07-08 05:18:59 +04:00
|
|
|
*/
|
|
|
|
int
|
2003-04-11 01:53:32 +04:00
|
|
|
genfs_eopnotsupp(void *v)
|
1999-07-08 05:18:59 +04:00
|
|
|
{
|
|
|
|
struct vop_generic_args /*
|
|
|
|
struct vnodeop_desc *a_desc;
|
2002-04-16 10:00:46 +04:00
|
|
|
/ * other random data follows, presumably * /
|
1999-07-08 05:18:59 +04:00
|
|
|
} */ *ap = v;
|
|
|
|
struct vnodeop_desc *desc = ap->a_desc;
|
2003-04-11 01:34:12 +04:00
|
|
|
struct vnode *vp, *vp_last = NULL;
|
1999-07-08 05:18:59 +04:00
|
|
|
int flags, i, j, offset;
|
|
|
|
|
|
|
|
flags = desc->vdesc_flags;
|
|
|
|
for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
|
|
|
|
if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
|
|
|
|
break; /* stop at end of list */
|
|
|
|
if ((j = flags & VDESC_VP0_WILLPUT)) {
|
2002-04-16 10:00:46 +04:00
|
|
|
vp = *VOPARG_OFFSETTO(struct vnode **, offset, ap);
|
2003-04-11 01:34:12 +04:00
|
|
|
|
|
|
|
/* Skip if NULL */
|
|
|
|
if (!vp)
|
|
|
|
continue;
|
|
|
|
|
1999-07-08 05:18:59 +04:00
|
|
|
switch (j) {
|
|
|
|
case VDESC_VP0_WILLPUT:
|
2003-04-11 01:34:12 +04:00
|
|
|
/* Check for dvp == vp cases */
|
|
|
|
if (vp == vp_last)
|
|
|
|
vrele(vp);
|
|
|
|
else {
|
|
|
|
vput(vp);
|
|
|
|
vp_last = vp;
|
|
|
|
}
|
1999-07-08 05:18:59 +04:00
|
|
|
break;
|
|
|
|
case VDESC_VP0_WILLUNLOCK:
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
break;
|
|
|
|
case VDESC_VP0_WILLRELE:
|
|
|
|
vrele(vp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_ebadf(void *v)
|
1996-09-02 03:47:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (EBADF);
|
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
|
1998-08-10 12:11:10 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_enoioctl(void *v)
|
1998-08-10 12:11:10 +04:00
|
|
|
{
|
|
|
|
|
2002-03-17 22:40:26 +03:00
|
|
|
return (EPASSTHROUGH);
|
1998-08-10 12:11:10 +04:00
|
|
|
}
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
|
|
|
|
/*
|
1999-11-15 21:49:07 +03:00
|
|
|
* Eliminate all activity associated with the requested vnode
|
1998-03-01 05:20:01 +03:00
|
|
|
* and with all vnodes aliased to the requested vnode.
|
|
|
|
*/
|
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_revoke(void *v)
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
|
|
|
struct vop_revoke_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((ap->a_flags & REVOKEALL) == 0)
|
|
|
|
panic("genfs_revoke: not revokeall");
|
|
|
|
#endif
|
2008-01-17 20:28:54 +03:00
|
|
|
vrevoke(ap->a_vp);
|
1998-03-01 05:20:01 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-07-08 05:18:59 +04:00
|
|
|
* Lock the node.
|
1998-03-01 05:20:01 +03:00
|
|
|
*/
|
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_lock(void *v)
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
|
|
|
struct vop_lock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2008-01-30 12:50:19 +03:00
|
|
|
int flags = ap->a_flags;
|
1998-03-01 05:20:01 +03:00
|
|
|
|
2008-01-30 12:50:19 +03:00
|
|
|
if ((flags & LK_INTERLOCK) != 0) {
|
|
|
|
flags &= ~LK_INTERLOCK;
|
|
|
|
mutex_exit(&vp->v_interlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (vlockmgr(vp->v_vnlock, flags));
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-07-08 05:18:59 +04:00
|
|
|
* Unlock the node.
|
1998-03-01 05:20:01 +03:00
|
|
|
*/
|
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_unlock(void *v)
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
|
|
|
struct vop_unlock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
2008-01-30 12:50:19 +03:00
|
|
|
KASSERT(ap->a_flags == 0);
|
|
|
|
|
|
|
|
return (vlockmgr(vp->v_vnlock, LK_RELEASE));
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-07-08 05:18:59 +04:00
|
|
|
* Return whether or not the node is locked.
|
1998-03-01 05:20:01 +03:00
|
|
|
*/
|
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_islocked(void *v)
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
|
|
|
struct vop_islocked_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
|
2008-01-30 12:50:19 +03:00
|
|
|
return (vlockstatus(vp->v_vnlock));
|
1999-07-08 05:18:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stubs to use when there is no locking to be done on the underlying object.
|
|
|
|
*/
|
|
|
|
int
|
2002-04-16 10:00:46 +04:00
|
|
|
genfs_nolock(void *v)
|
1999-07-08 05:18:59 +04:00
|
|
|
{
|
|
|
|
struct vop_lock_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *a_l;
|
1999-07-08 05:18:59 +04:00
|
|
|
} */ *ap = v;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we are not using the lock manager, we must clear
|
|
|
|
* the interlock here.
|
|
|
|
*/
|
|
|
|
if (ap->a_flags & LK_INTERLOCK)
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_exit(&ap->a_vp->v_interlock);
|
1999-07-08 05:18:59 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_nounlock(void *v)
|
1999-07-08 05:18:59 +04:00
|
|
|
{
|
2002-04-16 10:00:46 +04:00
|
|
|
|
1999-07-08 05:18:59 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_noislocked(void *v)
|
1999-07-08 05:18:59 +04:00
|
|
|
{
|
2002-04-16 10:00:46 +04:00
|
|
|
|
1999-07-08 05:18:59 +04:00
|
|
|
return (0);
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
1998-06-26 02:15:28 +04:00
|
|
|
|
2001-05-28 06:50:51 +04:00
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_mmap(void *v)
|
2001-05-28 06:50:51 +04:00
|
|
|
{
|
2002-04-16 10:00:46 +04:00
|
|
|
|
|
|
|
return (0);
|
2001-05-28 06:50:51 +04:00
|
|
|
}
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
void
|
2005-06-28 13:30:37 +04:00
|
|
|
genfs_node_init(struct vnode *vp, const struct genfs_ops *ops)
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
{
|
|
|
|
struct genfs_node *gp = VTOG(vp);
|
|
|
|
|
2007-02-15 18:40:50 +03:00
|
|
|
rw_init(&gp->g_glock);
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
gp->g_op = ops;
|
|
|
|
}
|
|
|
|
|
2007-02-20 19:19:42 +03:00
|
|
|
void
|
|
|
|
genfs_node_destroy(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct genfs_node *gp = VTOG(vp);
|
|
|
|
|
|
|
|
rw_destroy(&gp->g_glock);
|
|
|
|
}
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
genfs_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
|
2000-11-27 11:39:39 +03:00
|
|
|
{
|
|
|
|
int bsize;
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
bsize = 1 << vp->v_mount->mnt_fs_bshift;
|
|
|
|
*eobp = (size + bsize - 1) & ~(bsize - 1);
|
2000-11-27 11:39:39 +03:00
|
|
|
}
|
2001-12-18 10:49:36 +03:00
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
static void
|
|
|
|
filt_genfsdetach(struct knote *kn)
|
|
|
|
{
|
|
|
|
struct vnode *vp = (struct vnode *)kn->kn_hook;
|
|
|
|
|
2008-02-05 17:19:52 +03:00
|
|
|
mutex_enter(&vp->v_interlock);
|
2002-10-23 13:10:23 +04:00
|
|
|
SLIST_REMOVE(&vp->v_klist, kn, knote, kn_selnext);
|
2008-02-05 17:19:52 +03:00
|
|
|
mutex_exit(&vp->v_interlock);
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_genfsread(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
struct vnode *vp = (struct vnode *)kn->kn_hook;
|
2008-02-05 17:19:52 +03:00
|
|
|
int rv;
|
2002-10-23 13:10:23 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* filesystem is gone, so set the EOF flag and schedule
|
|
|
|
* the knote for deletion.
|
|
|
|
*/
|
2008-02-05 17:19:52 +03:00
|
|
|
switch (hint) {
|
|
|
|
case NOTE_REVOKE:
|
|
|
|
KASSERT(mutex_owned(&vp->v_interlock));
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_flags |= (EV_EOF | EV_ONESHOT);
|
|
|
|
return (1);
|
2008-02-05 17:19:52 +03:00
|
|
|
case 0:
|
|
|
|
mutex_enter(&vp->v_interlock);
|
2008-03-22 00:54:58 +03:00
|
|
|
kn->kn_data = vp->v_size - ((file_t *)kn->kn_obj)->f_offset;
|
2008-02-05 17:19:52 +03:00
|
|
|
rv = (kn->kn_data != 0);
|
|
|
|
mutex_exit(&vp->v_interlock);
|
|
|
|
return rv;
|
|
|
|
default:
|
|
|
|
KASSERT(mutex_owned(&vp->v_interlock));
|
2008-03-22 00:54:58 +03:00
|
|
|
kn->kn_data = vp->v_size - ((file_t *)kn->kn_obj)->f_offset;
|
2008-02-05 17:19:52 +03:00
|
|
|
return (kn->kn_data != 0);
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_genfsvnode(struct knote *kn, long hint)
|
|
|
|
{
|
2008-02-05 17:19:52 +03:00
|
|
|
struct vnode *vp = (struct vnode *)kn->kn_hook;
|
|
|
|
int fflags;
|
2002-10-23 13:10:23 +04:00
|
|
|
|
2008-02-05 17:19:52 +03:00
|
|
|
switch (hint) {
|
|
|
|
case NOTE_REVOKE:
|
|
|
|
KASSERT(mutex_owned(&vp->v_interlock));
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_flags |= EV_EOF;
|
2008-02-05 17:19:52 +03:00
|
|
|
if ((kn->kn_sfflags & hint) != 0)
|
|
|
|
kn->kn_fflags |= hint;
|
2002-10-23 13:10:23 +04:00
|
|
|
return (1);
|
2008-02-05 17:19:52 +03:00
|
|
|
case 0:
|
|
|
|
mutex_enter(&vp->v_interlock);
|
|
|
|
fflags = kn->kn_fflags;
|
|
|
|
mutex_exit(&vp->v_interlock);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
KASSERT(mutex_owned(&vp->v_interlock));
|
|
|
|
if ((kn->kn_sfflags & hint) != 0)
|
|
|
|
kn->kn_fflags |= hint;
|
|
|
|
fflags = kn->kn_fflags;
|
|
|
|
break;
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
2008-02-05 17:19:52 +03:00
|
|
|
|
2008-03-22 00:54:58 +03:00
|
|
|
return (fflags != 0);
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
|
|
|
|
2005-02-27 01:58:54 +03:00
|
|
|
static const struct filterops genfsread_filtops =
|
2002-10-23 13:10:23 +04:00
|
|
|
{ 1, NULL, filt_genfsdetach, filt_genfsread };
|
2005-02-27 01:58:54 +03:00
|
|
|
static const struct filterops genfsvnode_filtops =
|
2002-10-23 13:10:23 +04:00
|
|
|
{ 1, NULL, filt_genfsdetach, filt_genfsvnode };
|
|
|
|
|
|
|
|
int
|
|
|
|
genfs_kqfilter(void *v)
|
|
|
|
{
|
|
|
|
struct vop_kqfilter_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct knote *a_kn;
|
|
|
|
} */ *ap = v;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct knote *kn;
|
|
|
|
|
|
|
|
vp = ap->a_vp;
|
|
|
|
kn = ap->a_kn;
|
|
|
|
switch (kn->kn_filter) {
|
|
|
|
case EVFILT_READ:
|
|
|
|
kn->kn_fop = &genfsread_filtops;
|
|
|
|
break;
|
|
|
|
case EVFILT_VNODE:
|
|
|
|
kn->kn_fop = &genfsvnode_filtops;
|
|
|
|
break;
|
|
|
|
default:
|
2007-12-05 20:19:46 +03:00
|
|
|
return (EINVAL);
|
2002-10-23 13:10:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
kn->kn_hook = vp;
|
|
|
|
|
2008-02-05 17:19:52 +03:00
|
|
|
mutex_enter(&vp->v_interlock);
|
2002-10-23 13:10:23 +04:00
|
|
|
SLIST_INSERT_HEAD(&vp->v_klist, kn, kn_selnext);
|
2008-02-05 17:19:52 +03:00
|
|
|
mutex_exit(&vp->v_interlock);
|
2002-10-23 13:10:23 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2006-10-14 13:16:28 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
genfs_node_wrlock(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct genfs_node *gp = VTOG(vp);
|
|
|
|
|
2007-02-15 18:40:50 +03:00
|
|
|
rw_enter(&gp->g_glock, RW_WRITER);
|
2006-10-14 13:16:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
genfs_node_rdlock(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct genfs_node *gp = VTOG(vp);
|
|
|
|
|
2007-02-15 18:40:50 +03:00
|
|
|
rw_enter(&gp->g_glock, RW_READER);
|
2006-10-14 13:16:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
genfs_node_unlock(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct genfs_node *gp = VTOG(vp);
|
|
|
|
|
2007-02-15 18:40:50 +03:00
|
|
|
rw_exit(&gp->g_glock);
|
2006-10-14 13:16:28 +04:00
|
|
|
}
|