From 55c881fbd2ba35c3278e148cd78c2fee621eec43 Mon Sep 17 00:00:00 2001 From: mrg Date: Fri, 10 Oct 1997 13:16:24 +0000 Subject: [PATCH] when creating the per-device extent, use from 0 to nblks, and then extent_alloc_region() any skipped space. this is (basically) what the previous swap code did (with rmaps rather than extents). --- lib/libc/sys/swapctl.2 | 8 +++++++- sys/vm/vm_swap.c | 15 +++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/libc/sys/swapctl.2 b/lib/libc/sys/swapctl.2 index 3a6f0ec9197f..ab905c3ec023 100644 --- a/lib/libc/sys/swapctl.2 +++ b/lib/libc/sys/swapctl.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: swapctl.2,v 1.5 1997/08/27 07:31:36 mikel Exp $ +.\" $NetBSD: swapctl.2,v 1.6 1997/10/10 13:17:32 mrg Exp $ .\" .\" Copyright (c) 1997 Matthew R. Green .\" Copyright (c) 1980, 1991, 1993 @@ -132,6 +132,12 @@ parameters have the same function as for the .Dv SWAP_ON case, except that they change the priority of a currently enabled swap device. .El +.Pp +When swapping is enabled on a block device, the first portion of the disk is +left unused to prevent any disklable present from being overwritten. This +space is allocated from the swap device when the +.Dv SWAP_ON +command is used. .Sh RETURN VALUES If the .Fa cmd diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index 7a1eb4fffc75..0001cdb7f3c9 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm_swap.c,v 1.43 1997/10/10 05:40:30 mrg Exp $ */ +/* $NetBSD: vm_swap.c,v 1.44 1997/10/10 13:16:24 mrg Exp $ */ /* * Copyright (c) 1995, 1996, 1997 Matthew R. Green @@ -164,7 +164,7 @@ struct vndbuf { #define putvndbuf(vbp) \ free((caddr_t)(vbp), M_DEVBUF) -int nswapdev, nswap; +int nswapdev; int swflags; struct extent *swapmap; LIST_HEAD(swap_priority, swappri) swap_priority; @@ -590,8 +590,14 @@ swap_on(p, sdp) /* XXX make this based on ram as well. */ storagesize = EXTENT_FIXED_STORAGE_SIZE(maxproc * 2); storage = malloc(storagesize, M_VMSWAP, M_WAITOK); - sdp->swd_ex = extent_create(name, addr, addr + size, M_VMSWAP, + sdp->swd_ex = extent_create(name, 0, nblks, M_VMSWAP, storage, storagesize, EX_WAITOK); + if (addr) { + if (extent_alloc_region(sdp->swd_ex, 0, addr, EX_WAITOK)) + panic("disklabel region"); + sdp->swd_inuse += addr; + } + if (vp == rootvp) { struct mount *mp; @@ -615,7 +621,6 @@ swap_on(p, sdp) swap_addmap(sdp, size); nswapdev++; - nswap += nblks; sdp->swd_flags |= SWF_ENABLE; return (0); @@ -662,7 +667,6 @@ swap_off(p, sdp) return ENODEV; extent_free(swapmap, sdp->swd_mapoffset, sdp->swd_mapsize, EX_WAITOK); - nswap -= sdp->swd_nblks; nswapdev--; name = sdp->swd_ex->ex_name; extent_destroy(sdp->swd_ex); @@ -1110,7 +1114,6 @@ swapinit() if (vmswapdebug & VMSDB_SWINIT) printf("swapinit\n"); #endif - nswap = 0; nswapdev = 0; if (bdevvp(swapdev, &swapdev_vp)) panic("swapinit: can setup swapdev_vp");