4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / sys / vm / vm_pager.c
index 40f5b36..b3370cd 100644 (file)
@@ -1,16 +1,39 @@
 /* 
 /* 
- * Copyright (c) 1985, 1986 Avadis Tevanian, Jr., Michael Wayne Young
- * Copyright (c) 1987 Carnegie-Mellon University
- * Copyright (c) 1991 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * The Mach Operating System project at Carnegie-Mellon University.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * The Mach Operating System project at Carnegie-Mellon University.
  *
- * The CMU software License Agreement specifies the terms and conditions
- * for use and redistribution.
+ * %sccs.include.redist.c%
+ *
+ *     @(#)vm_pager.c  8.1 (Berkeley) %G%
+ *
+ *
+ * Copyright (c) 1987, 1990 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Authors: Avadis Tevanian, Jr., Michael Wayne Young
+ * 
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
  *
  *
- *     @(#)vm_pager.c  7.2 (Berkeley) %G%
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
  */
 
 /*
  */
 
 /*
  *     for builtin pagers.
  */
 
  *     for builtin pagers.
  */
 
-#include "param.h"
-#include "malloc.h"
-
-#include "vm.h"
-#include "vm_page.h"
-#include "vm_kern.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
 
 
-#ifdef hp300
-#include "../hp300/hp300/pte.h"                        /* XXX XXX XXX */
-#endif
+#include <vm/vm.h>
+#include <vm/vm_page.h>
+#include <vm/vm_kern.h>
 
 
-#include "swappager.h"
-
-#if NSWAPPAGER > 0
+#ifdef SWAPPAGER
 extern struct pagerops swappagerops;
 extern struct pagerops swappagerops;
-#else
-#define        swappagerops    NULL
 #endif
 #endif
-#include "vnodepager.h"
-#if NVNODEPAGER > 0
+
+#ifdef VNODEPAGER
 extern struct pagerops vnodepagerops;
 extern struct pagerops vnodepagerops;
-#else
-#define        vnodepagerops   NULL
 #endif
 #endif
-#include "devpager.h"
-#if NDEVPAGER > 0
+
+#ifdef DEVPAGER
 extern struct pagerops devicepagerops;
 extern struct pagerops devicepagerops;
-#else
-#define        devicepagerops  NULL
 #endif
 
 struct pagerops *pagertab[] = {
 #endif
 
 struct pagerops *pagertab[] = {
+#ifdef SWAPPAGER
        &swappagerops,          /* PG_SWAP */
        &swappagerops,          /* PG_SWAP */
+#endif
+#ifdef VNODEPAGER
        &vnodepagerops,         /* PG_VNODE */
        &vnodepagerops,         /* PG_VNODE */
+#endif
+#ifdef DEVPAGER
        &devicepagerops,        /* PG_DEV */
        &devicepagerops,        /* PG_DEV */
+#endif
 };
 int npagers = sizeof (pagertab) / sizeof (pagertab[0]);
 
 };
 int npagers = sizeof (pagertab) / sizeof (pagertab[0]);
 
@@ -64,17 +82,17 @@ struct pagerops *dfltpagerops = NULL;       /* default pager */
  */
 #define PAGER_MAP_SIZE (256 * PAGE_SIZE)
 vm_map_t pager_map;
  */
 #define PAGER_MAP_SIZE (256 * PAGE_SIZE)
 vm_map_t pager_map;
+vm_offset_t pager_sva, pager_eva;
 
 void
 vm_pager_init()
 {
 
 void
 vm_pager_init()
 {
-       vm_offset_t whocares1, whocares2;
        struct pagerops **pgops;
 
        /*
         * Allocate a kernel submap for tracking get/put page mappings
         */
        struct pagerops **pgops;
 
        /*
         * Allocate a kernel submap for tracking get/put page mappings
         */
-       pager_map = kmem_suballoc(kernel_map, &whocares1, &whocares2,
+       pager_map = kmem_suballoc(kernel_map, &pager_sva, &pager_eva,
                                  PAGER_MAP_SIZE, FALSE);
        /*
         * Initialize known pagers
                                  PAGER_MAP_SIZE, FALSE);
        /*
         * Initialize known pagers
@@ -112,6 +130,7 @@ vm_pager_deallocate(pager)
        VM_PAGER_DEALLOC(pager);
 }
 
        VM_PAGER_DEALLOC(pager);
 }
 
+int
 vm_pager_get(pager, m, sync)
        vm_pager_t      pager;
        vm_page_t       m;
 vm_pager_get(pager, m, sync)
        vm_pager_t      pager;
        vm_page_t       m;
@@ -124,6 +143,7 @@ vm_pager_get(pager, m, sync)
        return(VM_PAGER_GET(pager, m, sync));
 }
 
        return(VM_PAGER_GET(pager, m, sync));
 }
 
+int
 vm_pager_put(pager, m, sync)
        vm_pager_t      pager;
        vm_page_t       m;
 vm_pager_put(pager, m, sync)
        vm_pager_t      pager;
        vm_page_t       m;
@@ -163,18 +183,18 @@ vm_pager_map_page(m)
 {
        vm_offset_t kva;
 
 {
        vm_offset_t kva;
 
+#ifdef DEBUG
+       if ((m->flags & PG_BUSY) == 0)
+               panic("vm_pager_map_page: page not busy");
+       if (m->flags & PG_PAGEROWNED)
+               printf("vm_pager_map_page: page %x already in pager\n", m);
+#endif
        kva = kmem_alloc_wait(pager_map, PAGE_SIZE);
        kva = kmem_alloc_wait(pager_map, PAGE_SIZE);
-#ifdef hp300
-       /*
-        * XXX: cannot use pmap_enter as the mapping would be
-        * removed by a pmap_remove_all().
-        */
-       *(int *)kvtopte(kva) = VM_PAGE_TO_PHYS(m) | PG_CI | PG_V;
-       TBIS(kva);
-#else
+#ifdef DEBUG
+       m->flags |= PG_PAGEROWNED;
+#endif
        pmap_enter(vm_map_pmap(pager_map), kva, VM_PAGE_TO_PHYS(m),
                   VM_PROT_DEFAULT, TRUE);
        pmap_enter(vm_map_pmap(pager_map), kva, VM_PAGE_TO_PHYS(m),
                   VM_PROT_DEFAULT, TRUE);
-#endif
        return(kva);
 }
 
        return(kva);
 }
 
@@ -182,11 +202,20 @@ void
 vm_pager_unmap_page(kva)
        vm_offset_t     kva;
 {
 vm_pager_unmap_page(kva)
        vm_offset_t     kva;
 {
-#ifdef hp300
-       *(int *)kvtopte(kva) = PG_NV;
-       TBIS(kva);
+#ifdef DEBUG
+       vm_page_t m;
+
+       m = PHYS_TO_VM_PAGE(pmap_extract(vm_map_pmap(pager_map), kva));
 #endif
 #endif
+       pmap_remove(vm_map_pmap(pager_map), kva, kva + PAGE_SIZE);
        kmem_free_wakeup(pager_map, kva, PAGE_SIZE);
        kmem_free_wakeup(pager_map, kva, PAGE_SIZE);
+#ifdef DEBUG
+       if (m->flags & PG_PAGEROWNED)
+               m->flags &= ~PG_PAGEROWNED;
+       else
+               printf("vm_pager_unmap_page: page %x(%x/%x) not owned\n",
+                      m, kva, VM_PAGE_TO_PHYS(m));
+#endif
 }
 
 vm_pager_t
 }
 
 vm_pager_t
@@ -209,6 +238,7 @@ vm_pager_lookup(list, handle)
  * This routine gains a reference to the object.
  * Explicit deallocation is necessary.
  */
  * This routine gains a reference to the object.
  * Explicit deallocation is necessary.
  */
+int
 pager_cache(object, should_cache)
        vm_object_t     object;
        boolean_t       should_cache;
 pager_cache(object, should_cache)
        vm_object_t     object;
        boolean_t       should_cache;
@@ -218,7 +248,10 @@ pager_cache(object, should_cache)
 
        vm_object_cache_lock();
        vm_object_lock(object);
 
        vm_object_cache_lock();
        vm_object_lock(object);
-       object->can_persist = should_cache;
+       if (should_cache)
+               object->flags |= OBJ_CANPERSIST;
+       else
+               object->flags &= ~OBJ_CANPERSIST;
        vm_object_unlock(object);
        vm_object_cache_unlock();
 
        vm_object_unlock(object);
        vm_object_cache_unlock();