Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jun 2009 20:57:27 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r194767 - in head: bin/sh contrib/tcsh etc lib/libc/sys lib/libutil share/man/man7 share/man/man9 usr.bin/limits
Message-ID:  <200906232057.n5NKvRDE089939@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Tue Jun 23 20:57:27 2009
New Revision: 194767
URL: http://svn.freebsd.org/changeset/base/194767

Log:
  Usermode portion of the support for swap allocation accounting:
  - update for getrlimit(2) manpage;
  - support for setting RLIMIT_SWAP in login class;
  - addition to the limits(1) and sh and csh limit-setting builtins;
  - tuning(7) documentation on the sysctls controlling overcommit.
  
  In collaboration with:	pho
  Reviewed by:	alc
  Approved by:	re (kensmith)

Modified:
  head/bin/sh/miscbltin.c
  head/contrib/tcsh/sh.func.c
  head/contrib/tcsh/tcsh.man
  head/etc/login.conf
  head/lib/libc/sys/getrlimit.2
  head/lib/libutil/login_class.c
  head/share/man/man7/tuning.7
  head/share/man/man9/vm_map.9
  head/usr.bin/limits/limits.c

Modified: head/bin/sh/miscbltin.c
==============================================================================
--- head/bin/sh/miscbltin.c	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/bin/sh/miscbltin.c	Tue Jun 23 20:57:27 2009	(r194767)
@@ -403,7 +403,7 @@ ulimitcmd(int argc __unused, char **argv
 	struct rlimit	limit;
 
 	what = 'f';
-	while ((optc = nextopt("HSatfdsmcnuvlbp")) != '\0')
+	while ((optc = nextopt("HSatfdsmcnuvlbpw")) != '\0')
 		switch (optc) {
 		case 'H':
 			how = HARD;

Modified: head/contrib/tcsh/sh.func.c
==============================================================================
--- head/contrib/tcsh/sh.func.c	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/contrib/tcsh/sh.func.c	Tue Jun 23 20:57:27 2009	(r194767)
@@ -1796,6 +1796,10 @@ struct limits limits[] = 
     { RLIMIT_SBSIZE,	"sbsize",	1,	""		},
 # endif /* RLIMIT_SBSIZE */
 
+# ifdef RLIMIT_SWAP
+    { RLIMIT_SWAP,	"swaplimit",	1024,	"kbytes"	},
+# endif /* RLIMIT_SWAP */
+
     { -1, 		NULL, 		0, 	NULL		}
 };
 

Modified: head/contrib/tcsh/tcsh.man
==============================================================================
--- head/contrib/tcsh/tcsh.man	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/contrib/tcsh/tcsh.man	Tue Jun 23 20:57:27 2009	(r194767)
@@ -2921,6 +2921,9 @@ the maximum number of simultaneous proce
 .TP
 \fIsbsize\fR
 the maximum size of socket buffer usage for this user
+.TP
+\fIswaplimit\fR
+the maximum amount of swap space reserved or used for this user
 .PP
 \fImaximum-use\fR may be given as a (floating point or
 integer) number followed by a scale factor.  For all limits

Modified: head/etc/login.conf
==============================================================================
--- head/etc/login.conf	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/etc/login.conf	Tue Jun 23 20:57:27 2009	(r194767)
@@ -40,6 +40,7 @@ default:\
 	:maxproc=unlimited:\
 	:sbsize=unlimited:\
 	:vmemoryuse=unlimited:\
+	:swapuse=unlimited:\
 	:pseudoterminals=unlimited:\
 	:priority=0:\
 	:ignoretime@:\

Modified: head/lib/libc/sys/getrlimit.2
==============================================================================
--- head/lib/libc/sys/getrlimit.2	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/lib/libc/sys/getrlimit.2	Tue Jun 23 20:57:27 2009	(r194767)
@@ -97,6 +97,15 @@ mbufs, that this user may hold at any ti
 The maximum size (in bytes) of the stack segment for a process;
 this defines how far a program's stack segment may be extended.
 Stack extension is performed automatically by the system.
+.It Dv RLIMIT_SWAP
+The maximum size (in bytes) of the swap space that may be reserved or
+used by all of this user id's processes.
+This limit is enforced only if bit 1 of the
+.Va vm.overcommit
+sysctl is set.
+Please see
+.Xr tuning 7
+for a complete description of this sysctl.
 .It Dv RLIMIT_NPTS
 The maximum number of pseudo-terminals created by this user id.
 .El

Modified: head/lib/libutil/login_class.c
==============================================================================
--- head/lib/libutil/login_class.c	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/lib/libutil/login_class.c	Tue Jun 23 20:57:27 2009	(r194767)
@@ -64,6 +64,7 @@ static struct login_res {
     { "sbsize",          login_getcapsize, RLIMIT_SBSIZE  },
     { "vmemoryuse",      login_getcapsize, RLIMIT_VMEM    },
     { "pseudoterminals", login_getcapnum,  RLIMIT_NPTS    },
+    { "swapuse",         login_getcapsize, RLIMIT_SWAP    },
     { NULL,              0,                0              }
 };
 

Modified: head/share/man/man7/tuning.7
==============================================================================
--- head/share/man/man7/tuning.7	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/share/man/man7/tuning.7	Tue Jun 23 20:57:27 2009	(r194767)
@@ -404,6 +404,35 @@ In this document we will only cover the 
 on the system.
 .Pp
 The
+.Va vm.overcommit
+sysctl defines the overcommit behaviour of the vm subsystem.
+The virtual memory system always does accounting of the swap space
+reservation, both total for system and per-user. Corresponding values
+are available through sysctl
+.Va vm.swap_total,
+that gives the total bytes available for swapping, and
+.Va vm.swap_reserved,
+that gives number of bytes that may be needed to back all currently
+allocated anonymous memory.
+.Pp
+Setting bit 0 of the
+.Va vm.overcommit
+sysctl causes the virtual memory system to return failure
+to the process when allocation of memory causes vm.swap_reserved
+to exceed vm.swap_total.
+Bit 1 of the sysctl enforces RLIMIT_SWAP limit
+(see
+.Xr getrlimit 2 ).
+Root is exempt from this limit.
+Bit 2 allows to count most of the physical
+memory as allocatable, except wired and free reserved pages
+(accounted by
+.Va vm.stats.vm.v_free_target
+and
+.Va vm.stats.vm.v_wire_count
+sysctls, respectively).
+.Pp
+The
 .Va kern.ipc.maxpipekva
 loader tunable is used to set a hard limit on the
 amount of kernel address space allocated to mapping of pipe buffers.

Modified: head/share/man/man9/vm_map.9
==============================================================================
--- head/share/man/man9/vm_map.9	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/share/man/man9/vm_map.9	Tue Jun 23 20:57:27 2009	(r194767)
@@ -146,6 +146,10 @@ Do not include the mapping in a core dum
 .It Dv MAP_PREFAULT_MADVISE
 Specify that the request is from a user process calling
 .Xr madvise 2 .
+.It Dv MAP_ACC_CHARGED
+Region is already charged to the requestor by some means.
+.It Dv MAP_ACC_NO_CHARGE
+Do not charge for allocated region.
 .El
 .Pp
 The

Modified: head/usr.bin/limits/limits.c
==============================================================================
--- head/usr.bin/limits/limits.c	Tue Jun 23 20:45:22 2009	(r194766)
+++ head/usr.bin/limits/limits.c	Tue Jun 23 20:57:27 2009	(r194767)
@@ -87,7 +87,8 @@ static struct {
 	  { "  openfiles%-4s        %8s", "\n",       1    },
 	  { "  sbsize%-4s           %8s", " bytes\n", 1    },
 	  { "  vmemoryuse%-4s       %8s", " kB\n",    1024 },
-	  { "  pseudo-terminals%-4s %8s", "\n",       1    }
+	  { "  pseudo-terminals%-4s %8s", "\n",       1    },
+	  { "  swapuse%-4s          %8s", " kB\n",    1024 }
       }
     },
     { "sh", "unlimited", "", " -H", " -S", "",
@@ -103,7 +104,8 @@ static struct {
 	  { "ulimit%s -n %s", ";\n",  1    },
 	  { "ulimit%s -b %s", ";\n",  1    },
 	  { "ulimit%s -v %s", ";\n",  1024 },
-	  { "ulimit%s -p %s", ";\n",  1    }
+	  { "ulimit%s -p %s", ";\n",  1    },
+	  { "ulimit%s -w %s", ";\n",  1024 }
       }
     },
     { "csh", "unlimited", "", " -h", "", NULL,
@@ -119,7 +121,8 @@ static struct {
 	  { "limit%s openfiles %s",       ";\n",  1    },
 	  { "limit%s sbsize %s",          ";\n",  1    },
 	  { "limit%s vmemoryuse %s",      ";\n",  1024 },
-	  { "limit%s pseudoterminals %s", ";\n",  1    }
+	  { "limit%s pseudoterminals %s", ";\n",  1    },
+	  { "limit%s swapuse %s",         ";\n",  1024 }
       }
     },
     { "bash|bash2", "unlimited", "", " -H", " -S", "",
@@ -135,7 +138,8 @@ static struct {
 	  { "ulimit%s -n %s", ";\n",  1    },
 	  { "ulimit%s -b %s", ";\n",  1    },
 	  { "ulimit%s -v %s", ";\n",  1024 },
-	  { "ulimit%s -p %s", ";\n",  1    }
+	  { "ulimit%s -p %s", ";\n",  1    },
+	  { "ulimit%s -w %s", ";\n",  1024 }
       }
     },
     { "tcsh", "unlimited", "", " -h", "", NULL,
@@ -151,7 +155,8 @@ static struct {
 	  { "limit%s descriptors %s",     ";\n",  1    },
 	  { "limit%s sbsize %s",          ";\n",  1    },
 	  { "limit%s vmemoryuse %s",      ";\n",  1024 },
-	  { "limit%s pseudoterminals %s", ";\n",  1    }
+	  { "limit%s pseudoterminals %s", ";\n",  1    },
+	  { "limit%s swapuse %s",         ";\n",  1024 }
       }
     },
     { "ksh|pdksh", "unlimited", "", " -H", " -S", "",
@@ -167,7 +172,8 @@ static struct {
 	  { "ulimit%s -n %s", ";\n",  1    },
 	  { "ulimit%s -b %s", ";\n",  1    },
 	  { "ulimit%s -v %s", ";\n",  1024 },
-	  { "ulimit%s -p %s", ";\n",  1    }
+	  { "ulimit%s -p %s", ";\n",  1    },
+	  { "ulimit%s -w %s", ";\n",  1024 }
       }
     },
     { "zsh", "unlimited", "", " -H", " -S", "",
@@ -183,7 +189,8 @@ static struct {
 	  { "ulimit%s -n %s", ";\n",  1    },
 	  { "ulimit%s -b %s", ";\n",  1    },
 	  { "ulimit%s -v %s", ";\n",  1024 },
-	  { "ulimit%s -p %s", ";\n",  1    }
+	  { "ulimit%s -p %s", ";\n",  1    },
+	  { "ulimit%s -w %s", ";\n",  1024 }
       }
     },
     { "rc|es", "unlimited", "", " -h", "", NULL,
@@ -199,7 +206,8 @@ static struct {
 	  { "limit%s descriptors %s",     ";\n",  1    },
 	  { "limit%s sbsize %s",          ";\n",  1    },
 	  { "limit%s vmemoryuse %s",      ";\n",  1024 },
-	  { "limit%s pseudoterminals %s", ";\n",  1    }
+	  { "limit%s pseudoterminals %s", ";\n",  1    },
+	  { "limit%s swapuse %s",         ";\n",  1024 }
       }
     },
     { NULL, NULL, NULL, NULL, NULL, NULL,
@@ -220,9 +228,10 @@ static struct {
     { "memorylocked",	login_getcapsize },
     { "maxproc",	login_getcapnum  },
     { "openfiles",	login_getcapnum  },
-    { "sbsize",		login_getcapsize  },
-    { "vmemoryuse",	login_getcapsize  },
+    { "sbsize",		login_getcapsize },
+    { "vmemoryuse",	login_getcapsize },
     { "pseudoterminals",login_getcapnum  },
+    { "swapuse",	login_getcapsize }
 };
 
 /*
@@ -233,7 +242,7 @@ static struct {
  * to be modified accordingly!
  */
 
-#define RCS_STRING  "tfdscmlunbvp"
+#define RCS_STRING  "tfdscmlunbvpw"
 
 static rlim_t resource_num(int which, int ch, const char *str);
 static void usage(void);
@@ -270,7 +279,7 @@ main(int argc, char *argv[])
     }
 
     optarg = NULL;
-    while ((ch = getopt(argc, argv, ":EeC:U:BSHab:c:d:f:l:m:n:s:t:u:v:p:")) != -1) {
+    while ((ch = getopt(argc, argv, ":EeC:U:BSHab:c:d:f:l:m:n:s:t:u:v:p:w:")) != -1) {
 	switch(ch) {
 	case 'a':
 	    doall = 1;
@@ -484,7 +493,7 @@ static void
 usage(void)
 {
     (void)fprintf(stderr,
-"usage: limits [-C class|-U user] [-eaSHBE] [-bcdflmnstuvp [val]] [[name=val ...] cmd]\n");
+"usage: limits [-C class|-U user] [-eaSHBE] [-bcdflmnstuvpw [val]] [[name=val ...] cmd]\n");
     exit(EXIT_FAILURE);
 }
 
@@ -556,6 +565,7 @@ resource_num(int which, int ch, const ch
 	case RLIMIT_MEMLOCK:
 	case RLIMIT_SBSIZE:
 	case RLIMIT_VMEM:
+	case RLIMIT_SWAP:
 	    errno = 0;
 	    res = 0;
 	    while (*s) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906232057.n5NKvRDE089939>