vm_glue.c (178272) | vm_glue.c (181334) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 43 unchanged lines hidden (view full) --- 52 * Carnegie Mellon University 53 * Pittsburgh PA 15213-3890 54 * 55 * any improvements or extensions that they make and grant Carnegie the 56 * rights to redistribute these changes. 57 */ 58 59#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 43 unchanged lines hidden (view full) --- 52 * Carnegie Mellon University 53 * Pittsburgh PA 15213-3890 54 * 55 * any improvements or extensions that they make and grant Carnegie the 56 * rights to redistribute these changes. 57 */ 58 59#include <sys/cdefs.h> |
60__FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 178272 2008-04-17 04:20:10Z jeff $"); | 60__FBSDID("$FreeBSD: head/sys/vm/vm_glue.c 181334 2008-08-05 20:02:31Z jhb $"); |
61 62#include "opt_vm.h" 63#include "opt_kstack_pages.h" 64#include "opt_kstack_max_pages.h" 65 66#include <sys/param.h> 67#include <sys/systm.h> 68#include <sys/limits.h> --- 42 unchanged lines hidden (view full) --- 111static void scheduler(void *); 112SYSINIT(scheduler, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, scheduler, NULL); 113 114#ifndef NO_SWAPPING 115static int swapout(struct proc *); 116static void swapclear(struct proc *); 117#endif 118 | 61 62#include "opt_vm.h" 63#include "opt_kstack_pages.h" 64#include "opt_kstack_max_pages.h" 65 66#include <sys/param.h> 67#include <sys/systm.h> 68#include <sys/limits.h> --- 42 unchanged lines hidden (view full) --- 111static void scheduler(void *); 112SYSINIT(scheduler, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, scheduler, NULL); 113 114#ifndef NO_SWAPPING 115static int swapout(struct proc *); 116static void swapclear(struct proc *); 117#endif 118 |
119 120static volatile int proc0_rescan; 121 122 | |
123/* 124 * MPSAFE 125 * 126 * WARNING! This code calls vm_map_check_protection() which only checks 127 * the associated vm_map_entry range. It does not determine whether the 128 * contents of the memory is actually readable or writable. In most cases 129 * just checking the vm_map_entry is sufficient within the kernel's address 130 * space. --- 547 unchanged lines hidden (view full) --- 678 int pri; 679 680 mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED); 681 mtx_unlock(&Giant); 682 683loop: 684 if (vm_page_count_min()) { 685 VM_WAIT; | 119/* 120 * MPSAFE 121 * 122 * WARNING! This code calls vm_map_check_protection() which only checks 123 * the associated vm_map_entry range. It does not determine whether the 124 * contents of the memory is actually readable or writable. In most cases 125 * just checking the vm_map_entry is sufficient within the kernel's address 126 * space. --- 547 unchanged lines hidden (view full) --- 674 int pri; 675 676 mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED); 677 mtx_unlock(&Giant); 678 679loop: 680 if (vm_page_count_min()) { 681 VM_WAIT; |
686 thread_lock(&thread0); 687 proc0_rescan = 0; 688 thread_unlock(&thread0); | |
689 goto loop; 690 } 691 692 pp = NULL; 693 ppri = INT_MIN; 694 sx_slock(&allproc_lock); 695 FOREACH_PROC_IN_SYSTEM(p) { 696 PROC_LOCK(p); --- 30 unchanged lines hidden (view full) --- 727 PROC_UNLOCK(p); 728 } 729 sx_sunlock(&allproc_lock); 730 731 /* 732 * Nothing to do, back to sleep. 733 */ 734 if ((p = pp) == NULL) { | 682 goto loop; 683 } 684 685 pp = NULL; 686 ppri = INT_MIN; 687 sx_slock(&allproc_lock); 688 FOREACH_PROC_IN_SYSTEM(p) { 689 PROC_LOCK(p); --- 30 unchanged lines hidden (view full) --- 720 PROC_UNLOCK(p); 721 } 722 sx_sunlock(&allproc_lock); 723 724 /* 725 * Nothing to do, back to sleep. 726 */ 727 if ((p = pp) == NULL) { |
735 thread_lock(&thread0); 736 if (!proc0_rescan) { 737 TD_SET_IWAIT(&thread0); 738 mi_switch(SW_VOL | SWT_IWAIT, NULL); 739 } 740 proc0_rescan = 0; 741 thread_unlock(&thread0); | 728 tsleep(&proc0, PVM, "sched", maxslp * hz / 2); |
742 goto loop; 743 } 744 PROC_LOCK(p); 745 746 /* 747 * Another process may be bringing or may have already 748 * brought this process in while we traverse all threads. 749 * Or, this process may even be being swapped out again. 750 */ 751 if (p->p_flag & (P_INMEM | P_SWAPPINGOUT | P_SWAPPINGIN)) { 752 PROC_UNLOCK(p); | 729 goto loop; 730 } 731 PROC_LOCK(p); 732 733 /* 734 * Another process may be bringing or may have already 735 * brought this process in while we traverse all threads. 736 * Or, this process may even be being swapped out again. 737 */ 738 if (p->p_flag & (P_INMEM | P_SWAPPINGOUT | P_SWAPPINGIN)) { 739 PROC_UNLOCK(p); |
753 thread_lock(&thread0); 754 proc0_rescan = 0; 755 thread_unlock(&thread0); | |
756 goto loop; 757 } 758 759 /* 760 * We would like to bring someone in. (only if there is space). 761 * [What checks the space? ] 762 */ 763 faultin(p); 764 PROC_UNLOCK(p); | 740 goto loop; 741 } 742 743 /* 744 * We would like to bring someone in. (only if there is space). 745 * [What checks the space? ] 746 */ 747 faultin(p); 748 PROC_UNLOCK(p); |
765 thread_lock(&thread0); 766 proc0_rescan = 0; 767 thread_unlock(&thread0); | |
768 goto loop; 769} 770 | 749 goto loop; 750} 751 |
771void kick_proc0(void) | 752void 753kick_proc0(void) |
772{ | 754{ |
773 struct thread *td = &thread0; | |
774 | 755 |
775 /* XXX This will probably cause a LOR in some cases */ 776 thread_lock(td); 777 if (TD_AWAITING_INTR(td)) { 778 CTR2(KTR_INTR, "%s: sched_add %d", __func__, 0); 779 TD_CLR_IWAIT(td); 780 sched_add(td, SRQ_INTR); 781 } else { 782 proc0_rescan = 1; 783 CTR2(KTR_INTR, "%s: state %d", 784 __func__, td->td_state); 785 } 786 thread_unlock(td); 787 | 756 wakeup(&proc0); |
788} 789 | 757} 758 |
790 | |
791#ifndef NO_SWAPPING 792 793/* 794 * Swap_idle_threshold1 is the guaranteed swapped in time for a process 795 */ 796static int swap_idle_threshold1 = 2; 797SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold1, CTLFLAG_RW, 798 &swap_idle_threshold1, 0, "Guaranteed swapped in time for a process"); --- 176 unchanged lines hidden (view full) --- 975 PROC_LOCK_ASSERT(p, MA_OWNED); 976 977 FOREACH_THREAD_IN_PROC(p, td) { 978 thread_lock(td); 979 td->td_flags |= TDF_INMEM; 980 td->td_flags &= ~TDF_SWAPINREQ; 981 TD_CLR_SWAPPED(td); 982 if (TD_CAN_RUN(td)) | 759#ifndef NO_SWAPPING 760 761/* 762 * Swap_idle_threshold1 is the guaranteed swapped in time for a process 763 */ 764static int swap_idle_threshold1 = 2; 765SYSCTL_INT(_vm, OID_AUTO, swap_idle_threshold1, CTLFLAG_RW, 766 &swap_idle_threshold1, 0, "Guaranteed swapped in time for a process"); --- 176 unchanged lines hidden (view full) --- 943 PROC_LOCK_ASSERT(p, MA_OWNED); 944 945 FOREACH_THREAD_IN_PROC(p, td) { 946 thread_lock(td); 947 td->td_flags |= TDF_INMEM; 948 td->td_flags &= ~TDF_SWAPINREQ; 949 TD_CLR_SWAPPED(td); 950 if (TD_CAN_RUN(td)) |
983 setrunnable(td); | 951 if (setrunnable(td)) { 952#ifdef INVARIANTS 953 /* 954 * XXX: We just cleared TDI_SWAPPED 955 * above and set TDF_INMEM, so this 956 * should never happen. 957 */ 958 panic("not waking up swapper"); 959#endif 960 } |
984 thread_unlock(td); 985 } 986 p->p_flag &= ~(P_SWAPPINGIN|P_SWAPPINGOUT); 987 p->p_flag |= P_INMEM; 988} 989 990static int 991swapout(p) --- 55 unchanged lines hidden --- | 961 thread_unlock(td); 962 } 963 p->p_flag &= ~(P_SWAPPINGIN|P_SWAPPINGOUT); 964 p->p_flag |= P_INMEM; 965} 966 967static int 968swapout(p) --- 55 unchanged lines hidden --- |