tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

RLIMIT_AS and fixed process size calculations patch




hi folks.

the patch below implements 3 things:

        1 - adds a new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits
        the total address space available to processes.  this limit
        exists in most other modern unix variants, and like most of
        them, our defaults are unlimited.

        2 - adds the VMCMD_STACK flag to all the stack-creation vmcmd
        callers.  it is currently unused, but was added a few years ago.

        3 - adds a pair of new process size values to kinfo_proc2{}. 
        one is the total size of the process memory map, and the other
        is the total size adjusted for unused stack space (since most
        processes have a lot of this...)


i plan to commit this in a couple of days.  please comment.


.mrg.


Index: bin/csh/csh.1
===================================================================
RCS file: /cvsroot/src/bin/csh/csh.1,v
retrieving revision 1.45
diff -p -r1.45 csh.1
*** bin/csh/csh.1       13 Mar 2009 14:07:54 -0000      1.45
--- bin/csh/csh.1       27 Mar 2009 22:48:57 -0000
*************** The maximum number of simultaneous proce
*** 1431,1436 ****
--- 1431,1438 ----
  The maximum number of simultaneous open files for this user id.
  .It Ar sbsize
  The maximum socket buffer size of a process (in bytes).
+ .It Ar vmemoryuse
+ The maximum size (in bytes) which a process can obtain.
  .El
  .Pp
  The
Index: bin/csh/func.c
===================================================================
RCS file: /cvsroot/src/bin/csh/func.c,v
retrieving revision 1.36
diff -p -r1.36 func.c
*** bin/csh/func.c      15 Sep 2007 14:33:05 -0000      1.36
--- bin/csh/func.c      27 Mar 2009 22:48:57 -0000
*************** static const struct limits {
*** 1106,1111 ****
--- 1106,1112 ----
      { RLIMIT_NPROC,   "maxproc",      1,      "" },
      { RLIMIT_NOFILE,  "openfiles",    1,      "" },
      { RLIMIT_SBSIZE,  "sbsize",       1,      "bytes" },
+     { RLIMIT_AS,      "vmemoryuse",   1024,   "kbytes" },
      { -1,             NULL,           0,      NULL }
  };
  
Index: bin/ps/print.c
===================================================================
RCS file: /cvsroot/src/bin/ps/print.c,v
retrieving revision 1.110
diff -p -r1.110 print.c
*** bin/ps/print.c      14 Feb 2009 08:04:09 -0000      1.110
--- bin/ps/print.c      27 Mar 2009 22:48:57 -0000
*************** vsize(void *arg, VARENT *ve, int mode)
*** 973,980 ****
  
        k = arg;
        v = ve->var;
!       intprintorsetwidth(v,
!           pgtok(k->p_vm_dsize + k->p_vm_ssize + k->p_vm_tsize), mode);
  }
  
  void
--- 973,979 ----
  
        k = arg;
        v = ve->var;
!       intprintorsetwidth(v, pgtok(k->p_vm_msize), mode);
  }
  
  void
Index: bin/ps/ps.c
===================================================================
RCS file: /cvsroot/src/bin/ps/ps.c,v
retrieving revision 1.73
diff -p -r1.73 ps.c
*** bin/ps/ps.c 14 Feb 2009 08:04:10 -0000      1.73
--- bin/ps/ps.c 27 Mar 2009 22:48:57 -0000
*************** pscomp(const void *a, const void *b)
*** 585,591 ****
        struct varent *ve;
        const sigset_t *sa, *sb;
  
! #define       V_SIZE(k) (k->p_vm_dsize + k->p_vm_ssize + k->p_vm_tsize)
  #define       RDIFF_N(t, n) \
        if (((const t *)((const char *)ka + v->off))[n] > ((const t *)((const 
char *)kb + v->off))[n]) \
                return 1; \
--- 585,591 ----
        struct varent *ve;
        const sigset_t *sa, *sb;
  
! #define       V_SIZE(k) ((k)->p_vm_msize)
  #define       RDIFF_N(t, n) \
        if (((const t *)((const char *)ka + v->off))[n] > ((const t *)((const 
char *)kb + v->off))[n]) \
                return 1; \
Index: bin/sh/miscbltin.c
===================================================================
RCS file: /cvsroot/src/bin/sh/miscbltin.c,v
retrieving revision 1.37
diff -p -r1.37 miscbltin.c
*** bin/sh/miscbltin.c  28 Dec 2008 19:53:37 -0000      1.37
--- bin/sh/miscbltin.c  27 Mar 2009 22:48:57 -0000
*************** ulimitcmd(int argc, char **argv)
*** 360,366 ****
        struct rlimit   limit;
  
        what = 'f';
!       while ((optc = nextopt("HSabtfdsmcnpl")) != '\0')
                switch (optc) {
                case 'H':
                        how = HARD;
--- 360,366 ----
        struct rlimit   limit;
  
        what = 'f';
!       while ((optc = nextopt("HSabtfdsmcnplv")) != '\0')
                switch (optc) {
                case 'H':
                        how = HARD;
Index: bin/sh/sh.1
===================================================================
RCS file: /cvsroot/src/bin/sh/sh.1,v
retrieving revision 1.91
diff -p -r1.91 sh.1
*** bin/sh/sh.1 10 Mar 2009 15:14:28 -0000      1.91
--- bin/sh/sh.1 27 Mar 2009 22:48:58 -0000
*************** command, tracked alias and not found.
*** 1699,1705 ****
  For aliases the alias expansion is
  printed; for commands and tracked aliases the complete pathname of the
  command is printed.
! .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl tfdscmlpn Oo Ar value Oc Oc
  Inquire about or set the hard or soft limits on processes or set new
  limits.
  The choice between hard limit (which no process is allowed to
--- 1699,1705 ----
  For aliases the alias expansion is
  printed; for commands and tracked aliases the complete pathname of the
  command is printed.
! .It ulimit Oo Fl H \*(Ba Fl S Oc Oo Fl a \*(Ba Fl tfdscmlpnv Oo Ar value Oc Oc
  Inquire about or set the hard or soft limits on processes or set new
  limits.
  The choice between hard limit (which no process is allowed to
*************** show or set the limit on the number of p
*** 1750,1755 ****
--- 1750,1757 ----
  have at one time
  .It Fl n
  show or set the limit on the number of files a process can have open at once
+ .It Fl v
+ show or set the limit on how large a process address space can be
  .El
  .Pp
  If none of these is specified, it is the limit on file size that is shown
Index: external/bsd/top/dist/machine/m_netbsd.c
===================================================================
RCS file: /cvsroot/src/external/bsd/top/dist/machine/m_netbsd.c,v
retrieving revision 1.6
diff -p -r1.6 m_netbsd.c
*** external/bsd/top/dist/machine/m_netbsd.c    8 Mar 2009 16:26:03 -0000       
1.6
--- external/bsd/top/dist/machine/m_netbsd.c    27 Mar 2009 22:49:01 -0000
*************** struct handle {
*** 87,94 ****
                         ((pct) / (1.0 - exp((pp)->pfx ## swtime * logcpu))))
  
  /* what we consider to be process size: */
  #define PROCSIZE(pp) \
!       ((pp)->p_vm_tsize + (pp)->p_vm_dsize + (pp)->p_vm_ssize)
  
  
  /*
--- 87,100 ----
                         ((pct) / (1.0 - exp((pp)->pfx ## swtime * logcpu))))
  
  /* what we consider to be process size: */
+ /* NetBSD introduced p_vm_msize with RLIMIT_AS */
+ #ifdef RLIMIT_AS
  #define PROCSIZE(pp) \
!     ((pp)->p_vm_msize)
! #else
! #define PROCSIZE(pp) \
!     ((pp)->p_vm_tsize + (pp)->p_vm_dsize + (pp)->p_vm_ssize)
! #endif
  
  
  /*
Index: lib/libkvm/kvm_proc.c
===================================================================
RCS file: /cvsroot/src/lib/libkvm/kvm_proc.c,v
retrieving revision 1.81
diff -p -r1.81 kvm_proc.c
*** lib/libkvm/kvm_proc.c       28 Dec 2008 19:49:26 -0000      1.81
--- lib/libkvm/kvm_proc.c       27 Mar 2009 22:49:03 -0000
*************** __RCSID("$NetBSD: kvm_proc.c,v 1.81 2008
*** 99,104 ****
--- 99,105 ----
  #include <kvm.h>
  
  #include <uvm/uvm_extern.h>
+ #include <uvm/uvm_param.h>
  #include <uvm/uvm_amap.h>
  
  #include <sys/sysctl.h>
*************** again:
*** 679,684 ****
--- 680,691 ----
                        kp2p->p_vm_tsize = kp->kp_eproc.e_vm.vm_tsize;
                        kp2p->p_vm_dsize = kp->kp_eproc.e_vm.vm_dsize;
                        kp2p->p_vm_ssize = kp->kp_eproc.e_vm.vm_ssize;
+                       kp2p->p_vm_vsize = kp->kp_eproc.e_vm.vm_map.size;
+                       /* Adjust mapped size */
+                       kp2p->p_vm_msize =
+                           (kp->kp_eproc.e_vm.vm_map.size / kd->nbpg) -
+                           kp->kp_eproc.e_vm.vm_issize +
+                           kp->kp_eproc.e_vm.vm_ssize;
  
                        kp2p->p_eflag = (int32_t)kp->kp_eproc.e_flag;
  
Index: sys/arch/mips/mips/cpu_exec.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/cpu_exec.c,v
retrieving revision 1.54
diff -p -r1.54 cpu_exec.c
*** sys/arch/mips/mips/cpu_exec.c       14 Mar 2009 21:04:12 -0000      1.54
--- sys/arch/mips/mips/cpu_exec.c       27 Mar 2009 22:49:04 -0000
*************** mips_elf_makecmds (struct lwp *l, struct
*** 284,295 ****
         * note that in memory, things assumed to be: 0 ....... ep_maxsaddr
         * <stack> ep_minsaddr
         */
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero,
            ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr),
!           epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE);
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize,
            (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0,
!           VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
  
        return 0;
  }
--- 284,295 ----
         * note that in memory, things assumed to be: 0 ....... ep_maxsaddr
         * <stack> ep_minsaddr
         */
!       NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero,
            ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr),
!           epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK);
!       NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize,
            (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0,
!           VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, VMCMD_STACK);
  
        return 0;
  }
Index: sys/compat/darwin/darwin_exec.c
===================================================================
RCS file: /cvsroot/src/sys/compat/darwin/darwin_exec.c,v
retrieving revision 1.56
diff -p -r1.56 darwin_exec.c
*** sys/compat/darwin/darwin_exec.c     19 Nov 2008 18:36:02 -0000      1.56
--- sys/compat/darwin/darwin_exec.c     27 Mar 2009 22:49:04 -0000
*************** darwin_exec_setup_stack(struct lwp *l, s
*** 426,437 ****
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULL, 0, VM_PROT_NONE);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE);
  
        return 0;
  }
--- 426,438 ----
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD(2&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE,
!           VMCMD_STACK);
  
        return 0;
  }
Index: sys/compat/ibcs2/ibcs2_exec.c
===================================================================
RCS file: /cvsroot/src/sys/compat/ibcs2/ibcs2_exec.c,v
retrieving revision 1.72
diff -p -r1.72 ibcs2_exec.c
*** sys/compat/ibcs2/ibcs2_exec.c       19 Nov 2008 18:36:03 -0000      1.72
--- sys/compat/ibcs2/ibcs2_exec.c       27 Mar 2009 22:49:04 -0000
*************** ibcs2_exec_setup_stack(struct lwp *l, st
*** 181,194 ****
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULL, 0, VM_PROT_NONE);
        }
        KASSERT(access_size > 0);
        /* XXX: some ibcs2 binaries need an executable stack. */
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
            access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE |
!           VM_PROT_EXECUTE);
  
        return 0;
  }
--- 181,194 ----
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK);
        }
        KASSERT(access_size > 0);
        /* XXX: some ibcs2 binaries need an executable stack. */
!       NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
            access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE |
!           VM_PROT_EXECUTE, VMCMD_STACK);
  
        return 0;
  }
Index: sys/compat/linux/arch/amd64/linux_exec_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/compat/linux/arch/amd64/linux_exec_machdep.c,v
retrieving revision 1.15
diff -p -r1.15 linux_exec_machdep.c
*** sys/compat/linux/arch/amd64/linux_exec_machdep.c    15 Mar 2009 15:55:51 
-0000      1.15
--- sys/compat/linux/arch/amd64/linux_exec_machdep.c    27 Mar 2009 22:49:04 
-0000
*************** linux_exec_setup_stack(struct lwp *l, st
*** 113,124 ****
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULLVP, 0, VM_PROT_NONE);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULLVP, 0, VM_PROT_READ | VM_PROT_WRITE);
  
        return 0;
  }
--- 113,125 ----
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULLVP, 0, VM_PROT_READ | VM_PROT_WRITE,
!           VMCMD_STACK);
  
        return 0;
  }
Index: sys/compat/linux/arch/i386/linux_exec_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/compat/linux/arch/i386/linux_exec_machdep.c,v
retrieving revision 1.11
diff -p -r1.11 linux_exec_machdep.c
*** sys/compat/linux/arch/i386/linux_exec_machdep.c     26 Oct 2008 20:46:05 
-0000      1.11
--- sys/compat/linux/arch/i386/linux_exec_machdep.c     27 Mar 2009 22:49:04 
-0000
*************** linux_exec_setup_stack(struct lwp *l, st
*** 121,132 ****
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULLVP, 0, VM_PROT_NONE);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULLVP, 0, VM_PROT_READ | VM_PROT_WRITE);
  
        return 0;
  }
--- 121,133 ----
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULLVP, 0, VM_PROT_NONE, VMCMD_STACK);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULLVP, 0, VM_PROT_READ | VM_PROT_WRITE,
!           VMCMD_STACK);
  
        return 0;
  }
Index: sys/kern/exec_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_subr.c,v
retrieving revision 1.61
diff -p -r1.61 exec_subr.c
*** sys/kern/exec_subr.c        2 Jun 2008 16:16:27 -0000       1.61
--- sys/kern/exec_subr.c        27 Mar 2009 22:49:04 -0000
*************** vmcmd_map_zero(struct lwp *l, struct exe
*** 327,332 ****
--- 327,334 ----
                        UVM_MAPFLAG(prot, maxprot, UVM_INH_COPY,
                        UVM_ADV_NORMAL,
                        UVM_FLAG_FIXED|UVM_FLAG_COPYONW));
+       if (cmd->ev_flags & VMCMD_STACK)
+               curproc->p_vmspace->vm_issize += atop(round_page(cmd->ev_len));
        return error;
  }
  
*************** exec_setup_stack(struct lwp *l, struct e
*** 409,420 ****
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULL, 0, VM_PROT_NONE);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE);
  
        return 0;
  }
--- 411,423 ----
        noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
            access_size), noaccess_size);
        if (noaccess_size > 0) {
!               NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
!                   noaccess_linear_min, NULL, 0, VM_PROT_NONE, VMCMD_STACK);
        }
        KASSERT(access_size > 0);
!       NEW_VMCMD2(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
!           access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE,
!           VMCMD_STACK);
  
        return 0;
  }
Index: sys/kern/init_sysctl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/init_sysctl.c,v
retrieving revision 1.159
diff -p -r1.159 init_sysctl.c
*** sys/kern/init_sysctl.c      11 Mar 2009 05:55:22 -0000      1.159
--- sys/kern/init_sysctl.c      27 Mar 2009 22:49:04 -0000
*************** fill_kproc2(struct proc *p, struct kinfo
*** 3031,3036 ****
--- 3031,3044 ----
                ki->p_vm_tsize = vm->vm_tsize;
                ki->p_vm_dsize = vm->vm_dsize;
                ki->p_vm_ssize = vm->vm_ssize;
+               ki->p_vm_vsize = vm->vm_map.size;
+               /*
+                * Since the stack is initially mapped mostly with PROT_NONE
+                * and grown as needed, adjust the "mapped size" to not
+                * skip the unused stack portion.
+                */
+               ki->p_vm_msize =
+                   atop(vm->vm_map.size) - vm->vm_issize + vm->vm_ssize;
  
                /* Pick the primary (first) LWP */
                l = proc_active_lwp(p);
*************** fill_eproc(struct proc *p, struct eproc 
*** 3201,3206 ****
--- 3209,3215 ----
                ep->e_vm.vm_tsize = vm->vm_tsize;
                ep->e_vm.vm_dsize = vm->vm_dsize;
                ep->e_vm.vm_ssize = vm->vm_ssize;
+               ep->e_vm.vm_map.size = vm->vm_map.size;
  
                /* Pick the primary (first) LWP */
                l = proc_active_lwp(p);
Index: sys/kern/kern_exec.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_exec.c,v
retrieving revision 1.287
diff -p -r1.287 kern_exec.c
*** sys/kern/kern_exec.c        24 Mar 2009 21:00:05 -0000      1.287
--- sys/kern/kern_exec.c        27 Mar 2009 22:49:04 -0000
*************** execve1(struct lwp *l, const char *path,
*** 776,781 ****
--- 776,782 ----
        vm->vm_daddr = (void*)pack.ep_daddr;
        vm->vm_dsize = btoc(pack.ep_dsize);
        vm->vm_ssize = btoc(pack.ep_ssize);
+       vm->vm_issize = 0;
        vm->vm_maxsaddr = (void *)pack.ep_maxsaddr;
        vm->vm_minsaddr = (void *)pack.ep_minsaddr;
  
Index: sys/sys/resource.h
===================================================================
RCS file: /cvsroot/src/sys/sys/resource.h,v
retrieving revision 1.30
diff -p -r1.30 resource.h
*** sys/sys/resource.h  11 Jan 2009 02:45:55 -0000      1.30
--- sys/sys/resource.h  27 Mar 2009 22:49:04 -0000
*************** struct  rusage {
*** 88,96 ****
  #define       RLIMIT_NPROC    7               /* number of processes */
  #define       RLIMIT_NOFILE   8               /* number of open files */
  #define       RLIMIT_SBSIZE   9               /* maximum size of all socket 
buffers */
  
  #if defined(_NETBSD_SOURCE)
! #define       RLIM_NLIMITS    10              /* number of resource limits */
  #endif
  
  #define       RLIM_INFINITY   (~((u_quad_t)1 << 63))  /* no limit */
--- 88,98 ----
  #define       RLIMIT_NPROC    7               /* number of processes */
  #define       RLIMIT_NOFILE   8               /* number of open files */
  #define       RLIMIT_SBSIZE   9               /* maximum size of all socket 
buffers */
+ #define       RLIMIT_AS       10              /* virtual process size 
(inclusive of mmap) */
+ #define       RLIMIT_VMEM     RLIMIT_AS       /* common alias */
  
  #if defined(_NETBSD_SOURCE)
! #define       RLIM_NLIMITS    11              /* number of resource limits */
  #endif
  
  #define       RLIM_INFINITY   (~((u_quad_t)1 << 63))  /* no limit */
Index: sys/sys/sysctl.h
===================================================================
RCS file: /cvsroot/src/sys/sys/sysctl.h,v
retrieving revision 1.183
diff -p -r1.183 sysctl.h
*** sys/sys/sysctl.h    20 Jan 2009 18:20:48 -0000      1.183
--- sys/sys/sysctl.h    27 Mar 2009 22:49:04 -0000
*************** struct kinfo_proc2 {
*** 587,592 ****
--- 587,594 ----
        uint32_t p_svuid;               /* UID_T: saved user id */
        uint32_t p_svgid;               /* GID_T: saved group id */
        char p_ename[KI_MAXEMULLEN];    /* emulation name */
+       int64_t p_vm_vsize;             /* SEGSZ_T: total map size (pages) */
+       int64_t p_vm_msize;             /* SEGSZ_T: stack-adjusted map size 
(pages) */
  };
  
  /*
Index: sys/uvm/uvm_extern.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.152
diff -p -r1.152 uvm_extern.h
*** sys/uvm/uvm_extern.h        12 Mar 2009 12:55:16 -0000      1.152
--- sys/uvm/uvm_extern.h        27 Mar 2009 22:49:04 -0000
*************** struct vmspace {
*** 502,507 ****
--- 502,508 ----
        segsz_t vm_tsize;       /* text size (pages) XXX */
        segsz_t vm_dsize;       /* data size (pages) XXX */
        segsz_t vm_ssize;       /* stack size (pages) */
+       segsz_t vm_issize;      /* initial unmapped stack size (pages) */
        void *  vm_taddr;       /* user virtual address of text XXX */
        void *  vm_daddr;       /* user virtual address of data XXX */
        void *vm_maxsaddr;      /* user VA at max stack growth */
Index: sys/uvm/uvm_glue.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_glue.c,v
retrieving revision 1.135
diff -p -r1.135 uvm_glue.c
*** sys/uvm/uvm_glue.c  31 Jan 2009 09:13:09 -0000      1.135
--- sys/uvm/uvm_glue.c  27 Mar 2009 22:49:04 -0000
*************** uvm_init_limits(struct proc *p)
*** 425,430 ****
--- 425,432 ----
        p->p_rlimit[RLIMIT_STACK].rlim_max = maxsmap;
        p->p_rlimit[RLIMIT_DATA].rlim_cur = DFLDSIZ;
        p->p_rlimit[RLIMIT_DATA].rlim_max = maxdmap;
+       p->p_rlimit[RLIMIT_AS].rlim_cur = RLIM_INFINITY;
+       p->p_rlimit[RLIMIT_AS].rlim_max = RLIM_INFINITY;
        p->p_rlimit[RLIMIT_RSS].rlim_cur = ptoa(uvmexp.free);
  }
  
Index: sys/uvm/uvm_mmap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_mmap.c,v
retrieving revision 1.127
diff -p -r1.127 uvm_mmap.c
*** sys/uvm/uvm_mmap.c  14 Mar 2009 21:04:26 -0000      1.127
--- sys/uvm/uvm_mmap.c  27 Mar 2009 22:49:04 -0000
*************** sys_mmap(struct lwp *l, const struct sys
*** 502,525 ****
                pos = 0;
        }
  
-       /*
-        * XXX (in)sanity check.  We don't do proper datasize checking
-        * XXX for anonymous (or private writable) mmap().  However,
-        * XXX know that if we're trying to allocate more than the amount
-        * XXX remaining under our current data size limit, _that_ should
-        * XXX be disallowed.
-        */
-       if ((flags & MAP_ANON) != 0 ||
-           ((flags & MAP_PRIVATE) != 0 && (prot & PROT_WRITE) != 0)) {
-               if (size >
-                   (p->p_rlimit[RLIMIT_DATA].rlim_cur -
-                    ctob(p->p_vmspace->vm_dsize))) {
-                       if (fp != NULL)
-                               fd_putfile(fd);
-                       return (ENOMEM);
-               }
-       }
- 
  #if NVERIEXEC > 0
        if (handle != NULL) {
                /*
--- 502,507 ----
*************** uvm_mmap(struct vm_map *map, vaddr_t *ad
*** 1115,1120 ****
--- 1097,1111 ----
        }
  
        /*
+        * check resource limits
+        */
+ 
+       if (!VM_MAP_IS_KERNEL(map) &&
+           (((rlim_t)curproc->p_vmspace->vm_map.size + (rlim_t)size) >
+           curproc->p_rlimit[RLIMIT_AS].rlim_cur))
+               return ENOMEM;
+ 
+       /*
         * handle anon vs. non-anon mappings.   for non-anon mappings attach
         * to underlying vm object.
         */
Index: usr.bin/systat/ps.c
===================================================================
RCS file: /cvsroot/src/usr.bin/systat/ps.c,v
retrieving revision 1.31
diff -p -r1.31 ps.c
*** usr.bin/systat/ps.c 29 Dec 2008 01:48:19 -0000      1.31
--- usr.bin/systat/ps.c 27 Mar 2009 22:49:05 -0000
*************** vsz2int(struct kinfo_proc2 *kp)
*** 247,253 ****
  {
        int     i;
  
!       i = pgtok(kp->p_vm_dsize + kp->p_vm_ssize + kp->p_vm_tsize);
  
        return ((i < 0) ? 0 : i);
  }
--- 247,253 ----
  {
        int     i;
  
!       i = pgtok(kp->p_vm_msize);
  
        return ((i < 0) ? 0 : i);
  }


Home | Main Index | Thread Index | Old Index