Subject: Re: re-limit?
To: None <mcmahill@mtl.mit.edu>
From: Simon Burge <simonb@netbsd.org>
List: netbsd-help
Date: 04/19/2000 00:00:41
mcmahill@mtl.mit.edu wrote:

> Is there a way to change the memory limits on an already running job?  Ie,
> I should have done 'unlimit datasize' _before_ starting this job, but its
> now 2 days into it and I don't want to stop it and start over.  

Can you tell the job to load arbitary code and execute it? ;)


It looks like if you set p->p_rlimit[RLIMIT_{DATA,NOFILE,NPROC}].rlim_cur
by playing around in kernel memory, there should be no side effects.

The following really ugly hacky patch thingy to ps will double the current
data limit for each process it lists, for a very limited bit of testing on
an i386 (using "ps <pid>").  USE AT YOUR OWN RISK :-)

Simon.
--
Index: ps.c
===================================================================
RCS file: /cvsroot/basesrc/bin/ps/ps.c,v
retrieving revision 1.36
diff -p -u -r1.36 ps.c
--- ps.c	2000/04/15 04:40:46	1.36
+++ ps.c	2000/04/18 13:55:24
@@ -114,6 +114,7 @@ main(argc, argv)
 	int argc;
 	char *argv[];
 {
+struct rlimit rlimitbuf[RLIM_NLIMITS];
 	struct varent *vent;
 	struct winsize ws;
 	gid_t egid = getegid();
@@ -313,7 +314,7 @@ main(argc, argv)
 	else
 		(void)setegid(egid);
 
-	kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf);
+	kd = kvm_openfiles(nlistf, memf, swapf, O_RDWR, errbuf);
 	if (kd == 0) {
 		if (dontuseprocfs)
 			errx(1, "%s", errbuf);
@@ -388,6 +389,14 @@ main(argc, argv)
 	 */
 	for (i = lineno = 0; i < nentries; i++) {
 		KINFO *ki = &kinfo[i];
+
+printf("rlimit = %p\n", KI_PROC(ki)->p_rlimit);
+kvm_read(kd, (u_long)KI_PROC(ki)->p_rlimit, rlimitbuf, sizeof(rlimitbuf));
+printf("rlimit[RLIMIT_DATA].rlim_cur = %p\n", rlimitbuf[RLIMIT_DATA].rlim_cur);
+printf("rlimit[RLIMIT_DATA].rlim_max = %p\n", rlimitbuf[RLIMIT_DATA].rlim_max);
+
+rlimitbuf[RLIMIT_DATA].rlim_cur *= 2;
+kvm_write(kd, (u_long)KI_PROC(ki)->p_rlimit, rlimitbuf, sizeof(rlimitbuf));
 
 		if (xflg == 0 && (KI_EPROC(ki)->e_tdev == NODEV ||
 		    (KI_PROC(ki)->p_flag & P_CONTROLT ) == 0))