From owner-p4-projects@FreeBSD.ORG Mon Aug 30 18:35:49 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 917C81065693; Mon, 30 Aug 2010 18:35:49 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 53D3D1065670 for ; Mon, 30 Aug 2010 18:35:49 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 40EBD8FC12 for ; Mon, 30 Aug 2010 18:35:49 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id o7UIZnwZ054164 for ; Mon, 30 Aug 2010 18:35:49 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id o7UIZnBr054161 for perforce@freebsd.org; Mon, 30 Aug 2010 18:35:49 GMT (envelope-from trasz@freebsd.org) Date: Mon, 30 Aug 2010 18:35:49 GMT Message-Id: <201008301835.o7UIZnBr054161@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 183084 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2010 18:35:49 -0000 http://p4web.freebsd.org/@@183084?ac=10 Change 183084 by trasz@trasz_victim on 2010/08/30 18:34:59 Clean up stuff and improve distinction between HRL and CONTAINERS - the latter is not related to lim_cur() removal. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/compat/linux/linux_misc.c#15 edit .. //depot/projects/soc2009/trasz_limits/sys/compat/svr4/imgact_svr4.c#9 edit .. //depot/projects/soc2009/trasz_limits/sys/conf/options#23 edit .. //depot/projects/soc2009/trasz_limits/sys/fs/fdescfs/fdesc_vfsops.c#4 edit .. //depot/projects/soc2009/trasz_limits/sys/i386/linux/imgact_linux.c#8 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/imgact_aout.c#9 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/imgact_elf.c#16 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/imgact_gzip.c#7 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/init_main.c#28 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#29 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#93 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#20 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_prot.c#29 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#47 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/vfs_vnops.c#19 edit .. //depot/projects/soc2009/trasz_limits/sys/vm/vm_glue.c#8 edit .. //depot/projects/soc2009/trasz_limits/sys/vm/vm_mmap.c#16 edit .. //depot/projects/soc2009/trasz_limits/sys/vm/vm_pageout.c#13 edit .. //depot/projects/soc2009/trasz_limits/sys/vm/vm_unix.c#9 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/compat/linux/linux_misc.c#15 (text+ko) ==== @@ -359,6 +359,16 @@ * XXX - this is not complete. it should check current usage PLUS * the resources needed by this library. */ +#ifndef HRL + PROC_LOCK(td->td_proc); + if (a_out->a_text > maxtsiz || + a_out->a_data + bss_size > lim_cur(td->td_proc, RLIMIT_DATA)) { + PROC_UNLOCK(td->td_proc); + error = ENOMEM; + goto cleanup; + } + PROC_UNLOCK(td->td_proc); +#endif #ifdef CONTAINERS if (a_out->a_text > maxtsiz) { error = ENOMEM; @@ -370,15 +380,6 @@ error = ENOMEM; goto cleanup; } -#else - PROC_LOCK(td->td_proc); - if (a_out->a_text > maxtsiz || - a_out->a_data + bss_size > lim_cur(td->td_proc, RLIMIT_DATA)) { - PROC_UNLOCK(td->td_proc); - error = ENOMEM; - goto cleanup; - } - PROC_UNLOCK(td->td_proc); #endif /* !CONTAINERS */ /* ==== //depot/projects/soc2009/trasz_limits/sys/compat/svr4/imgact_svr4.c#9 (text+ko) ==== @@ -107,6 +107,15 @@ /* * text/data/bss must not exceed limits */ +#ifndef HRL + PROC_LOCK(imgp->proc); + if (a_out->a_text > maxtsiz || + a_out->a_data + bss_size > lim_cur(imgp->proc, RLIMIT_DATA)) { + PROC_UNLOCK(imgp->proc); + return (ENOMEM); + } + PROC_UNLOCK(imgp->proc); +#endif /* !HRL */ #ifdef CONTAINERS if (a_out->a_text > maxtsiz) return (ENOMEM); @@ -114,15 +123,7 @@ a_out->a_data + bss_size); if (error) return (ENOMEM); -#else - PROC_LOCK(imgp->proc); - if (a_out->a_text > maxtsiz || - a_out->a_data + bss_size > lim_cur(imgp->proc, RLIMIT_DATA)) { - PROC_UNLOCK(imgp->proc); - return (ENOMEM); - } - PROC_UNLOCK(imgp->proc); -#endif /* !CONTAINERS */ +#endif VOP_UNLOCK(imgp->vp, 0); ==== //depot/projects/soc2009/trasz_limits/sys/conf/options#23 (text+ko) ==== @@ -859,4 +859,4 @@ CONTAINERS opt_global.h # Hierarchical Resource Limits -HRL opt_hrl.h +HRL opt_global.h ==== //depot/projects/soc2009/trasz_limits/sys/fs/fdescfs/fdesc_vfsops.c#4 (text+ko) ==== @@ -38,6 +38,7 @@ * /dev/fd Filesystem */ +#include #include #include #include @@ -186,6 +187,9 @@ int i; int last; int freefd; +#ifdef CONTAINERS + uint64_t limit; +#endif td = curthread; @@ -195,12 +199,22 @@ * limit is ever reduced below the current number * of open files... ] */ +#ifndef HRL PROC_LOCK(td->td_proc); lim = lim_cur(td->td_proc, RLIMIT_NOFILE); PROC_UNLOCK(td->td_proc); - /* XXX: Check HRL? */ +#endif fdp = td->td_proc->p_fd; FILEDESC_SLOCK(fdp); +#ifdef CONTAINERS + limit = rusage_get_limit(td->td_proc, RUSAGE_NOFILE); +#ifdef HRL + lim = limit; +#else + if (lim > limit) + lim = limit; +#endif +#endif last = min(fdp->fd_nfiles, lim); freefd = 0; for (i = fdp->fd_freefile; i < last; i++) ==== //depot/projects/soc2009/trasz_limits/sys/i386/linux/imgact_linux.c#8 (text+ko) ==== @@ -105,6 +105,15 @@ /* * text/data/bss must not exceed limits */ +#ifndef HRL + PROC_LOCK(imgp->proc); + if (a_out->a_text > maxtsiz || + a_out->a_data + bss_size > lim_cur(imgp->proc, RLIMIT_DATA)) { + PROC_UNLOCK(imgp->proc); + return (ENOMEM); + } + PROC_UNLOCK(imgp->proc); +#endif /* !HRL */ #ifdef CONTAINERS if (a_out->a_text > maxtsiz) return (ENOMEM); @@ -112,15 +121,7 @@ a_out->a_data + bss_size); if (error) return (ENOMEM); -#else - PROC_LOCK(imgp->proc); - if (a_out->a_text > maxtsiz || - a_out->a_data + bss_size > lim_cur(imgp->proc, RLIMIT_DATA)) { - PROC_UNLOCK(imgp->proc); - return (ENOMEM); - } - PROC_UNLOCK(imgp->proc); -#endif /* !CONTAINERS */ +#endif /* CONTAINERS */ VOP_UNLOCK(imgp->vp, 0); ==== //depot/projects/soc2009/trasz_limits/sys/kern/imgact_aout.c#9 (text+ko) ==== @@ -185,15 +185,7 @@ /* * text/data/bss must not exceed limits */ -#ifdef CONTAINERS - if (/* text can't exceed maximum text size */ - a_out->a_text > maxtsiz) - return (ENOMEM); - error = rusage_set(imgp->proc, RUSAGE_DATA, - a_out->a_data + bss_size); - if (error) - return (ENOMEM); -#else +#ifndef HRL PROC_LOCK(imgp->proc); if (/* text can't exceed maximum text size */ a_out->a_text > maxtsiz || @@ -204,7 +196,16 @@ return (ENOMEM); } PROC_UNLOCK(imgp->proc); -#endif +#endif /* !HRL */ +#ifdef CONTAINERS + if (/* text can't exceed maximum text size */ + a_out->a_text > maxtsiz) + return (ENOMEM); + error = rusage_set(imgp->proc, RUSAGE_DATA, + a_out->a_data + bss_size); + if (error) + return (ENOMEM); +#endif /* CONTAINERS */ /* * Avoid a possible deadlock if the current address space is destroyed ==== //depot/projects/soc2009/trasz_limits/sys/kern/imgact_elf.c#16 (text+ko) ==== @@ -874,6 +874,17 @@ * limits after loading the segments since we do * not actually fault in all the segments pages. */ +#ifndef HRL + PROC_LOCK(imgp->proc); + if (data_size > lim_cur(imgp->proc, RLIMIT_DATA) || + text_size > maxtsiz || + total_size > lim_cur(imgp->proc, RLIMIT_VMEM)) { + PROC_UNLOCK(imgp->proc); + return (ENOMEM); + } +#else + PROC_LOCK(imgp->proc); +#endif /* !HRL */ #ifdef CONTAINERS if (text_size > maxtsiz) return (ENOMEM); @@ -885,17 +896,8 @@ total_size); if (error) return (ENOMEM); +#endif /* CONTAINERS */ - PROC_LOCK(imgp->proc); -#else - PROC_LOCK(imgp->proc); - if (data_size > lim_cur(imgp->proc, RLIMIT_DATA) || - text_size > maxtsiz || - total_size > lim_cur(imgp->proc, RLIMIT_VMEM)) { - PROC_UNLOCK(imgp->proc); - return (ENOMEM); - } -#endif /* !CONTAINERS */ vmspace->vm_tsize = text_size >> PAGE_SHIFT; vmspace->vm_taddr = (caddr_t)(uintptr_t)text_addr; vmspace->vm_dsize = data_size >> PAGE_SHIFT; @@ -1120,7 +1122,7 @@ error = EFAULT; goto done; } -#endif +#endif /* CONTAINERS */ if (hdrsize + seginfo.size >= limit) { error = EFAULT; goto done; ==== //depot/projects/soc2009/trasz_limits/sys/kern/imgact_gzip.c#7 (text+ko) ==== @@ -210,17 +210,7 @@ /* * text/data/bss must not exceed limits */ -#ifdef CONTAINERS - if ( /* text can't exceed maximum text size */ - gz->a_out.a_text > maxtsiz) { - gz->where = __LINE__; - return (ENOMEM); - } - error = rusage_set(gz->ip->proc, RUSAGE_DATA, - gz->a_out.a_data + gz->bss_size); - if (error) - return (ENOMEM); -#else +#ifndef HRL PROC_LOCK(gz->ip->proc); if ( /* text can't exceed maximum text size */ gz->a_out.a_text > maxtsiz || @@ -233,7 +223,18 @@ return (ENOMEM); } PROC_UNLOCK(gz->ip->proc); -#endif /* !CONTAINERS */ +#endif /* !HRL */ +#ifdef CONTAINERS + if ( /* text can't exceed maximum text size */ + gz->a_out.a_text > maxtsiz) { + gz->where = __LINE__; + return (ENOMEM); + } + error = rusage_set(gz->ip->proc, RUSAGE_DATA, + gz->a_out.a_data + gz->bss_size); + if (error) + return (ENOMEM); +#endif /* CONTAINERS */ /* Find out how far we should go */ gz->file_end = gz->file_offset + gz->a_out.a_text + gz->a_out.a_data; ==== //depot/projects/soc2009/trasz_limits/sys/kern/init_main.c#28 (text+ko) ==== @@ -45,7 +45,6 @@ __FBSDID("$FreeBSD: src/sys/kern/init_main.c,v 1.314 2010/08/09 14:48:31 gavin Exp $"); #include "opt_ddb.h" -#include "opt_hrl.h" #include "opt_init_path.h" #include ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#29 (text+ko) ==== @@ -32,7 +32,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_hrl.h" #include "opt_kdtrace.h" #include ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#93 (text+ko) ==== @@ -27,8 +27,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_hrl.h" - #include #include #include ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#20 (text+ko) ==== @@ -40,8 +40,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_hrl.h" - #include #include #include ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_prot.c#29 (text+ko) ==== @@ -45,7 +45,6 @@ __FBSDID("$FreeBSD: src/sys/kern/kern_prot.c,v 1.230 2010/07/18 20:57:53 trasz Exp $"); #include "opt_compat.h" -#include "opt_hrl.h" #include "opt_inet.h" #include "opt_inet6.h" ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#47 (text+ko) ==== @@ -38,7 +38,6 @@ __FBSDID("$FreeBSD: src/sys/kern/kern_resource.c,v 1.202 2010/07/18 20:57:53 trasz Exp $"); #include "opt_compat.h" -#include "opt_hrl.h" #include #include @@ -655,7 +654,7 @@ } #endif -#ifndef CONTAINERS +#ifndef HRL static void lim_cb(void *arg) { @@ -689,7 +688,7 @@ if ((p->p_flag & P_WEXIT) == 0) callout_reset(&p->p_limco, hz, lim_cb, p); } -#endif /* !CONTAINERS */ +#endif /* !HRL */ #ifdef HRL static void @@ -846,7 +845,7 @@ switch (which) { -#ifndef CONTAINERS +#ifndef HRL case RLIMIT_CPU: if (limp->rlim_cur != RLIM_INFINITY && p->p_cpulimit == RLIM_INFINITY) @@ -1262,7 +1261,7 @@ { p2->p_limit = lim_hold(p1->p_limit); callout_init_mtx(&p2->p_limco, &p2->p_mtx, 0); -#ifndef CONTAINERS +#ifndef HRL if (p1->p_cpulimit != RLIM_INFINITY) callout_reset(&p2->p_limco, hz, lim_cb, p2); #endif ==== //depot/projects/soc2009/trasz_limits/sys/kern/vfs_vnops.c#19 (text+ko) ==== @@ -1347,11 +1347,7 @@ if (vp->v_type != VREG || td == NULL) return (0); -#ifdef CONTAINERS - if (rusage_set(td->td_proc, RUSAGE_FSIZE, - (uoff_t)uio->uio_offset + uio->uio_resid)) - return (EFBIG); -#else +#ifndef HRL PROC_LOCK(td->td_proc); if ((uoff_t)uio->uio_offset + uio->uio_resid > lim_cur(td->td_proc, RLIMIT_FSIZE)) { @@ -1361,5 +1357,11 @@ } PROC_UNLOCK(td->td_proc); #endif +#ifdef CONTAINERS + if (rusage_set(td->td_proc, RUSAGE_FSIZE, + (uoff_t)uio->uio_offset + uio->uio_resid)) + return (EFBIG); +#endif + return (0); } ==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_glue.c#8 (text+ko) ==== @@ -200,10 +200,12 @@ PROC_LOCK(curproc); nsize = ptoa(npages + pmap_wired_count(vm_map_pmap(&curproc->p_vmspace->vm_map))); +#ifndef HRL if (nsize > lim_cur(curproc, RLIMIT_MEMLOCK)) { PROC_UNLOCK(curproc); return (ENOMEM); } +#endif PROC_UNLOCK(curproc); #ifdef CONTAINERS if (rusage_set(curproc, RUSAGE_MEMLOCK, nsize)) ==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_mmap.c#16 (text+ko) ==== @@ -1043,10 +1043,12 @@ PROC_LOCK(proc); nsize = ptoa(npages + pmap_wired_count(vm_map_pmap(&proc->p_vmspace->vm_map))); +#ifndef HRL if (nsize > lim_cur(proc, RLIMIT_MEMLOCK)) { PROC_UNLOCK(proc); return (ENOMEM); } +#endif PROC_UNLOCK(proc); if (npages + cnt.v_wire_count > vm_page_max_wired) return (EAGAIN); @@ -1432,6 +1434,7 @@ size = round_page(size); +#ifndef HRL PROC_LOCK(td->td_proc); if (td->td_proc->p_vmspace->vm_map.size + size > lim_cur(td->td_proc, RLIMIT_VMEM)) { @@ -1439,6 +1442,12 @@ return(ENOMEM); } PROC_UNLOCK(td->td_proc); +#endif +#ifdef CONTAINERS + if (rusage_set(td->td_proc, RUSAGE_VMEM, + td->td_proc->p_vmspace->vm_map.size + size)) + return (ENOMEM); +#endif /* * We currently can only deal with page aligned file offsets. ==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_pageout.c#13 (text+ko) ==== @@ -1704,7 +1704,10 @@ maxsize = OFF_TO_IDX(rusage_get_limit(p, RUSAGE_RSS)); if (size > maxsize) { vm_pageout_map_deactivate_pages( - &vm->vm_map, limit); + &vm->vm_map, maxsize); + /* Update RSS usage after paging out. */ + size = vmspace_resident_count(vm); + rusage_set(p, RUSAGE_RSS, IDX_TO_OFF(size)); } #endif vmspace_free(vm); ==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_unix.c#9 (text+ko) ==== @@ -74,19 +74,20 @@ { struct vmspace *vm = td->td_proc->p_vmspace; vm_offset_t new, old, base; -#ifndef CONTAINERS +#ifndef HRL rlim_t datalim, vmemlim; #endif int rv; int error = 0; boolean_t do_map_wirefuture; -#ifndef CONTAINERS +#ifndef HRL PROC_LOCK(td->td_proc); datalim = lim_cur(td->td_proc, RLIMIT_DATA); vmemlim = lim_cur(td->td_proc, RLIMIT_VMEM); PROC_UNLOCK(td->td_proc); #endif + do_map_wirefuture = FALSE; new = round_page((vm_offset_t)uap->nsize); vm_map_lock(&vm->vm_map); @@ -94,14 +95,7 @@ base = round_page((vm_offset_t) vm->vm_daddr); old = base + ctob(vm->vm_dsize); if (new > base) { -#ifdef CONTAINERS - error = rusage_set(td->td_proc, RUSAGE_DATA, - new - base); - if (error) { - error = ENOMEM; - goto done; - } -#else +#ifndef HRL /* * Check the resource limit, but allow a process to reduce * its usage, even if it remains over the limit. @@ -110,7 +104,16 @@ error = ENOMEM; goto done; } -#endif /* !CONTAINERS */ +#endif /* !HRL */ +#ifdef CONTAINERS + error = rusage_set(td->td_proc, RUSAGE_DATA, + new - base); + if (error) { + error = ENOMEM; + goto done; + } +#endif + if (new > vm_map_max(&vm->vm_map)) { error = ENOMEM; goto done; @@ -125,6 +128,12 @@ goto done; } if (new > old) { +#ifndef HRL + if (vm->vm_map.size + (new - old) > vmemlim) { + error = ENOMEM; + goto done; + } +#endif /* !HRL */ #ifdef CONTAINERS error = rusage_set(td->td_proc, RUSAGE_VMEM, vm->vm_map.size + (new - old)); @@ -132,12 +141,7 @@ error = ENOMEM; goto done; } -#else - if (vm->vm_map.size + (new - old) > vmemlim) { - error = ENOMEM; - goto done; - } -#endif /* !CONTAINERS */ +#endif rv = vm_map_insert(&vm->vm_map, NULL, 0, old, new, VM_PROT_RW, VM_PROT_ALL, 0); if (rv != KERN_SUCCESS) {