Finding/changing max memory size available

der Mouse mouse at thunder.mcrcim.mcgill.edu
Thu May 30 20:37:31 AEST 1991


In article <24817 at unix.SRI.COM>, ric at 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 at larry.mcrcim.mcgill.edu



More information about the Comp.unix.questions mailing list