Initialize the virtual memory-related resource limits in a single place.
Previously, one of these limits was initialized in two places to a different value in each place. Moreover, because an unsigned int was used to represent the amount of pageable physical memory, some of these limits were incorrectly initialized on 64-bit architectures. (Currently, this error is masked by login.conf's default settings.) Make vm_thread_swapin() and vm_thread_swapout() static. Submitted by: bde (an earlier version) Reviewed by: kib
This commit is contained in:
parent
36e51f655d
commit
ac45ee97c9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=206483
@ -382,8 +382,9 @@ static void
|
||||
proc0_init(void *dummy __unused)
|
||||
{
|
||||
struct proc *p;
|
||||
unsigned i;
|
||||
struct thread *td;
|
||||
vm_paddr_t pageablemem;
|
||||
int i;
|
||||
|
||||
GIANT_REQUIRED;
|
||||
p = &proc0;
|
||||
@ -493,10 +494,16 @@ proc0_init(void *dummy __unused)
|
||||
p->p_limit->pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
|
||||
p->p_limit->pl_rlimit[RLIMIT_NPROC].rlim_cur =
|
||||
p->p_limit->pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
|
||||
i = ptoa(cnt.v_free_count);
|
||||
p->p_limit->pl_rlimit[RLIMIT_RSS].rlim_max = i;
|
||||
p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_max = i;
|
||||
p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3;
|
||||
p->p_limit->pl_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz;
|
||||
p->p_limit->pl_rlimit[RLIMIT_DATA].rlim_max = maxdsiz;
|
||||
p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur = dflssiz;
|
||||
p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_max = maxssiz;
|
||||
/* Cast to avoid overflow on i386/PAE. */
|
||||
pageablemem = ptoa((vm_paddr_t)cnt.v_free_count);
|
||||
p->p_limit->pl_rlimit[RLIMIT_RSS].rlim_cur =
|
||||
p->p_limit->pl_rlimit[RLIMIT_RSS].rlim_max = pageablemem;
|
||||
p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = pageablemem / 3;
|
||||
p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_max = pageablemem;
|
||||
p->p_cpulimit = RLIM_INFINITY;
|
||||
|
||||
p->p_stats = pstats_alloc();
|
||||
|
@ -84,7 +84,5 @@ struct sf_buf *vm_imgact_map_page(vm_object_t object, vm_ooffset_t offset);
|
||||
void vm_imgact_unmap_page(struct sf_buf *sf);
|
||||
void vm_thread_dispose(struct thread *td);
|
||||
int vm_thread_new(struct thread *td, int pages);
|
||||
void vm_thread_swapin(struct thread *td);
|
||||
void vm_thread_swapout(struct thread *td);
|
||||
#endif /* _KERNEL */
|
||||
#endif /* !_VM_EXTERN_H_ */
|
||||
|
@ -99,12 +99,6 @@ extern int maxslp;
|
||||
/*
|
||||
* System initialization
|
||||
*
|
||||
* Note: proc0 from proc.h
|
||||
*/
|
||||
static void vm_init_limits(void *);
|
||||
SYSINIT(vm_limits, SI_SUB_VM_CONF, SI_ORDER_FIRST, vm_init_limits, &proc0);
|
||||
|
||||
/*
|
||||
* THIS MUST BE THE LAST INITIALIZATION ITEM!!!
|
||||
*
|
||||
* Note: run scheduling should be divorced from the vm system.
|
||||
@ -115,6 +109,8 @@ SYSINIT(scheduler, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, scheduler, NULL);
|
||||
#ifndef NO_SWAPPING
|
||||
static int swapout(struct proc *);
|
||||
static void swapclear(struct proc *);
|
||||
static void vm_thread_swapin(struct thread *td);
|
||||
static void vm_thread_swapout(struct thread *td);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -498,10 +494,11 @@ kstack_cache_init(void *nulll)
|
||||
MTX_SYSINIT(kstack_cache, &kstack_cache_mtx, "kstkch", MTX_DEF);
|
||||
SYSINIT(vm_kstacks, SI_SUB_KTHREAD_INIT, SI_ORDER_ANY, kstack_cache_init, NULL);
|
||||
|
||||
#ifndef NO_SWAPPING
|
||||
/*
|
||||
* Allow a thread's kernel stack to be paged out.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
vm_thread_swapout(struct thread *td)
|
||||
{
|
||||
vm_object_t ksobj;
|
||||
@ -528,7 +525,7 @@ vm_thread_swapout(struct thread *td)
|
||||
/*
|
||||
* Bring the kernel stack for a specified thread back in.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
vm_thread_swapin(struct thread *td)
|
||||
{
|
||||
vm_object_t ksobj;
|
||||
@ -556,6 +553,7 @@ vm_thread_swapin(struct thread *td)
|
||||
pmap_qenter(td->td_kstack, ma, pages);
|
||||
cpu_thread_swapin(td);
|
||||
}
|
||||
#endif /* !NO_SWAPPING */
|
||||
|
||||
/*
|
||||
* Implement fork's actions on an address space.
|
||||
@ -629,38 +627,6 @@ vm_waitproc(p)
|
||||
vmspace_exitfree(p); /* and clean-out the vmspace */
|
||||
}
|
||||
|
||||
/*
|
||||
* Set default limits for VM system.
|
||||
* Called for proc 0, and then inherited by all others.
|
||||
*
|
||||
* XXX should probably act directly on proc0.
|
||||
*/
|
||||
static void
|
||||
vm_init_limits(udata)
|
||||
void *udata;
|
||||
{
|
||||
struct proc *p = udata;
|
||||
struct plimit *limp;
|
||||
int rss_limit;
|
||||
|
||||
/*
|
||||
* Set up the initial limits on process VM. Set the maximum resident
|
||||
* set size to be half of (reasonably) available memory. Since this
|
||||
* is a soft limit, it comes into effect only when the system is out
|
||||
* of memory - half of main memory helps to favor smaller processes,
|
||||
* and reduces thrashing of the object cache.
|
||||
*/
|
||||
limp = p->p_limit;
|
||||
limp->pl_rlimit[RLIMIT_STACK].rlim_cur = dflssiz;
|
||||
limp->pl_rlimit[RLIMIT_STACK].rlim_max = maxssiz;
|
||||
limp->pl_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz;
|
||||
limp->pl_rlimit[RLIMIT_DATA].rlim_max = maxdsiz;
|
||||
/* limit the limit to no less than 2MB */
|
||||
rss_limit = max(cnt.v_free_count, 512);
|
||||
limp->pl_rlimit[RLIMIT_RSS].rlim_cur = ptoa(rss_limit);
|
||||
limp->pl_rlimit[RLIMIT_RSS].rlim_max = RLIM_INFINITY;
|
||||
}
|
||||
|
||||
void
|
||||
faultin(p)
|
||||
struct proc *p;
|
||||
|
Loading…
Reference in New Issue
Block a user