freebsd-skq/sys/kern/kern_physio.c

188 lines
3.9 KiB
C
Raw Normal View History

/*
* Copyright (c) 1994 John S. Dyson
* All rights reserved.
1994-05-24 10:09:53 +00:00
*
* 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 immediately at the beginning of the file, without modification,
* this list of conditions, and the following disclaimer.
1994-05-24 10:09:53 +00:00
* 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.
* 3. Absolutely no warranty of function or purpose is made by the author
* John S. Dyson.
* 4. Modifications may be freely made to this file if the above conditions
* are met.
1994-08-02 07:55:43 +00:00
*
These changes embody the support of the fully coherent merged VM buffer cache, much higher filesystem I/O performance, and much better paging performance. It represents the culmination of over 6 months of R&D. The majority of the merged VM/cache work is by John Dyson. The following highlights the most significant changes. Additionally, there are (mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to support the new VM/buffer scheme. vfs_bio.c: Significant rewrite of most of vfs_bio to support the merged VM buffer cache scheme. The scheme is almost fully compatible with the old filesystem interface. Significant improvement in the number of opportunities for write clustering. vfs_cluster.c, vfs_subr.c Upgrade and performance enhancements in vfs layer code to support merged VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff. vm_object.c: Yet more improvements in the collapse code. Elimination of some windows that can cause list corruption. vm_pageout.c: Fixed it, it really works better now. Somehow in 2.0, some "enhancements" broke the code. This code has been reworked from the ground-up. vm_fault.c, vm_page.c, pmap.c, vm_object.c Support for small-block filesystems with merged VM/buffer cache scheme. pmap.c vm_map.c Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of kernel PTs. vm_glue.c Much simpler and more effective swapping code. No more gratuitous swapping. proc.h Fixed the problem that the p_lock flag was not being cleared on a fork. swap_pager.c, vnode_pager.c Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the code doesn't need it anymore. machdep.c Changes to better support the parameter values for the merged VM/buffer cache scheme. machdep.c, kern_exec.c, vm_glue.c Implemented a seperate submap for temporary exec string space and another one to contain process upages. This eliminates all map fragmentation problems that previously existed. ffs_inode.c, ufs_inode.c, ufs_readwrite.c Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on busy buffers. Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
* $Id: kern_physio.c,v 1.8 1994/09/25 19:33:40 phk Exp $
1994-05-24 10:09:53 +00:00
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/conf.h>
#include <sys/proc.h>
#include <vm/vm.h>
1994-05-24 10:09:53 +00:00
static void physwakeup();
int
physio(strategy, bp, dev, rw, minp, uio)
int (*strategy)();
struct buf *bp;
dev_t dev;
int rw;
u_int (*minp)();
struct uio *uio;
1994-05-24 10:09:53 +00:00
{
int i;
int bufflags = rw?B_READ:0;
int error;
int spl;
caddr_t sa;
int bp_alloc = (bp == 0);
struct buf *bpa;
/*
* keep the process from being swapped
*/
curproc->p_flag |= P_PHYSIO;
/* create and build a buffer header for a transfer */
bpa = (struct buf *)getpbuf();
if (!bp_alloc) {
spl = splbio();
while (bp->b_flags & B_BUSY) {
bp->b_flags |= B_WANTED;
tsleep((caddr_t)bp, PRIBIO, "physbw", 0);
}
bp->b_flags |= B_BUSY;
splx(spl);
} else {
bp = bpa;
}
/*
* get a copy of the kva from the physical buffer
*/
sa = bpa->b_data;
bp->b_proc = curproc;
bp->b_dev = dev;
error = bp->b_error = 0;
for(i=0;i<uio->uio_iovcnt;i++) {
while( uio->uio_iov[i].iov_len) {
bp->b_bcount = uio->uio_iov[i].iov_len;
bp->b_bcount = minp( bp);
if( minp != minphys)
bp->b_bcount = minphys( bp);
bp->b_bufsize = bp->b_bcount;
bp->b_flags = B_BUSY | B_PHYS | B_CALL | bufflags;
bp->b_iodone = physwakeup;
bp->b_data = uio->uio_iov[i].iov_base;
/*
* pass in the kva from the physical buffer
* for the temporary kernel mapping.
*/
bp->b_saveaddr = sa;
bp->b_blkno = btodb(uio->uio_offset);
if (rw && !useracc(bp->b_data, bp->b_bufsize, B_WRITE)) {
error = EFAULT;
goto doerror;
}
if (!rw && !useracc(bp->b_data, bp->b_bufsize, B_READ)) {
error = EFAULT;
goto doerror;
}
vmapbuf(bp);
/* perform transfer */
(*strategy)(bp);
spl = splbio();
while ((bp->b_flags & B_DONE) == 0)
tsleep((caddr_t)bp, PRIBIO, "physstr", 0);
splx(spl);
1994-05-24 10:09:53 +00:00
vunmapbuf(bp);
/*
* update the uio data
*/
{
int iolen = bp->b_bcount - bp->b_resid;
if (iolen == 0 && !(bp->b_flags & B_ERROR))
goto doerror; /* EOF */
uio->uio_iov[i].iov_len -= iolen;
uio->uio_iov[i].iov_base += iolen;
uio->uio_resid -= iolen;
uio->uio_offset += iolen;
}
/*
* check for an error
*/
if( bp->b_flags & B_ERROR) {
error = bp->b_error;
goto doerror;
}
}
}
doerror:
relpbuf(bpa);
if (!bp_alloc) {
bp->b_flags &= ~(B_BUSY|B_PHYS);
if( bp->b_flags & B_WANTED) {
bp->b_flags &= ~B_WANTED;
wakeup((caddr_t)bp);
}
}
/*
* allow the process to be swapped
*/
curproc->p_flag &= ~P_PHYSIO;
return (error);
1994-05-24 10:09:53 +00:00
}
u_int
minphys(struct buf *bp)
1994-05-24 10:09:53 +00:00
{
These changes embody the support of the fully coherent merged VM buffer cache, much higher filesystem I/O performance, and much better paging performance. It represents the culmination of over 6 months of R&D. The majority of the merged VM/cache work is by John Dyson. The following highlights the most significant changes. Additionally, there are (mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to support the new VM/buffer scheme. vfs_bio.c: Significant rewrite of most of vfs_bio to support the merged VM buffer cache scheme. The scheme is almost fully compatible with the old filesystem interface. Significant improvement in the number of opportunities for write clustering. vfs_cluster.c, vfs_subr.c Upgrade and performance enhancements in vfs layer code to support merged VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff. vm_object.c: Yet more improvements in the collapse code. Elimination of some windows that can cause list corruption. vm_pageout.c: Fixed it, it really works better now. Somehow in 2.0, some "enhancements" broke the code. This code has been reworked from the ground-up. vm_fault.c, vm_page.c, pmap.c, vm_object.c Support for small-block filesystems with merged VM/buffer cache scheme. pmap.c vm_map.c Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of kernel PTs. vm_glue.c Much simpler and more effective swapping code. No more gratuitous swapping. proc.h Fixed the problem that the p_lock flag was not being cleared on a fork. swap_pager.c, vnode_pager.c Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the code doesn't need it anymore. machdep.c Changes to better support the parameter values for the merged VM/buffer cache scheme. machdep.c, kern_exec.c, vm_glue.c Implemented a seperate submap for temporary exec string space and another one to contain process upages. This eliminates all map fragmentation problems that previously existed. ffs_inode.c, ufs_inode.c, ufs_readwrite.c Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on busy buffers. Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
if( bp->b_bcount > MAXPHYS) {
bp->b_bcount = MAXPHYS;
}
return bp->b_bcount;
1994-05-24 10:09:53 +00:00
}
int
rawread(dev_t dev, struct uio *uio)
1994-05-24 10:09:53 +00:00
{
return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
dev, 1, minphys, uio));
1994-05-24 10:09:53 +00:00
}
int
rawwrite(dev_t dev, struct uio *uio)
1994-05-24 10:09:53 +00:00
{
return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
dev, 0, minphys, uio));
}
static void
physwakeup(bp)
struct buf *bp;
{
wakeup((caddr_t) bp);
bp->b_flags &= ~B_CALL;
1994-05-24 10:09:53 +00:00
}