describe ap (Kirk); delete lfs_mntinvalbuf, lfs_vinvalbuf, add
[unix-history] / usr / src / sys / kern / subr_rmap.c
index 35e52b6..1f0a45e 100644 (file)
@@ -1,18 +1,17 @@
-/*
- * Copyright (c) 1982 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1982, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
  *
  *
- *     @(#)subr_rmap.c 6.3 (Berkeley) %G%
+ *     @(#)subr_rmap.c 7.10 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
 #include "map.h"
  */
 
 #include "param.h"
 #include "systm.h"
 #include "map.h"
-#include "dir.h"
-#include "user.h"
+#include "dmap.h"              /* XXX */
 #include "proc.h"
 #include "proc.h"
-#include "text.h"
 #include "kernel.h"
 
 /*
 #include "kernel.h"
 
 /*
@@ -47,6 +46,7 @@
  * 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;
        long size, addr;
 rminit(mp, size, addr, name, mapsize)
        register struct map *mp;
        long size, addr;
@@ -72,18 +72,16 @@ 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)
  */
 long
 rmalloc(mp, size)
@@ -109,7 +107,7 @@ rmalloc(mp, size)
                         * boundaries.
                         */
                        if (mp == swapmap && nswdev > 1 &&
                         * boundaries.
                         */
                        if (mp == swapmap && nswdev > 1 &&
-                           (first = dmmax - bp->m_addr%dmmax) < bp->m_size) {
+                           (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;
@@ -142,11 +140,12 @@ 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;
        long size, addr;
 rmfree(mp, size, addr)
        struct map *mp;
        long size, addr;
@@ -197,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
@@ -208,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
@@ -243,100 +242,7 @@ 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");
 }
-
-/*
- * Allocate 'size' units from the given map, starting at address 'addr'.
- * Return 'addr' if successful, 0 if not.
- * This may cause the creation or destruction of a resource map segment.
- *
- * This routine will return failure status if there is not enough room
- * for a required additional map segment.
- *
- * An attempt to use this on 'swapmap' will result in
- * a failure return.  This is due mainly to laziness and could be fixed
- * to do the right thing, although it probably will never be used.
- */
-rmget(mp, size, addr)
-       register struct map *mp;
-{
-       register struct mapent *ep = (struct mapent *)(mp+1);
-       register struct mapent *bp, *bp2;
-
-       if (size <= 0)
-               panic("rmget");
-       if (mp == swapmap)
-               return (0);
-       /*
-        * Look for a map segment containing the requested address.
-        * If none found, return failure.
-        */
-       for (bp = ep; bp->m_size; bp++)
-               if (bp->m_addr <= addr && bp->m_addr + bp->m_size > addr)
-                       break;
-       if (bp->m_size == 0)
-               return (0);
-
-       /*
-        * If segment is too small, return failure.
-        * If big enough, allocate the block, compressing or expanding
-        * the map as necessary.
-        */
-       if (bp->m_addr + bp->m_size < addr + size)
-               return (0);
-       if (bp->m_addr == addr)
-               if (bp->m_addr + bp->m_size == addr + size) {
-                       /*
-                        * Allocate entire segment and compress map
-                        */
-                       bp2 = bp;
-                       while (bp2->m_size) {
-                               bp2++;
-                               (bp2-1)->m_addr = bp2->m_addr;
-                               (bp2-1)->m_size = bp2->m_size;
-                       }
-               } else {
-                       /*
-                        * Allocate first part of segment
-                        */
-                       bp->m_addr += size;
-                       bp->m_size -= size;
-               }
-       else
-               if (bp->m_addr + bp->m_size == addr + size) {
-                       /*
-                        * Allocate last part of segment
-                        */
-                       bp->m_size -= size;
-               } else {
-                       /*
-                        * Allocate from middle of segment, but only
-                        * if table can be expanded.
-                        */
-                       for (bp2=bp; bp2->m_size; bp2++)
-                               ;
-                       if (bp2 == mp->m_limit)
-                               return (0);
-                       while (bp2 > bp) {
-                               (bp2+1)->m_addr = bp2->m_addr;
-                               (bp2+1)->m_size = bp2->m_size;
-                               bp2--;
-                       }
-                       (bp+1)->m_addr = addr + size;
-                       (bp+1)->m_size =
-                           bp->m_addr + bp->m_size - (addr + size);
-                       bp->m_size = addr - bp->m_addr;
-               }
-       return (addr);
-}