From db0d5cd641f1c95ac8f8c41ae9c79b92756fb2e2 Mon Sep 17 00:00:00 2001 From: ps Date: Wed, 10 Oct 2001 23:06:54 +0000 Subject: Make MAXTSIZ, DFLDSIZ, MAXDSIZ, DFLSSIZ, MAXSSIZ, SGROWSIZ loader tunable. Reviewed by: peter MFC after: 2 weeks --- sys/alpha/include/elf.h | 2 +- sys/amd64/include/elf.h | 2 +- sys/arm/include/elf.h | 2 +- sys/compat/linux/linux_misc.c | 2 +- sys/compat/svr4/imgact_svr4.c | 2 +- sys/compat/svr4/svr4_misc.c | 2 +- sys/conf/options | 8 +++----- sys/i386/include/elf.h | 2 +- sys/i386/linux/imgact_linux.c | 2 +- sys/ia64/include/elf.h | 2 +- sys/kern/imgact_aout.c | 2 +- sys/kern/imgact_elf.c | 2 -- sys/kern/imgact_gzip.c | 2 +- sys/kern/kern_environment.c | 8 ++++++++ sys/kern/kern_exec.c | 10 +++++----- sys/kern/kern_resource.c | 17 ++++++++--------- sys/kern/subr_param.c | 21 +++++++++++++++++++++ sys/kern/sysv_shm.c | 3 +-- sys/modules/sysvipc/sysvshm/Makefile | 2 +- sys/powerpc/include/elf.h | 2 +- sys/sparc64/include/elf.h | 2 +- sys/sys/kernel.h | 23 +++++++++++++++++++++++ sys/vm/vm_glue.c | 9 ++++----- sys/vm/vm_map.c | 6 +++--- sys/vm/vm_mmap.c | 5 ++--- sys/vm/vm_param.h | 6 ++++++ 26 files changed, 98 insertions(+), 48 deletions(-) (limited to 'sys') diff --git a/sys/alpha/include/elf.h b/sys/alpha/include/elf.h index e57e3cb..d3a935a 100644 --- a/sys/alpha/include/elf.h +++ b/sys/alpha/include/elf.h @@ -155,7 +155,7 @@ __ElfType(Hashelt); * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/amd64/include/elf.h b/sys/amd64/include/elf.h index eb411d8..1b718d0 100644 --- a/sys/amd64/include/elf.h +++ b/sys/amd64/include/elf.h @@ -138,7 +138,7 @@ __ElfType(Hashelt); * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif /* _KERNEL */ #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/arm/include/elf.h b/sys/arm/include/elf.h index ebafde3..07cd0a6 100644 --- a/sys/arm/include/elf.h +++ b/sys/arm/include/elf.h @@ -100,7 +100,7 @@ * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif /* _KERNEL */ #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 0d21eca..64b9782 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -365,7 +365,7 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args) * XXX - this is not complete. it should check current usage PLUS * the resources needed by this library. */ - if (a_out->a_text > MAXTSIZ || + if (a_out->a_text > maxtsiz || a_out->a_data + bss_size > td->td_proc->p_rlimit[RLIMIT_DATA].rlim_cur) { error = ENOMEM; diff --git a/sys/compat/svr4/imgact_svr4.c b/sys/compat/svr4/imgact_svr4.c index 6692c98..02ce42f 100644 --- a/sys/compat/svr4/imgact_svr4.c +++ b/sys/compat/svr4/imgact_svr4.c @@ -107,7 +107,7 @@ exec_svr4_imgact(imgp) /* * text/data/bss must not exceed limits */ - if (a_out->a_text > MAXTSIZ || + if (a_out->a_text > maxtsiz || a_out->a_data + bss_size > imgp->proc->p_rlimit[RLIMIT_DATA].rlim_cur) return (ENOMEM); diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c index fd6c472..700be90 100644 --- a/sys/compat/svr4/svr4_misc.c +++ b/sys/compat/svr4/svr4_misc.c @@ -576,7 +576,7 @@ svr4_sys_mmap64(td, uap) SCARG(&mm, addr) = SCARG(uap, addr); SCARG(&mm, pos) = SCARG(uap, pos); - rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + MAXDSIZ)); + rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz)); if ((SCARG(&mm, flags) & MAP_FIXED) == 0 && SCARG(&mm, addr) != 0 && (void *)SCARG(&mm, addr) < rp) SCARG(&mm, addr) = rp; diff --git a/sys/conf/options b/sys/conf/options index 4a29129..7655b64 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -177,6 +177,9 @@ NSFBUFS opt_param.h VM_BCACHE_SIZE_MAX opt_param.h VM_SWZONE_SIZE_MAX opt_param.h MAXUSERS +DFLDSIZ opt_param.h +MAXDSIZ opt_param.h +MAXSSIZ opt_param.h # Generic SCSI options. CAM_MAX_HIGHPOWER opt_cam.h @@ -243,11 +246,6 @@ DEV_ATAPICD opt_ata.h DEV_ATAPIST opt_ata.h DEV_ATAPIFD opt_ata.h -# Resource limits. -DFLDSIZ opt_rlimit.h -MAXDSIZ opt_rlimit.h -MAXSSIZ opt_rlimit.h - # Net stuff. ACCEPT_FILTER_DATA ACCEPT_FILTER_HTTP diff --git a/sys/i386/include/elf.h b/sys/i386/include/elf.h index eb411d8..1b718d0 100644 --- a/sys/i386/include/elf.h +++ b/sys/i386/include/elf.h @@ -138,7 +138,7 @@ __ElfType(Hashelt); * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif /* _KERNEL */ #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/i386/linux/imgact_linux.c b/sys/i386/linux/imgact_linux.c index d86c62d..29741d93 100644 --- a/sys/i386/linux/imgact_linux.c +++ b/sys/i386/linux/imgact_linux.c @@ -106,7 +106,7 @@ exec_linux_imgact(imgp) * text/data/bss must not exceed limits */ mtx_assert(&Giant, MA_OWNED); - if (a_out->a_text > MAXTSIZ || + if (a_out->a_text > maxtsiz || a_out->a_data + bss_size > imgp->proc->p_rlimit[RLIMIT_DATA].rlim_cur) return (ENOMEM); diff --git a/sys/ia64/include/elf.h b/sys/ia64/include/elf.h index 31bd5b2..37f63c2 100644 --- a/sys/ia64/include/elf.h +++ b/sys/ia64/include/elf.h @@ -212,7 +212,7 @@ __ElfType(Hashelt); * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif /* _KERNEL */ #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c index 5a53581..bd6ff7b 100644 --- a/sys/kern/imgact_aout.c +++ b/sys/kern/imgact_aout.c @@ -163,7 +163,7 @@ exec_aout_imgact(imgp) */ mtx_assert(&Giant, MA_OWNED); if (/* text can't exceed maximum text size */ - a_out->a_text > MAXTSIZ || + a_out->a_text > maxtsiz || /* data + bss can't exceed rlimit */ a_out->a_data + bss_size > diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index d7a27ba..8d6a2bd 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -30,8 +30,6 @@ * $FreeBSD$ */ -#include "opt_rlimit.h" - #include #include #include diff --git a/sys/kern/imgact_gzip.c b/sys/kern/imgact_gzip.c index 00f9040..3516daa 100644 --- a/sys/kern/imgact_gzip.c +++ b/sys/kern/imgact_gzip.c @@ -209,7 +209,7 @@ do_aout_hdr(struct imgact_gzip * gz) */ mtx_assert(&Giant, MA_OWNED); if ( /* text can't exceed maximum text size */ - gz->a_out.a_text > MAXTSIZ || + gz->a_out.a_text > maxtsiz || /* data + bss can't exceed rlimit */ gz->a_out.a_data + gz->bss_size > diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c index a3342b4..9789706 100644 --- a/sys/kern/kern_environment.c +++ b/sys/kern/kern_environment.c @@ -163,6 +163,14 @@ tunable_int_init(void *data) } void +tunable_quad_init(void *data) +{ + struct tunable_quad *d = (struct tunable_quad *)data; + + TUNABLE_QUAD_FETCH(d->path, d->var); +} + +void tunable_str_init(void *data) { struct tunable_str *d = (struct tunable_str *)data; diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 8cfeb74..32df1c2 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -551,7 +551,7 @@ exec_new_vmspace(imgp) { int error; struct vmspace *vmspace = imgp->proc->p_vmspace; - caddr_t stack_addr = (caddr_t) (USRSTACK - MAXSSIZ); + caddr_t stack_addr = (caddr_t) (USRSTACK - maxssiz); vm_map_t map = &vmspace->vm_map; GIANT_REQUIRED; @@ -576,7 +576,7 @@ exec_new_vmspace(imgp) /* Allocate a new stack */ error = vm_map_stack (&vmspace->vm_map, (vm_offset_t)stack_addr, - (vm_size_t)MAXSSIZ, VM_PROT_ALL, VM_PROT_ALL, 0); + (vm_size_t)maxssiz, VM_PROT_ALL, VM_PROT_ALL, 0); if (error) return (error); @@ -588,7 +588,7 @@ exec_new_vmspace(imgp) * store to grow upwards. This will do for now. */ vm_offset_t bsaddr; - bsaddr = USRSTACK - 2*MAXSSIZ; + bsaddr = USRSTACK - 2*maxssiz; error = vm_map_find(&vmspace->vm_map, 0, 0, &bsaddr, 4*PAGE_SIZE, 0, VM_PROT_ALL, VM_PROT_ALL, 0); @@ -600,8 +600,8 @@ exec_new_vmspace(imgp) * VM_STACK case, but they are still used to monitor the size of the * process stack so we can check the stack rlimit. */ - vmspace->vm_ssize = SGROWSIZ >> PAGE_SHIFT; - vmspace->vm_maxsaddr = (char *)USRSTACK - MAXSSIZ; + vmspace->vm_ssize = sgrowsiz >> PAGE_SHIFT; + vmspace->vm_maxsaddr = (char *)USRSTACK - maxssiz; return(0); } diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 093e4c2..b5eeb5e 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -40,7 +40,6 @@ */ #include "opt_compat.h" -#include "opt_rlimit.h" #include #include @@ -518,17 +517,17 @@ dosetrlimit(td, which, limp) (rlim_t)1000000 * limp->rlim_cur; break; case RLIMIT_DATA: - if (limp->rlim_cur > MAXDSIZ) - limp->rlim_cur = MAXDSIZ; - if (limp->rlim_max > MAXDSIZ) - limp->rlim_max = MAXDSIZ; + if (limp->rlim_cur > maxdsiz) + limp->rlim_cur = maxdsiz; + if (limp->rlim_max > maxdsiz) + limp->rlim_max = maxdsiz; break; case RLIMIT_STACK: - if (limp->rlim_cur > MAXSSIZ) - limp->rlim_cur = MAXSSIZ; - if (limp->rlim_max > MAXSSIZ) - limp->rlim_max = MAXSSIZ; + if (limp->rlim_cur > maxssiz) + limp->rlim_cur = maxssiz; + if (limp->rlim_max > maxssiz) + limp->rlim_max = maxssiz; /* * Stack is allocated to the max at exec time with only * "rlim_cur" bytes accessible. If stack limit is going diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c index 96398dc..ced6d95 100644 --- a/sys/kern/subr_param.c +++ b/sys/kern/subr_param.c @@ -46,6 +46,8 @@ #include #include +#include + /* * System parameter formulae. */ @@ -74,6 +76,12 @@ int nbuf; int nswbuf; int maxswzone; /* max swmeta KVA storage */ int maxbcache; /* max buffer cache KVA storage */ +u_quad_t maxtsiz; /* max text size */ +u_quad_t dfldsiz; /* initial data size limit */ +u_quad_t maxdsiz; /* max data size */ +u_quad_t dflssiz; /* initial stack size limit */ +u_quad_t maxssiz; /* max stack size */ +u_quad_t sgrowsiz; /* amount to grow stack */ /* * These have to be allocated somewhere; allocating @@ -126,4 +134,17 @@ init_param(void) TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache); ncallout = 16 + maxproc + maxfiles; TUNABLE_INT_FETCH("kern.ncallout", &ncallout); + + maxtsiz = MAXTSIZ; + TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz); + dfldsiz = DFLDSIZ; + TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz); + maxdsiz = MAXDSIZ; + TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz); + dflssiz = DFLSSIZ; + TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz); + maxssiz = MAXSSIZ; + TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz); + sgrowsiz = SGROWSIZ; + TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz); } diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 650bee7..74743e5 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -32,7 +32,6 @@ */ #include "opt_compat.h" -#include "opt_rlimit.h" #include "opt_sysvipc.h" #include @@ -355,7 +354,7 @@ shmat(td, uap) * put it. */ attach_va = round_page((vm_offset_t)p->p_vmspace->vm_taddr - + MAXTSIZ + MAXDSIZ); + + maxtsiz + maxdsiz); } shm_handle = shmseg->shm_internal; diff --git a/sys/modules/sysvipc/sysvshm/Makefile b/sys/modules/sysvipc/sysvshm/Makefile index 9276537..0f06ec8 100644 --- a/sys/modules/sysvipc/sysvshm/Makefile +++ b/sys/modules/sysvipc/sysvshm/Makefile @@ -3,7 +3,7 @@ .PATH: ${.CURDIR}/../../../kern KMOD= sysvshm -OPTS= opt_sysvipc.h opt_compat.h opt_rlimit.h +OPTS= opt_sysvipc.h opt_compat.h SRCS= sysv_shm.c $(OPTS) .include diff --git a/sys/powerpc/include/elf.h b/sys/powerpc/include/elf.h index 81c748c..0ab7d5f 100644 --- a/sys/powerpc/include/elf.h +++ b/sys/powerpc/include/elf.h @@ -178,7 +178,7 @@ __ElfType(Hashelt); * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif /* _KERNEL */ #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/sparc64/include/elf.h b/sys/sparc64/include/elf.h index 7d76a4b..56b45ae 100644 --- a/sys/sparc64/include/elf.h +++ b/sys/sparc64/include/elf.h @@ -121,7 +121,7 @@ __ElfType(Hashelt); * its maximum allowed size. */ #define ELF_RTLD_ADDR(vmspace) \ - (round_page((vm_offset_t)(vmspace)->vm_daddr + MAXDSIZ)) + (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz)) #endif /* _KERNEL */ #endif /* !_MACHINE_ELF_H_ */ diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h index 821c325..5f9cf17 100644 --- a/sys/sys/kernel.h +++ b/sys/sys/kernel.h @@ -282,6 +282,29 @@ do { \ getenv_int((path), (var)); \ } while (0) +extern void tunable_quad_init(void *); +struct tunable_quad { + const char *path; + quad_t *var; +}; +#define TUNABLE_QUAD(path, var) \ + _TUNABLE_QUAD((path), (var), __LINE__) +#define _TUNABLE_QUAD(path, var, line) \ + __TUNABLE_QUAD((path), (var), line) + +#define __TUNABLE_QUAD(path, var, line) \ + static struct tunable_quad __tunable_quad_ ## line = { \ + path, \ + var, \ + }; \ + SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \ + tunable_quad_init, &__tunable_quad_ ## line) + +#define TUNABLE_QUAD_FETCH(path, var) \ +do { \ + getenv_quad((path), (var)); \ +} while (0) + extern void tunable_str_init(void *); struct tunable_str { const char *path; diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c index d239516..7a03cca 100644 --- a/sys/vm/vm_glue.c +++ b/sys/vm/vm_glue.c @@ -62,7 +62,6 @@ * $FreeBSD$ */ -#include "opt_rlimit.h" #include "opt_vm.h" #include @@ -328,10 +327,10 @@ vm_init_limits(udata) * of memory - half of main memory helps to favor smaller processes, * and reduces thrashing of the object cache. */ - p->p_rlimit[RLIMIT_STACK].rlim_cur = DFLSSIZ; - p->p_rlimit[RLIMIT_STACK].rlim_max = MAXSSIZ; - p->p_rlimit[RLIMIT_DATA].rlim_cur = DFLDSIZ; - p->p_rlimit[RLIMIT_DATA].rlim_max = MAXDSIZ; + p->p_rlimit[RLIMIT_STACK].rlim_cur = dflssiz; + p->p_rlimit[RLIMIT_STACK].rlim_max = maxssiz; + p->p_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz; + p->p_rlimit[RLIMIT_DATA].rlim_max = maxdsiz; /* limit the limit to no less than 2MB */ rss_limit = max(cnt.v_free_count, 512); p->p_rlimit[RLIMIT_RSS].rlim_cur = ptoa(rss_limit); diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index e7a4898..30ff0c7 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2396,10 +2396,10 @@ vm_map_stack (vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, if (VM_MIN_ADDRESS > 0 && addrbos < VM_MIN_ADDRESS) return (KERN_NO_SPACE); - if (max_ssize < SGROWSIZ) + if (max_ssize < sgrowsiz) init_ssize = max_ssize; else - init_ssize = SGROWSIZ; + init_ssize = sgrowsiz; vm_map_lock(map); @@ -2542,7 +2542,7 @@ Retry: } /* Round up the grow amount modulo SGROWSIZ */ - grow_amount = roundup (grow_amount, SGROWSIZ); + grow_amount = roundup (grow_amount, sgrowsiz); if (grow_amount > stack_entry->avail_ssize) { grow_amount = stack_entry->avail_ssize; } diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index c03c588..015ef9b 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -47,7 +47,6 @@ #include "opt_bleed.h" #include "opt_compat.h" -#include "opt_rlimit.h" #include #include @@ -276,8 +275,8 @@ mmap(td, uap) */ else if (addr == 0 || (addr >= round_page((vm_offset_t)vms->vm_taddr) && - addr < round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ))) - addr = round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ); + addr < round_page((vm_offset_t)vms->vm_daddr + maxdsiz))) + addr = round_page((vm_offset_t)vms->vm_daddr + maxdsiz); mtx_lock(&Giant); /* syscall marked mp-safe but isn't */ if (flags & MAP_ANON) { diff --git a/sys/vm/vm_param.h b/sys/vm/vm_param.h index 7237638..795157f 100644 --- a/sys/vm/vm_param.h +++ b/sys/vm/vm_param.h @@ -133,6 +133,12 @@ struct xswdev { #ifdef _KERNEL #define num_pages(x) \ ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT)) +extern u_quad_t maxtsiz; +extern u_quad_t dfldsiz; +extern u_quad_t maxdsiz; +extern u_quad_t dflssiz; +extern u_quad_t maxssiz; +extern u_quad_t sgrowsiz; #endif /* _KERNEL */ #endif /* ASSEMBLER */ #endif /* _VM_PARAM_ */ -- cgit v1.1