Xref: utzoo comp.unix.questions:31792 comp.lang.c:39718 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.unix.questions,comp.lang.c Subject: Re: Finding/changing max memory size available Message-ID: <1991May30.103731.28593@thunder.mcrcim.mcgill.edu> Date: 30 May 91 10:37:31 GMT References: <24817@unix.SRI.COM> Organization: McGill Research Centre for Intelligent Machines Lines: 52 In article <24817@unix.SRI.COM>, ric@ace.sri.com (Richard Steinberger) writes: > The following short program finds the maximum amount of memory that > can be allocated through use of malloc(). [program deleted - it just repeats malloc(1000000L) until failure] Not quite. Aside from the bug (malloc takes an int or an unsigned int, not a long, as an argument), it tells you the number of 1000000-byte chunks you can allocate. This may bear less relation than you hope to the maximum amount of memory allocatable. > What I'd like to know is, "Where/How is this limit set? Is this a a > function of 1 or more kernel parameters, or other system > configuration variables?" Can the upper allocatable memory limit be > changed (without adding physical memory, of course)? This limit is a complex interaction of several things. - There's generally a limit on the maximum size of a process' virtual address space. (Set at kernel build time on those few systems I am sufficiently familiar with to tell about.) - There's a limit on the total size of the virtual address spaces of all processes. (Typically this is the amount of swap space available, with shared text segments and mmap()ed files (if applicable) not counted.) - There may be a purely software-imposed limit on the maximum size of your data segment, depending on your system. (Check to see if you have the setrlimit call, and look for RLIMIT_DATA.) - There may be an implicit limit built into malloc. - Probably something else I've forgotten. Usually, in my experience, the second one is the one you actually hit, though in some circumstances I've hit the first one instead. As for how you can change it...that depends on which one you want to change. For the first one you will have to consult your OS documentation; if it is silent, it is probably (at best) a compile-time parameter of your kernel. For the second, you'll have to either add swap space or kill off other processes. For the third, you should raise the resource limit with setrlimit. For the fourth, you'd have to recompile malloc. For the fifth I can't help :-) der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu