describe ap (Kirk); delete lfs_mntinvalbuf, lfs_vinvalbuf, add
[unix-history] / usr / src / sys / kern / subr_rmap.c
index a841721..1f0a45e 100644 (file)
@@ -1,13 +1,18 @@
-/*     subr_rmap.c     4.4     81/03/09        */
+/*-
+ * Copyright (c) 1982, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
+ *
+ *     @(#)subr_rmap.c 7.10 (Berkeley) %G%
+ */
 
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/map.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/proc.h"
-#include "../h/mtpr.h"
-#include "../h/text.h"
+#include "param.h"
+#include "systm.h"
+#include "map.h"
+#include "dmap.h"              /* XXX */
+#include "proc.h"
+#include "kernel.h"
 
 /*
  * Resource map handling routines.
 
 /*
  * Resource map handling routines.
  * The map itself is initialized with size elements free
  * starting at addr.
  */
  * The map itself is initialized with size elements free
  * starting at addr.
  */
+void
 rminit(mp, size, addr, name, mapsize)
        register struct map *mp;
 rminit(mp, size, addr, name, mapsize)
        register struct map *mp;
-       int size, addr;
+       long size, addr;
        char *name;
        int mapsize;
 {
        char *name;
        int mapsize;
 {
@@ -66,28 +72,28 @@ rminit(mp, size, addr, name, mapsize)
         */
        ep->m_size = size;
        ep->m_addr = addr;
         */
        ep->m_size = size;
        ep->m_addr = addr;
+       (++ep)->m_size = 0;
+       ep->m_addr = 0;
 }
 
 /*
 }
 
 /*
- * Allocate 'size' units from the given
- * map. Return the base of the allocated space.
- * In a map, the addresses are increasing and the
- * list is terminated by a 0 size.
- *
- * Algorithm is first-fit.
+ * A piece of memory of at least size units is allocated from the
+ * specified map using a first-fit algorithm. It returns the starting
+ * address of the allocated space.
  *
  *
- * This routine knows about the interleaving of the swapmap
- * and handles that.
+ * This routine knows about and handles the interleaving of the swapmap.
  */
  */
+long
 rmalloc(mp, size)
        register struct map *mp;
 rmalloc(mp, size)
        register struct map *mp;
+       long size;
 {
        register struct mapent *ep = (struct mapent *)(mp+1);
        register int addr;
        register struct mapent *bp;
        swblk_t first, rest;
 
 {
        register struct mapent *ep = (struct mapent *)(mp+1);
        register int addr;
        register struct mapent *bp;
        swblk_t first, rest;
 
-       if (size <= 0 || mp == swapmap && size > DMMAX)
+       if (size <= 0 || mp == swapmap && size > dmmax)
                panic("rmalloc");
        /*
         * Search for a piece of the resource map which has enough
                panic("rmalloc");
        /*
         * Search for a piece of the resource map which has enough
@@ -100,8 +106,8 @@ rmalloc(mp, size)
                         * then have to respect interleaving
                         * boundaries.
                         */
                         * then have to respect interleaving
                         * boundaries.
                         */
-                       if (mp == swapmap &&
-                           (first = DMMAX - bp->m_addr%DMMAX) < bp->m_size) {
+                       if (mp == swapmap && nswdev > 1 &&
+                           (first = dmmax - bp->m_addr%dmmax) < size) {
                                if (bp->m_size - first < size)
                                        continue;
                                addr = bp->m_addr + first;
                                if (bp->m_size - first < size)
                                        continue;
                                addr = bp->m_addr + first;
@@ -134,14 +140,15 @@ rmalloc(mp, size)
 }
 
 /*
 }
 
 /*
- * Free the previously allocated space at addr
- * of size units into the specified map.
- * Sort addr into map and combine on
- * one or both ends if possible.
+ * The previously allocated space at addr of size units is freed
+ * into the specified map. This routine is responsible for sorting
+ * the frred space into the correct location in the map, and coalescing
+ * it with free space on either side if they adjoin.
  */
  */
+void
 rmfree(mp, size, addr)
        struct map *mp;
 rmfree(mp, size, addr)
        struct map *mp;
-       register int size, addr;
+       long size, addr;
 {
        struct mapent *firstbp;
        register struct mapent *bp;
 {
        struct mapent *firstbp;
        register struct mapent *bp;
@@ -189,7 +196,7 @@ rmfree(mp, size, addr)
                                (bp-1)->m_size = bp->m_size;
                        }
                }
                                (bp-1)->m_size = bp->m_size;
                        }
                }
-               goto done;
+               return;
        }
        /*
         * Don't abut on the left, check for abutting on
        }
        /*
         * Don't abut on the left, check for abutting on
@@ -200,7 +207,7 @@ rmfree(mp, size, addr)
                        goto badrmfree;
                bp->m_addr -= size;
                bp->m_size += size;
                        goto badrmfree;
                bp->m_addr -= size;
                bp->m_size += size;
-               goto done;
+               return;
        }
        /*
         * Don't abut at all.  Make a new entry
        }
        /*
         * Don't abut at all.  Make a new entry
@@ -235,14 +242,6 @@ rmfree(mp, size, addr)
                bp[-1] = bp[0];
                bp[0].m_size = bp[0].m_addr = 0;
        }
                bp[-1] = bp[0];
                bp[0].m_size = bp[0].m_addr = 0;
        }
-done:
-       /*
-        * THIS IS RIDICULOUS... IT DOESN'T BELONG HERE!
-        */
-       if ((mp == kernelmap) && kmapwnt) {
-               kmapwnt = 0;
-               wakeup((caddr_t)kernelmap);
-       }
        return;
 badrmfree:
        panic("bad rmfree");
        return;
 badrmfree:
        panic("bad rmfree");