reorganization to move ufsmount ops to be vnode ops
[unix-history] / usr / src / sys / vm / vm_fault.c
index 4c73ad4..19ef27f 100644 (file)
@@ -1,5 +1,16 @@
 /* 
 /* 
- * Copyright (c) 1987 Carnegie-Mellon University.
+ * Copyright (c) 1991 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.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)vm_fault.c  7.8 (Berkeley) %G%
+ *
+ *
+ * Copyright (c) 1987, 1990 Carnegie-Mellon University.
  * All rights reserved.
  *
  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
  * All rights reserved.
  *
  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  * 
  * 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 Carnegie
- * any improvements or extensions that they make and grant Carnegie
- * the rights to redistribute these changes.  We can be reached at
- * mach@cs.cmu.edu or
- *     Project Mach
- *     School of Computer Science
- *     Carnegie Mellon University
- *     Pittsburgh PA 15213-3890
+ * Carnegie Mellon requests users of this software to return to
  *
  *
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
  *
  *
- * Copyright (c) 1991 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.
- *
- * %sccs.include.redist.c%
- *
- *     @(#)vm_fault.c  7.3 (Berkeley) %G%
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
  */
 
 /*
  */
 
 /*
  */
 
 #include "param.h"
  */
 
 #include "param.h"
-#include "../vm/vm_param.h"
-#include "../vm/vm_map.h"
-#include "../vm/vm_object.h"
-#include "../vm/vm_page.h"
-#include "../vm/pmap.h"
-#include "../vm/vm_statistics.h"
-#include "../vm/vm_pageout.h"
+
+#include "vm.h"
+#include "vm_page.h"
+#include "vm_pageout.h"
 
 /*
  *     vm_fault:
 
 /*
  *     vm_fault:
@@ -88,7 +86,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
        vm_page_t               old_m;
        vm_object_t             next_object;
 
        vm_page_t               old_m;
        vm_object_t             next_object;
 
-       vm_stat.faults++;               /* needs lock XXX */
+       cnt.v_vm_faults++;              /* needs lock XXX */
 /*
  *     Recovery actions
  */
 /*
  *     Recovery actions
  */
@@ -147,7 +145,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
        if (wired)
                fault_type = prot;
 
        if (wired)
                fault_type = prot;
 
-       first_m = VM_PAGE_NULL;
+       first_m = NULL;
 
        /*
         *      Make a reference to this object to
 
        /*
         *      Make a reference to this object to
@@ -209,7 +207,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
 
        while (TRUE) {
                m = vm_page_lookup(object, offset);
 
        while (TRUE) {
                m = vm_page_lookup(object, offset);
-               if (m != VM_PAGE_NULL) {
+               if (m != NULL) {
                        /*
                         *      If the page is being brought in,
                         *      wait for it and then retry.
                        /*
                         *      If the page is being brought in,
                         *      wait for it and then retry.
@@ -280,15 +278,15 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                                queue_remove(&vm_page_queue_inactive, m,
                                                vm_page_t, pageq);
                                m->inactive = FALSE;
                                queue_remove(&vm_page_queue_inactive, m,
                                                vm_page_t, pageq);
                                m->inactive = FALSE;
-                               vm_page_inactive_count--;
-                               vm_stat.reactivations++;
+                               cnt.v_inactive_count--;
+                               cnt.v_reactivated++;
                        } 
 
                        if (m->active) {
                                queue_remove(&vm_page_queue_active, m,
                                                vm_page_t, pageq);
                                m->active = FALSE;
                        } 
 
                        if (m->active) {
                                queue_remove(&vm_page_queue_active, m,
                                                vm_page_t, pageq);
                                m->active = FALSE;
-                               vm_page_active_count--;
+                               cnt.v_active_count--;
                        }
                        vm_page_unlock_queues();
 
                        }
                        vm_page_unlock_queues();
 
@@ -300,7 +298,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                        break;
                }
 
                        break;
                }
 
-               if (((object->pager != vm_pager_null) &&
+               if (((object->pager != NULL) &&
                                (!change_wiring || wired))
                    || (object == first_object)) {
 
                                (!change_wiring || wired))
                    || (object == first_object)) {
 
@@ -311,14 +309,14 @@ vm_fault(map, vaddr, fault_type, change_wiring)
 
                        m = vm_page_alloc(object, offset);
 
 
                        m = vm_page_alloc(object, offset);
 
-                       if (m == VM_PAGE_NULL) {
+                       if (m == NULL) {
                                UNLOCK_AND_DEALLOCATE;
                                VM_WAIT;
                                goto RetryFault;
                        }
                }
 
                                UNLOCK_AND_DEALLOCATE;
                                VM_WAIT;
                                goto RetryFault;
                        }
                }
 
-               if ((object->pager != vm_pager_null) &&
+               if ((object->pager != NULL) &&
                                (!change_wiring || wired)) {
                        int rv;
 
                                (!change_wiring || wired)) {
                        int rv;
 
@@ -349,7 +347,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                                 */
                                m = vm_page_lookup(object, offset);
 
                                 */
                                m = vm_page_lookup(object, offset);
 
-                               vm_stat.pageins++;
+                               cnt.v_pageins++;
                                m->fake = FALSE;
                                pmap_clear_modify(VM_PAGE_TO_PHYS(m));
                                break;
                                m->fake = FALSE;
                                pmap_clear_modify(VM_PAGE_TO_PHYS(m));
                                break;
@@ -403,7 +401,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
 
                offset += object->shadow_offset;
                next_object = object->shadow;
 
                offset += object->shadow_offset;
                next_object = object->shadow;
-               if (next_object == VM_OBJECT_NULL) {
+               if (next_object == NULL) {
                        /*
                         *      If there's no object left, fill the page
                         *      in the top object with zeros.
                        /*
                         *      If there's no object left, fill the page
                         *      in the top object with zeros.
@@ -417,10 +415,10 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                                m = first_m;
                                vm_object_lock(object);
                        }
                                m = first_m;
                                vm_object_lock(object);
                        }
-                       first_m = VM_PAGE_NULL;
+                       first_m = NULL;
 
                        vm_page_zero_fill(m);
 
                        vm_page_zero_fill(m);
-                       vm_stat.zero_fill_count++;
+                       cnt.v_zfod++;
                        m->fake = FALSE;
                        m->absent = FALSE;
                        break;
                        m->fake = FALSE;
                        m->absent = FALSE;
                        break;
@@ -493,31 +491,15 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                         *      can't distinguish those which want the
                         *      original from those which need the
                         *      new copy.
                         *      can't distinguish those which want the
                         *      original from those which need the
                         *      new copy.
+                        *
+                        *      XXX If we know that only one map has
+                        *      access to this page, then we could
+                        *      avoid the pmap_page_protect() call.
                         */
 
                        vm_page_lock_queues();
                         */
 
                        vm_page_lock_queues();
-                       if (!su) {
-                               /*
-                                *      Also, once it's no longer in
-                                *      use by any maps, move it to
-                                *      the inactive queue instead.
-                                */
-
-                               vm_page_deactivate(m);
-                               pmap_remove_all(VM_PAGE_TO_PHYS(m));
-                       }
-                       else {
-                               /*
-                                *      Old page is only (possibly)
-                                *      in use by faulting map.  We
-                                *      should do a pmap_remove on
-                                *      that mapping, but we know
-                                *      that pmap_enter will remove
-                                *      the old mapping before
-                                *      inserting the new one.
-                                */
-                               vm_page_activate(m);
-                       }
+                       vm_page_deactivate(m);
+                       pmap_page_protect(VM_PAGE_TO_PHYS(m), VM_PROT_NONE);
                        vm_page_unlock_queues();
 
                        /*
                        vm_page_unlock_queues();
 
                        /*
@@ -531,7 +513,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                         *      Only use the new page below...
                         */
 
                         *      Only use the new page below...
                         */
 
-                       vm_stat.cow_faults++;
+                       cnt.v_cow_faults++;
                        m = first_m;
                        object = first_object;
                        offset = first_offset;
                        m = first_m;
                        object = first_object;
                        offset = first_offset;
@@ -563,10 +545,10 @@ vm_fault(map, vaddr, fault_type, change_wiring)
         *      copied to the copy-object, we have to copy it there.
         */
     RetryCopy:
         *      copied to the copy-object, we have to copy it there.
         */
     RetryCopy:
-       if (first_object->copy != VM_OBJECT_NULL) {
-               vm_object_t             copy_object = first_object->copy;
-               vm_offset_t             copy_offset;
-               vm_page_t               copy_m;
+       if (first_object->copy != NULL) {
+               vm_object_t copy_object = first_object->copy;
+               vm_offset_t copy_offset;
+               vm_page_t copy_m;
 
                /*
                 *      We only need to copy if we want to write it.
 
                /*
                 *      We only need to copy if we want to write it.
@@ -599,7 +581,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                        copy_offset = first_offset
                                - copy_object->shadow_offset;
                        copy_m = vm_page_lookup(copy_object, copy_offset);
                        copy_offset = first_offset
                                - copy_object->shadow_offset;
                        copy_m = vm_page_lookup(copy_object, copy_offset);
-                       if (page_exists = (copy_m != VM_PAGE_NULL)) {
+                       if (page_exists = (copy_m != NULL)) {
                                if (copy_m->busy) {
 #ifdef DOTHREADS
                                        int     wait_result;
                                if (copy_m->busy) {
 #ifdef DOTHREADS
                                        int     wait_result;
@@ -656,7 +638,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                                 */
                                copy_m = vm_page_alloc(copy_object,
                                                                copy_offset);
                                 */
                                copy_m = vm_page_alloc(copy_object,
                                                                copy_offset);
-                               if (copy_m == VM_PAGE_NULL) {
+                               if (copy_m == NULL) {
                                        /*
                                         *      Wait for a page, then retry.
                                         */
                                        /*
                                         *      Wait for a page, then retry.
                                         */
@@ -668,7 +650,7 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                                        goto RetryFault;
                                }
 
                                        goto RetryFault;
                                }
 
-                               if (copy_object->pager != vm_pager_null) {
+                               if (copy_object->pager != NULL) {
                                        vm_object_unlock(object);
                                        vm_object_unlock(copy_object);
                                        UNLOCK_MAP;
                                        vm_object_unlock(object);
                                        vm_object_unlock(copy_object);
                                        UNLOCK_MAP;
@@ -730,7 +712,8 @@ vm_fault(map, vaddr, fault_type, change_wiring)
                                 *    pmaps use it.)
                                 */
                                vm_page_lock_queues();
                                 *    pmaps use it.)
                                 */
                                vm_page_lock_queues();
-                               pmap_remove_all(VM_PAGE_TO_PHYS(old_m));
+                               pmap_page_protect(VM_PAGE_TO_PHYS(old_m),
+                                                 VM_PROT_NONE);
                                copy_m->clean = FALSE;
                                vm_page_activate(copy_m);       /* XXX */
                                vm_page_unlock_queues();
                                copy_m->clean = FALSE;
                                vm_page_activate(copy_m);       /* XXX */
                                vm_page_unlock_queues();
@@ -1016,12 +999,12 @@ void vm_fault_copy_entry(dst_map, src_map, dst_entry, src_entry)
                vm_object_lock(dst_object);
                do {
                        dst_m = vm_page_alloc(dst_object, dst_offset);
                vm_object_lock(dst_object);
                do {
                        dst_m = vm_page_alloc(dst_object, dst_offset);
-                       if (dst_m == VM_PAGE_NULL) {
+                       if (dst_m == NULL) {
                                vm_object_unlock(dst_object);
                                VM_WAIT;
                                vm_object_lock(dst_object);
                        }
                                vm_object_unlock(dst_object);
                                VM_WAIT;
                                vm_object_lock(dst_object);
                        }
-               } while (dst_m == VM_PAGE_NULL);
+               } while (dst_m == NULL);
 
                /*
                 *      Find the page in the source object, and copy it in.
 
                /*
                 *      Find the page in the source object, and copy it in.
@@ -1030,7 +1013,7 @@ void vm_fault_copy_entry(dst_map, src_map, dst_entry, src_entry)
                 */
                vm_object_lock(src_object);
                src_m = vm_page_lookup(src_object, dst_offset + src_offset);
                 */
                vm_object_lock(src_object);
                src_m = vm_page_lookup(src_object, dst_offset + src_offset);
-               if (src_m == VM_PAGE_NULL)
+               if (src_m == NULL)
                        panic("vm_fault_copy_wired: page missing");
 
                vm_page_copy(src_m, dst_m);
                        panic("vm_fault_copy_wired: page missing");
 
                vm_page_copy(src_m, dst_m);