diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index 22e1d6e125bc..97b5fad618ed 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm_swap.c,v 1.50 1997/12/01 16:33:15 pk Exp $ */ +/* $NetBSD: vm_swap.c,v 1.51 1997/12/01 17:10:48 pk Exp $ */ /* * Copyright (c) 1995, 1996, 1997 Matthew R. Green @@ -97,6 +97,13 @@ #define VMSDB_SWFLOW 0x0010 #define VMSDB_INFO 0x0020 int vmswapdebug = 0; + +#define DPRINTF(f, m) do { \ + if (vmswapdebug & (f)) \ + printf m; \ +} while(0) +#else +#define DPRINTF(f, m) #endif #define SWAP_TO_FILES @@ -366,11 +373,8 @@ again: tsleep((caddr_t)&lbolt, PSWP, "memory", 0); goto again; } -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("sw: had to create a new swappri = %d\n", - priority); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, + ("sw: had to create a new swappri = %d\n", priority)); spp->spi_priority = priority; CIRCLEQ_INIT(&spp->spi_swapdev); @@ -458,17 +462,11 @@ sys_swapctl(p, v, retval) misc = SCARG(uap, misc); -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("entering sys_swapctl\n"); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, ("entering sys_swapctl\n")); /* how many swap devices */ if (SCARG(uap, cmd) == SWAP_NSWAP) { -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("did SWAP_NSWAP: leaving sys_swapctl\n"); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW,("did SWAP_NSWAP: leaving sys_swapctl\n")); *retval = nswapdev; return (0); } @@ -497,10 +495,9 @@ sys_swapctl(p, v, retval) (void)lockmgr(&swaplist_change_lock, LK_RELEASE, (void *)0, p); if (error) return (error); -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("sw: did SWAP_STATS: leaving sys_swapctl\n"); -#endif /* SWAPDEBUG */ + + DPRINTF(VMSDB_SWFLOW,("did SWAP_STATS: leaving sys_swapctl\n")); + *retval = count; return (0); } @@ -570,10 +567,7 @@ sys_swapctl(p, v, retval) break; case SWAP_OFF: -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("doing SWAP_OFF...\n"); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, ("doing SWAP_OFF...\n")); #ifdef SWAP_OFF_WORKS if ((sdp = find_swapdev(vp, 0)) == NULL) { error = ENXIO; @@ -603,10 +597,8 @@ sys_swapctl(p, v, retval) break; default: -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("doing default...\n"); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, + ("unhandled command: %x\n", SCARG(uap, cmd))); error = EINVAL; } @@ -615,10 +607,7 @@ bad: bad2: vput(vp); -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("leaving sys_swapctl: error %d\n", error); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, ("leaving sys_swapctl: error %d\n", error)); return (error); } @@ -653,10 +642,8 @@ swap_on(p, sdp) return (error); } -#ifdef SWAPDEBUG /* this wants only for block devices */ - if (vmswapdebug & VMSDB_INFO) - printf("swap_on: dev = %d, major(dev) = %d\n", dev, major(dev)); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_INFO, + ("swap_on: dev = %d, major(dev) = %d\n", dev, major(dev))); switch (vp->v_type) { case VBLK: @@ -691,10 +678,7 @@ swap_on(p, sdp) goto bad; } if (nblks == 0) { -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("swap_on: nblks == 0\n"); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, ("swap_on: nblks == 0\n")); error = EINVAL; goto bad; } @@ -714,10 +698,8 @@ swap_on(p, sdp) addr = (long)0; } -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWON) - printf("swap_on: dev %x: size %d, addr %ld\n", dev, size, addr); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWON, + ("swap_on: dev %x: size %d, addr %ld\n", dev, size, addr)); name = malloc(12, M_VMSWAP, M_WAITOK); sprintf(name, "swap0x%04x", count++); @@ -795,10 +777,7 @@ swap_off(p, sdp) /* turn off the enable flag */ sdp->swd_flags &= ~SWF_ENABLE; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWOFF) - printf("swap_off: %x\n", sdp->swd_dev); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWOFF, ("swap_off: %x\n", sdp->swd_dev)); /* * XXX write me @@ -995,12 +974,10 @@ swstrategy(bp) bn -= sdp->swd_mapoffset; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("swstrategy(%s): mapoff %x, bn %x, bcount %ld\n", + DPRINTF(VMSDB_SWFLOW, + ("swstrategy(%s): mapoff %x, bn %x, bcount %ld\n", ((bp->b_flags & B_READ) == 0) ? "write" : "read", - sdp->swd_mapoffset, bn, bp->b_bcount); -#endif + sdp->swd_mapoffset, bn, bp->b_bcount)); switch (sdp->swd_vp->v_type) { default: @@ -1096,11 +1073,9 @@ sw_reg_strategy(sdp, bp, bn) if (resid < sz) sz = resid; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("sw_reg_strategy: vp %p/%p bn 0x%x/0x%x" - " sz 0x%x\n", sdp->swd_vp, vp, bn, nbn, sz); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, + ("sw_reg_strategy: vp %p/%p bn 0x%x/0x%x" + " sz 0x%x\n", sdp->swd_vp, vp, bn, nbn, sz)); getvndbuf(nbp); nbp->vb_buf.b_flags = bp->b_flags | B_CALL; @@ -1198,12 +1173,10 @@ static int busy; /* Recursion control */ sdp->swd_tab.b_actf = bp->b_actf; sdp->swd_tab.b_active++; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf( - "sw_reg_start: bp %p vp %p blkno %x addr %p cnt %lx\n", - bp, bp->b_vp, bp->b_blkno,bp->b_data, bp->b_bcount); -#endif + DPRINTF(VMSDB_SWFLOW, + ("sw_reg_start: bp %p vp %p blkno %x addr %p cnt %lx\n", + bp, bp->b_vp, bp->b_blkno,bp->b_data, bp->b_bcount)); + if ((bp->b_flags & B_READ) == 0) bp->b_vp->v_numoutput++; VOP_STRATEGY(bp); @@ -1221,14 +1194,12 @@ sw_reg_iodone(bp) struct swapdev *sdp = vnx->vx_sdp; int s, resid; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("sw_reg_iodone: vbp %p vp %p blkno %x addr %p " - "cnt %lx(%lx)\n", - vbp, vbp->vb_buf.b_vp, vbp->vb_buf.b_blkno, - vbp->vb_buf.b_data, vbp->vb_buf.b_bcount, - vbp->vb_buf.b_resid); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_SWFLOW, + ("sw_reg_iodone: vbp %p vp %p blkno %x addr %p " + "cnt %lx(%lx)\n", + vbp, vbp->vb_buf.b_vp, vbp->vb_buf.b_blkno, + vbp->vb_buf.b_data, vbp->vb_buf.b_bcount, + vbp->vb_buf.b_resid)); s = splbio(); resid = vbp->vb_buf.b_bcount - vbp->vb_buf.b_resid; @@ -1236,11 +1207,8 @@ sw_reg_iodone(bp) vnx->vx_pending--; if (vbp->vb_buf.b_error) { -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("sw_reg_iodone: vbp %p error %d\n", vbp, - vbp->vb_buf.b_error); -#endif /* SWAPDEBUG */ + DPRINTF(VMSDB_INFO, ("sw_reg_iodone: vbp %p error %d\n", vbp, + vbp->vb_buf.b_error)); vnx->vx_error = vbp->vb_buf.b_error; } @@ -1258,11 +1226,10 @@ sw_reg_iodone(bp) pbp->b_flags |= B_ERROR; pbp->b_error = vnx->vx_error; if ((vnx->vx_flags & VX_BUSY) == 0 && vnx->vx_pending == 0) { -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("swiodone: pbp %p iodone: error %d\n", - pbp, vnx->vx_error); -#endif + + DPRINTF(VMSDB_SWFLOW, + ("swiodone: pbp %p iodone: error %d\n", + pbp, vnx->vx_error)); putvndxfer(vnx); biodone(pbp); } @@ -1274,10 +1241,8 @@ sw_reg_iodone(bp) #endif if ((vnx->vx_flags & VX_BUSY) == 0) { -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWFLOW) - printf("swiodone: pbp %p iodone\n", pbp); -#endif + DPRINTF(VMSDB_SWFLOW, + ("swiodone: pbp %p iodone\n", pbp)); putvndxfer(vnx); biodone(pbp); } @@ -1297,10 +1262,8 @@ swapinit() struct proc *p = &proc0; /* XXX */ int i; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWINIT) - printf("swapinit\n"); -#endif + DPRINTF(VMSDB_SWINIT, ("swapinit\n")); + nswapdev = 0; if (bdevvp(swapdev, &swapdev_vp)) panic("swapinit: can setup swapdev_vp"); @@ -1332,8 +1295,6 @@ swapinit() sp->b_rcred = sp->b_wcred = p->p_ucred; sp->b_vnbufs.le_next = NOLIST; sp->b_actf = NULL; -#ifdef SWAPDEBUG - if (vmswapdebug & VMSDB_SWINIT) - printf("leaving swapinit\n"); -#endif + + DPRINTF(VMSDB_SWINIT, ("leaving swapinit\n")); }