Return to BSD News archive
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!sun-barr!cs.utexas.edu!uunet!not-for-mail From: sef@Kithrup.COM (Sean Eric Fagan) Newsgroups: comp.os.386bsd.bugs Subject: Re: VM problems w/unlimited memory? PATCHES Date: 12 Mar 1993 16:46:50 -0800 Organization: Kithrup Enterprises, Ltd. Lines: 214 Sender: sef@ftp.UU.NET Message-ID: <1nratqINN4uk@ftp.UU.NET> References: <C3qpIH.Is9@unx.sas.com> <1nprd8$8nj@Germany.EU.net> <C3s2nz.9sz@unx.sas.com> <1nqtmjINNlns@ftp.uu.net> NNTP-Posting-Host: ftp.uu.net In article <1nqtmjINNlns@ftp.uu.net> sef@Kithrup.COM (Sean Eric Fagan) writes: >I'm thinking about the "right" way to fix it. Well, the "right" way of fixing it won't be possible without some 4.4 changes (the "sysctl" system call), but here is a more traditional and still correct and clean way of fixing it. I have tested it, and bash no longer causes my system to panic. Note that it does place an upper limit on the number of open files per process, defaulting to 2048; to increase this default, add a maxfdescs <num> to your configuration file, and re-config it. There are patches to kernel files, and to config. My kernel is slightly different from the "official" ones, so line numbers in the patches may be off by a bit; hopefully not too much. *** sys.386bsd/kern/kern_resource.c.~1~ Sat Jun 20 20:01:33 1992 --- sys.386bsd/kern/kern_resource.c Fri Mar 12 14:57:01 1993 *************** *** 191,196 **** --- 191,197 ---- struct rlimit alim; register struct rlimit *alimp; extern unsigned maxdmap; + extern int maxfdescs; int error; if (uap->which >= RLIM_NLIMITS) *************** *** 217,222 **** --- 218,229 ---- alim.rlim_max = maxdmap; break; + case RLIMIT_OFILE: + if (alim.rlim_cur > maxfdescs) + alim.rlim_cur = maxfdescs; + if (alim.rlim_max > maxfdescs) + alim.rlim_max = maxfdescs; + break; case RLIMIT_STACK: if (alim.rlim_cur > maxdmap) alim.rlim_cur = maxdmap; *** sys.386bsd/kern/kern_descrip.c.~1~ Fri Mar 27 16:04:45 1992 --- sys.386bsd/kern/kern_descrip.c Fri Mar 12 14:36:38 1993 *************** *** 55,60 **** --- 55,61 ---- */ struct file *filehead; /* head of list of open files */ int nfiles; /* actual number of open files */ + extern int maxfdescs; /* maximum number of file descriptors to a process */ /* * System calls on descriptors. *************** *** 123,129 **** if (old >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[old]) == NULL || ! new >= p->p_rlimit[RLIMIT_OFILE].rlim_cur) return (EBADF); *retval = new; if (old == new) --- 124,131 ---- if (old >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[old]) == NULL || ! new >= p->p_rlimit[RLIMIT_OFILE].rlim_cur || ! new >= maxfdescs) return (EBADF); *retval = new; if (old == new) *************** *** 175,181 **** pop = &fdp->fd_ofileflags[uap->fd]; switch(uap->cmd) { case F_DUPFD: ! if ((unsigned)uap->arg >= p->p_rlimit[RLIMIT_OFILE].rlim_cur) return (EINVAL); if (error = fdalloc(p, uap->arg, &i)) return (error); --- 177,184 ---- pop = &fdp->fd_ofileflags[uap->fd]; switch(uap->cmd) { case F_DUPFD: ! if ((unsigned)uap->arg >= p->p_rlimit[RLIMIT_OFILE].rlim_cur || ! ((unsigned)uap->arg >= maxfdescs)) return (EINVAL); if (error = fdalloc(p, uap->arg, &i)) return (error); *** sys.386bsd/conf/param.c.~1~ Tue Dec 24 14:24:07 1991 --- sys.386bsd/conf/param.c Fri Mar 12 14:35:15 1993 *************** *** 56,62 **** * the kernel; it should be modified there to suit local taste * if necessary. * ! * Compiled with -DHZ=xx -DTIMEZONE=x -DDST=x -DMAXUSERS=xx */ #ifndef HZ --- 56,62 ---- * the kernel; it should be modified there to suit local taste * if necessary. * ! * Compiled with -DHZ=xx -DTIMEZONE=x -DDST=x -DMAXUSERS=xx -DMAXFDESCS=xx */ #ifndef HZ *************** *** 71,76 **** --- 71,77 ---- #define NTEXT (80 + NPROC / 8) /* actually the object cache */ #define NVNODE (NPROC + NTEXT + 100) long desiredvnodes = NVNODE; + int maxfdescs = MAXFDESCS; int maxfiles = 3 * (NPROC + MAXUSERS) + 80; int ncallout = 16 + NPROC; int nclist = 60 + 12 * MAXUSERS; *** usr.sbin/config/config.h.~1~ Mon Jul 1 11:14:10 1991 --- usr.sbin/config/config.h Fri Mar 12 14:23:05 1993 *************** *** 191,196 **** --- 191,197 ---- int profiling; int debugging; + int maxfdescs; int maxusers; #define eq(a,b) (!strcmp(a,b)) *** usr.sbin/config/config.y.~1~ Mon Jul 1 11:14:11 1991 --- usr.sbin/config/config.y Fri Mar 12 14:27:15 1993 *************** *** 31,36 **** --- 31,37 ---- %token MACHINE %token MAJOR %token MASTER + %token MAXFDESCS %token MAXUSERS %token MINOR %token MINUS *************** *** 200,205 **** --- 201,208 ---- = { zone = -$3; dst = $5; check_tz(); } | TIMEZONE MINUS FPNUMBER DST = { zone = -$3; dst = 1; check_tz(); } | + MAXFDESCS NUMBER + = { maxfdescs = $2; }; | MAXUSERS NUMBER = { maxusers = $2; }; *** usr.sbin/config/lang.l.~1~ Mon Feb 24 14:38:58 1992 --- usr.sbin/config/lang.l Fri Mar 12 14:23:10 1993 *************** *** 78,83 **** --- 78,84 ---- { "major", MAJOR }, { "makeoptions", MAKEOPTIONS }, { "master", MASTER }, + { "maxfdescs", MAXFDESCS }, { "maxusers", MAXUSERS }, { "minor", MINOR }, #if MACHINE_I386 *** usr.sbin/config/mkmakefile.c.~1~ Sat Mar 6 17:27:25 1993 --- usr.sbin/config/mkmakefile.c Fri Mar 12 14:29:03 1993 *************** *** 55,60 **** --- 55,62 ---- #include "y.tab.h" #include "config.h" + #define DEF_MAXFDESCS 2048 + #define next_word(fp, wd) \ { register char *word = get_word(fp); \ if (word == (char *)EOF) \ *************** *** 183,188 **** --- 185,194 ---- up = &users[MACHINE_VAX-1]; } else up = &users[machine-1]; + if (maxfdescs == 0) { + printf("maxfdescs not specifid; %d assumed\n", DEF_MAXFDESCS); + maxfdescs = DEF_MAXFDESCS; + } if (maxusers == 0) { printf("maxusers not specified; %d assumed\n", up->u_default); maxusers = up->u_default; *************** *** 191,198 **** maxusers = up->u_min; } else if (maxusers > up->u_max) printf("warning: maxusers > %d (%d)\n", up->u_max, maxusers); ! fprintf(ofp, "PARAM=-DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d\n", ! zone, dst, maxusers); for (op = mkopt; op; op = op->op_next) fprintf(ofp, "%s=%s\n", op->op_name, op->op_value); if (debugging) --- 197,204 ---- maxusers = up->u_min; } else if (maxusers > up->u_max) printf("warning: maxusers > %d (%d)\n", up->u_max, maxusers); ! fprintf(ofp, "PARAM=-DTIMEZONE=%d -DDST=%d -DMAXUSERS=%d -DMAXFDESCS=%d\n", ! zone, dst, maxusers, maxfdescs); for (op = mkopt; op; op = op->op_next) fprintf(ofp, "%s=%s\n", op->op_name, op->op_value); if (debugging)