summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_fork.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2009-06-23 20:45:22 +0000
committerkib <kib@FreeBSD.org>2009-06-23 20:45:22 +0000
commitfa686c638eece83a18de058d1934f4722487818b (patch)
treeefadbd0bda4d9f0ec36869d4d465b2cabf2dcd1b /sys/kern/kern_fork.c
parent39fa9f1c9918ad9bb25af4f1bbce28c34cb2cd65 (diff)
downloadFreeBSD-src-fa686c638eece83a18de058d1934f4722487818b.zip
FreeBSD-src-fa686c638eece83a18de058d1934f4722487818b.tar.gz
Implement global and per-uid accounting of the anonymous memory. Add
rlimit RLIMIT_SWAP that limits the amount of swap that may be reserved for the uid. The accounting information (charge) is associated with either map entry, or vm object backing the entry, assuming the object is the first one in the shadow chain and entry does not require COW. Charge is moved from entry to object on allocation of the object, e.g. during the mmap, assuming the object is allocated, or on the first page fault on the entry. It moves back to the entry on forks due to COW setup. The per-entry granularity of accounting makes the charge process fair for processes that change uid during lifetime, and decrements charge for proper uid when region is unmapped. The interface of vm_pager_allocate(9) is extended by adding struct ucred *, that is used to charge appropriate uid when allocation if performed by kernel, e.g. md(4). Several syscalls, among them is fork(2), may now return ENOMEM when global or per-uid limits are enforced. In collaboration with: pho Reviewed by: alc Approved by: re (kensmith)
Diffstat (limited to 'sys/kern/kern_fork.c')
-rw-r--r--sys/kern/kern_fork.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 721d48d..bfa43a9 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -214,6 +214,7 @@ fork1(td, flags, pages, procp)
struct thread *td2;
struct sigacts *newsigacts;
struct vmspace *vm2;
+ vm_ooffset_t mem_charged;
int error;
/* Can't copy and clear. */
@@ -274,6 +275,7 @@ norfproc_fail:
* however it proved un-needed and caused problems
*/
+ mem_charged = 0;
vm2 = NULL;
/* Allocate new proc. */
newproc = uma_zalloc(proc_zone, M_WAITOK);
@@ -295,12 +297,24 @@ norfproc_fail:
}
}
if ((flags & RFMEM) == 0) {
- vm2 = vmspace_fork(p1->p_vmspace);
+ vm2 = vmspace_fork(p1->p_vmspace, &mem_charged);
if (vm2 == NULL) {
error = ENOMEM;
goto fail1;
}
- }
+ if (!swap_reserve(mem_charged)) {
+ /*
+ * The swap reservation failed. The accounting
+ * from the entries of the copied vm2 will be
+ * substracted in vmspace_free(), so force the
+ * reservation there.
+ */
+ swap_reserve_force(mem_charged);
+ error = ENOMEM;
+ goto fail1;
+ }
+ } else
+ vm2 = NULL;
#ifdef MAC
mac_proc_init(newproc);
#endif
OpenPOWER on IntegriCloud