diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2013-11-24 15:44:27 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2013-11-24 15:44:27 +0000 |
commit | ed928a2b17edc445bcb0fcd087e74dc840880697 (patch) | |
tree | 7f9d42741dd0d051c08fe23c98a9e6c800d1faa6 /sys/uvm | |
parent | 36375f456c47b65442c15622963a2e3ea855c3f3 (diff) |
Replace the swapdev CIRCLEQ with a TAILQ and replace the manually rolled
list traversals with LIST_FOREACH.
ok beck@ krw@
Diffstat (limited to 'sys/uvm')
-rw-r--r-- | sys/uvm/uvm_swap.c | 100 |
1 files changed, 45 insertions, 55 deletions
diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index f4a2590d0bc..8e2a0d3fe8e 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.c,v 1.123 2013/11/21 00:13:33 dlg Exp $ */ +/* $OpenBSD: uvm_swap.c,v 1.124 2013/11/24 15:44:26 jsing Exp $ */ /* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */ /* @@ -87,7 +87,7 @@ * partitions/files. there is a sorted LIST of "swappri" structures * which describe "swapdev"'s at that priority. this LIST is headed * by the "swap_priority" global var. each "swappri" contains a - * CIRCLEQ of "swapdev" structures at that priority. + * TAILQ of "swapdev" structures at that priority. * * locking: * - swap_syscall_lock (sleep lock): this lock serializes the swapctl @@ -142,7 +142,7 @@ struct swapdev { struct extent *swd_ex; /* extent for this swapdev */ char swd_exname[12]; /* name of extent above */ struct vnode *swd_vp; /* backing vnode */ - CIRCLEQ_ENTRY(swapdev) swd_next; /* priority circleq */ + TAILQ_ENTRY(swapdev) swd_next; /* priority tailq */ int swd_bsize; /* blocksize (bytes) */ int swd_maxactive; /* max active i/o reqs */ @@ -170,8 +170,8 @@ struct swapdev { */ struct swappri { int spi_priority; /* priority */ - CIRCLEQ_HEAD(spi_swapdev, swapdev) spi_swapdev; - /* circleq of swapdevs at this priority */ + TAILQ_HEAD(spi_swapdev, swapdev) spi_swapdev; + /* tailq of swapdevs at this priority */ LIST_ENTRY(swappri) spi_swappri; /* global list of pri's */ }; @@ -329,12 +329,13 @@ uvm_swap_initcrypt_all(void) LIST_FOREACH(spp, &swap_priority, spi_swappri) { - CIRCLEQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { if (sdp->swd_decrypt == NULL) { npages = dbtob((uint64_t)sdp->swd_nblks) >> PAGE_SHIFT; uvm_swap_initcrypt(sdp, npages); } + } } } @@ -451,7 +452,7 @@ uvm_swap_finicrypt_all(void) unsigned int nkeys; LIST_FOREACH(spp, &swap_priority, spi_swappri) { - CIRCLEQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { if (sdp->swd_decrypt == NULL) continue; @@ -501,7 +502,7 @@ swaplist_insert(struct swapdev *sdp, struct swappri *newspp, int priority) spp = newspp; /* use newspp! */ spp->spi_priority = priority; - CIRCLEQ_INIT(&spp->spi_swapdev); + TAILQ_INIT(&spp->spi_swapdev); if (pspp) LIST_INSERT_AFTER(pspp, spp, spi_swappri); @@ -514,10 +515,10 @@ swaplist_insert(struct swapdev *sdp, struct swappri *newspp, int priority) /* * priority found (or created). now insert on the priority's - * circleq list and bump the total number of swapdevs. + * tailq list and bump the total number of swapdevs. */ sdp->swd_priority = priority; - CIRCLEQ_INSERT_TAIL(&spp->spi_swapdev, sdp, swd_next); + TAILQ_INSERT_TAIL(&spp->spi_swapdev, sdp, swd_next); uvmexp.nswapdev++; } @@ -537,19 +538,16 @@ swaplist_find(struct vnode *vp, boolean_t remove) /* * search the lists for the requested vp */ - for (spp = LIST_FIRST(&swap_priority); spp != NULL; - spp = LIST_NEXT(spp, spi_swappri)) { - for (sdp = CIRCLEQ_FIRST(&spp->spi_swapdev); - sdp != (void *)&spp->spi_swapdev; - sdp = CIRCLEQ_NEXT(sdp, swd_next)) - if (sdp->swd_vp == vp) { - if (remove) { - CIRCLEQ_REMOVE(&spp->spi_swapdev, - sdp, swd_next); - uvmexp.nswapdev--; - } - return(sdp); + LIST_FOREACH(spp, &swap_priority, spi_swappri) { + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { + if (sdp->swd_vp != vp) + continue; + if (remove) { + TAILQ_REMOVE(&spp->spi_swapdev, sdp, swd_next); + uvmexp.nswapdev--; } + return (sdp); + } } return (NULL); } @@ -566,10 +564,8 @@ swaplist_trim(void) { struct swappri *spp, *nextspp; - for (spp = LIST_FIRST(&swap_priority); spp != NULL; spp = nextspp) { - nextspp = LIST_NEXT(spp, spi_swappri); - if (CIRCLEQ_FIRST(&spp->spi_swapdev) != - (void *)&spp->spi_swapdev) + LIST_FOREACH_SAFE(spp, &swap_priority, spi_swappri, nextspp) { + if (!TAILQ_EMPTY(&spp->spi_swapdev)) continue; LIST_REMOVE(spp, spi_swappri); free(spp, M_VMSWAP); @@ -608,15 +604,14 @@ swapdrum_getsdp(int pgno) struct swapdev *sdp; struct swappri *spp; - for (spp = LIST_FIRST(&swap_priority); spp != NULL; - spp = LIST_NEXT(spp, spi_swappri)) - for (sdp = CIRCLEQ_FIRST(&spp->spi_swapdev); - sdp != (void *)&spp->spi_swapdev; - sdp = CIRCLEQ_NEXT(sdp, swd_next)) + LIST_FOREACH(spp, &swap_priority, spi_swappri) { + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { if (pgno >= sdp->swd_drumoffset && pgno < (sdp->swd_drumoffset + sdp->swd_drumsize)) { return sdp; } + } + } return NULL; } @@ -674,25 +669,25 @@ sys_swapctl(struct proc *p, void *v, register_t *retval) sep = (struct swapent *)SCARG(uap, arg); count = 0; - for (spp = LIST_FIRST(&swap_priority); spp != NULL; - spp = LIST_NEXT(spp, spi_swappri)) { - for (sdp = CIRCLEQ_FIRST(&spp->spi_swapdev); - sdp != (void *)&spp->spi_swapdev && misc-- > 0; - sdp = CIRCLEQ_NEXT(sdp, swd_next)) { + LIST_FOREACH(spp, &swap_priority, spi_swappri) { + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { + if (count >= misc) + continue; + sdp->swd_inuse = btodb((u_int64_t)sdp->swd_npginuse << PAGE_SHIFT); error = copyout(&sdp->swd_se, sep, sizeof(struct swapent)); + if (error) + goto out; /* now copy out the path if necessary */ - if (error == 0) - error = copyoutstr(sdp->swd_path, - sep->se_path, sizeof(sep->se_path), - NULL); - + error = copyoutstr(sdp->swd_path, + sep->se_path, sizeof(sep->se_path), NULL); if (error) goto out; + count++; sep++; } @@ -1439,7 +1434,7 @@ sw_reg_iodone_internal(void *xvbp, void *xvnx) * uvm_swap_alloc: allocate space on swap * * => allocation is done "round robin" down the priority list, as we - * allocate in a priority we "rotate" the circle queue. + * allocate in a priority we "rotate" the tail queue. * => space can be freed with uvm_swap_free * => we return the page slot number in /dev/drum (0 == invalid slot) * => we lock uvm.swap_data_lock @@ -1463,11 +1458,8 @@ uvm_swap_alloc(int *nslots, boolean_t lessok) */ ReTry: /* XXXMRG */ - for (spp = LIST_FIRST(&swap_priority); spp != NULL; - spp = LIST_NEXT(spp, spi_swappri)) { - for (sdp = CIRCLEQ_FIRST(&spp->spi_swapdev); - sdp != (void *)&spp->spi_swapdev; - sdp = CIRCLEQ_NEXT(sdp,swd_next)) { + LIST_FOREACH(spp, &swap_priority, spi_swappri) { + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { /* if it's not enabled, then we can't swap from it */ if ((sdp->swd_flags & SWF_ENABLE) == 0) continue; @@ -1480,10 +1472,10 @@ ReTry: /* XXXMRG */ } /* - * successful allocation! now rotate the circleq. + * successful allocation! now rotate the tailq. */ - CIRCLEQ_REMOVE(&spp->spi_swapdev, sdp, swd_next); - CIRCLEQ_INSERT_TAIL(&spp->spi_swapdev, sdp, swd_next); + TAILQ_REMOVE(&spp->spi_swapdev, sdp, swd_next); + TAILQ_INSERT_TAIL(&spp->spi_swapdev, sdp, swd_next); sdp->swd_npginuse += *nslots; uvmexp.swpginuse += *nslots; /* done! return drum slot number */ @@ -2031,14 +2023,12 @@ uvm_hibswap(dev_t dev, u_long *sp, u_long *ep) if (uvmexp.nswapdev < 1 || dev != swdevt[0].sw_dev) return (1); - for (spp = LIST_FIRST(&swap_priority); spp != NULL; - spp = LIST_NEXT(spp, spi_swappri)) - for (sdp = CIRCLEQ_FIRST(&spp->spi_swapdev); - sdp != (void *)&spp->spi_swapdev; - sdp = CIRCLEQ_NEXT(sdp,swd_next)) { + LIST_FOREACH(spp, &swap_priority, spi_swappri) { + TAILQ_FOREACH(sdp, &spp->spi_swapdev, swd_next) { if (sdp->swd_dev == dev) swd = sdp; } + } if (swd == NULL || (swd->swd_flags & SWF_ENABLE) == 0) return (1); |