--- Gnu-Mach/vm/vm_fault.c 2020/09/02 04:42:52 1.1.1.2 +++ Gnu-Mach/vm/vm_fault.c 2020/09/02 04:45:24 1.1.1.3 @@ -32,15 +32,13 @@ * * Page fault handling module. */ -#include -#include -#include - +#include #include #include #include /* for error codes */ #include +#include #include #include #include @@ -51,11 +49,10 @@ #include #include #include -#include "memory_object_user.h" +#include /* For memory_object_data_{request,unlock} */ -#include #include -#include +#include #if MACH_PCSAMPLE #include @@ -87,7 +84,7 @@ typedef struct vm_fault_state { vm_prot_t vmfp_access; } vm_fault_state_t; -zone_t vm_fault_state_zone = 0; +struct kmem_cache vm_fault_state_cache; int vm_object_absent_max = 50; @@ -107,12 +104,10 @@ extern struct db_watchpoint *db_watchpoi * Purpose: * Initialize our private data structures. */ -void vm_fault_init() +void vm_fault_init(void) { - vm_fault_state_zone = zinit(sizeof(vm_fault_state_t), - THREAD_MAX * sizeof(vm_fault_state_t), - sizeof(vm_fault_state_t), - 0, "vm fault state"); + kmem_cache_init(&vm_fault_state_cache, "vm_fault_state", + sizeof(vm_fault_state_t), 0, NULL, NULL, NULL, 0); } /* @@ -243,7 +238,6 @@ vm_fault_return_t vm_fault_page(first_ob boolean_t look_for_page; vm_prot_t access_required; -#ifdef CONTINUATIONS if (resume) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; @@ -257,13 +251,10 @@ vm_fault_return_t vm_fault_page(first_ob access_required = state->vmfp_access; goto after_thread_block; } -#else /* not CONTINUATIONS */ - assert(continuation == 0); - assert(!resume); -#endif /* not CONTINUATIONS */ vm_stat_sample(SAMPLED_PC_VM_FAULTS_ANY); vm_stat.faults++; /* needs lock XXX */ + current_task()->faults++; /* * Recovery actions @@ -365,7 +356,6 @@ vm_fault_return_t vm_fault_page(first_ob PAGE_ASSERT_WAIT(m, interruptible); vm_object_unlock(object); -#ifdef CONTINUATIONS if (continuation != (void (*)()) 0) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; @@ -387,7 +377,6 @@ vm_fault_return_t vm_fault_page(first_ob counter(c_vm_fault_page_block_busy_user++); thread_block(continuation); } else -#endif /* CONTINUATIONS */ { counter(c_vm_fault_page_block_busy_kernel++); thread_block((void (*)()) 0); @@ -483,6 +472,7 @@ vm_fault_return_t vm_fault_page(first_ob vm_stat_sample(SAMPLED_PC_VM_ZFILL_FAULTS); vm_stat.zero_fill_count++; + current_task()->zero_fills++; vm_object_lock(object); pmap_clear_modify(m->phys_addr); break; @@ -564,6 +554,7 @@ vm_fault_return_t vm_fault_page(first_ob if (m->inactive) { vm_stat_sample(SAMPLED_PC_VM_REACTIVATION_FAULTS); vm_stat.reactivations++; + current_task()->reactivations++; } VM_PAGE_QUEUES_REMOVE(m); @@ -663,13 +654,14 @@ vm_fault_return_t vm_fault_page(first_ob vm_stat.pageins++; vm_stat_sample(SAMPLED_PC_VM_PAGEIN_FAULTS); + current_task()->pageins++; if ((rc = memory_object_data_request(object->pager, object->pager_request, m->offset + object->paging_offset, PAGE_SIZE, access_required)) != KERN_SUCCESS) { if (rc != MACH_SEND_INTERRUPTED) - printf("%s(0x%x, 0x%x, 0x%x, 0x%x, 0x%x) failed, %d\n", + printf("%s(0x%p, 0x%p, 0x%lx, 0x%x, 0x%x) failed, %x\n", "memory_object_data_request", object->pager, object->pager_request, @@ -752,6 +744,7 @@ vm_fault_return_t vm_fault_page(first_ob vm_page_zero_fill(m); vm_stat_sample(SAMPLED_PC_VM_ZFILL_FAULTS); vm_stat.zero_fill_count++; + current_task()->zero_fills++; vm_object_lock(object); pmap_clear_modify(m->phys_addr); break; @@ -867,6 +860,7 @@ vm_fault_return_t vm_fault_page(first_ob vm_stat.cow_faults++; vm_stat_sample(SAMPLED_PC_VM_COW_FAULTS); + current_task()->cow_faults++; object = first_object; offset = first_offset; @@ -1099,7 +1093,6 @@ vm_fault_return_t vm_fault_page(first_ob block_and_backoff: vm_fault_cleanup(object, first_m); -#ifdef CONTINUATIONS if (continuation != (void (*)()) 0) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; @@ -1114,7 +1107,6 @@ vm_fault_return_t vm_fault_page(first_ob counter(c_vm_fault_page_block_backoff_user++); thread_block(continuation); } else -#endif /* CONTINUATIONS */ { counter(c_vm_fault_page_block_backoff_kernel++); thread_block((void (*)()) 0); @@ -1148,7 +1140,6 @@ vm_fault_return_t vm_fault_page(first_ob * and deallocated when leaving vm_fault. */ -#ifdef CONTINUATIONS void vm_fault_continue() { @@ -1162,7 +1153,6 @@ vm_fault_continue() TRUE, state->vmf_continuation); /*NOTREACHED*/ } -#endif /* CONTINUATIONS */ kern_return_t vm_fault(map, vaddr, fault_type, change_wiring, resume, continuation) @@ -1186,7 +1176,6 @@ kern_return_t vm_fault(map, vaddr, fault register vm_page_t m; /* Fast access to result_page */ -#ifdef CONTINUATIONS if (resume) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; @@ -1220,19 +1209,15 @@ kern_return_t vm_fault(map, vaddr, fault /* * if this assignment stmt is written as - * 'active_threads[cpu_number()] = zalloc()', - * cpu_number may be evaluated before zalloc; - * if zalloc blocks, cpu_number will be wrong + * 'active_threads[cpu_number()] = kmem_cache_alloc()', + * cpu_number may be evaluated before kmem_cache_alloc; + * if kmem_cache_alloc blocks, cpu_number will be wrong */ - state = (char *) zalloc(vm_fault_state_zone); + state = (char *) kmem_cache_alloc(&vm_fault_state_cache); current_thread()->ith_other = state; } -#else /* not CONTINUATIONS */ - assert(continuation == 0); - assert(!resume); -#endif /* not CONTINUATIONS */ RetryFault: ; @@ -1267,7 +1252,6 @@ kern_return_t vm_fault(map, vaddr, fault object->ref_count++; vm_object_paging_begin(object); -#ifdef CONTINUATIONS if (continuation != (void (*)()) 0) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; @@ -1294,7 +1278,6 @@ kern_return_t vm_fault(map, vaddr, fault &prot, &result_page, &top_page, FALSE, vm_fault_continue); } else -#endif /* CONTINUATIONS */ { kr = vm_fault_page(object, offset, fault_type, (change_wiring && !wired), !change_wiring, @@ -1323,7 +1306,6 @@ kern_return_t vm_fault(map, vaddr, fault kr = KERN_SUCCESS; goto done; case VM_FAULT_MEMORY_SHORTAGE: -#ifdef CONTINUATIONS if (continuation != (void (*)()) 0) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; @@ -1342,7 +1324,6 @@ kern_return_t vm_fault(map, vaddr, fault VM_PAGE_WAIT(vm_fault_continue); } else -#endif /* CONTINUATIONS */ VM_PAGE_WAIT((void (*)()) 0); goto RetryFault; case VM_FAULT_FICTITIOUS_SHORTAGE: @@ -1508,16 +1489,14 @@ kern_return_t vm_fault(map, vaddr, fault #undef RELEASE_PAGE done: -#ifdef CONTINUATIONS if (continuation != (void (*)()) 0) { register vm_fault_state_t *state = (vm_fault_state_t *) current_thread()->ith_other; - zfree(vm_fault_state_zone, (vm_offset_t) state); + kmem_cache_free(&vm_fault_state_cache, (vm_offset_t) state); (*continuation)(kr); /*NOTREACHED*/ } -#endif /* CONTINUATIONS */ return(kr); } @@ -1665,6 +1644,7 @@ kern_return_t vm_fault_wire_fast(map, va vm_prot_t prot; vm_stat.faults++; /* needs lock XXX */ + current_task()->faults++; /* * Recovery actions */