diff options
author | Mike Larkin <mlarkin@cvs.openbsd.org> | 2012-07-11 10:07:41 +0000 |
---|---|---|
committer | Mike Larkin <mlarkin@cvs.openbsd.org> | 2012-07-11 10:07:41 +0000 |
commit | a860b51fe2eb6a410556373b230b0bd6c8535f87 (patch) | |
tree | cb1481b10e771b60dcefafb2058f712c947241f3 | |
parent | ec5a5808178841e2ba2ba3b8542340bfede603b2 (diff) |
add uvm_swap_check_range to scan for contig free space at end of swap.
will be needed shortly for hibernate.
ok deraadt@
-rw-r--r-- | sys/uvm/uvm_swap.c | 46 | ||||
-rw-r--r-- | sys/uvm/uvm_swap.h | 3 |
2 files changed, 47 insertions, 2 deletions
diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index 6610be38497..6b7568b0a65 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.c,v 1.105 2012/06/14 15:53:38 jasper Exp $ */ +/* $OpenBSD: uvm_swap.c,v 1.106 2012/07/11 10:07:40 mlarkin Exp $ */ /* $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $ */ /* @@ -2080,3 +2080,47 @@ swapmount(void) VOP_UNLOCK(vp, 0, curproc); } + +/* + * Check if free swap available at end of swap dev swdev. + * Used by hibernate to check for usable swap area before writing the image + */ +int +uvm_swap_check_range(dev_t swdev, size_t size) +{ + struct swapdev *sdp, *swd = NULL; + struct swappri *spp; + struct extent *ex; + struct extent_region *exr; + int r = 0, start, npages = size / PAGE_SIZE; + + /* no swap devices configured yet? then range is not in use */ + if (uvmexp.nswapdev < 1) + return (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; + sdp = CIRCLEQ_NEXT(sdp,swd_next)) { + if (sdp->swd_dev == swdev) + swd = sdp; + } + + if (swd == NULL) + return (0); + + if ((swd->swd_flags & SWF_ENABLE) == 0) + return (0); + + ex = swd->swd_ex; + start = swd->swd_drumsize-npages; + + LIST_FOREACH(exr, &ex->ex_regions, er_link) + { + if (exr->er_end >= start) + r = 1; + } + + return (r); +} diff --git a/sys/uvm/uvm_swap.h b/sys/uvm/uvm_swap.h index ba3629579a5..c0dc9e68e12 100644 --- a/sys/uvm/uvm_swap.h +++ b/sys/uvm/uvm_swap.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_swap.h,v 1.13 2010/07/01 19:48:05 oga Exp $ */ +/* $OpenBSD: uvm_swap.h,v 1.14 2012/07/11 10:07:40 mlarkin Exp $ */ /* $NetBSD: uvm_swap.h,v 1.5 2000/01/11 06:57:51 chs Exp $ */ /* @@ -44,6 +44,7 @@ int uvm_swap_alloc(int *, boolean_t); void uvm_swap_free(int, int); void uvm_swap_markbad(int, int); void uvm_swap_freepages(struct vm_page **, int); +int uvm_swap_check_range(dev_t, size_t); #ifdef UVM_SWAP_ENCRYPT void uvm_swap_initcrypt_all(void); void uvm_swap_finicrypt_all(void); |