home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11447 < prev    next >
Encoding:
Text File  |  1992-07-22  |  2.5 KB  |  59 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!centerline!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!yale.edu!jvnc.net!darwin.sura.net!mips!pacbell.com!decwrl!parc!boehm
  3. From: boehm@parc.xerox.com (Hans Boehm)
  4. Subject: Re: good memory allocation strategies?
  5. Message-ID: <boehm.711834865@siria>
  6. Keywords: SGI kernel
  7. Sender: news@parc.xerox.com
  8. Organization: Xerox PARC
  9. References: <1992Jul21.214115.28569@tamsun.tamu.edu> <1992Jul22.172111.2646@hyper.hyper.com>
  10. Date: 22 Jul 92 19:54:25 GMT
  11. Lines: 46
  12.  
  13. hurst@hyper.hyper.com (Graham Hurst) writes:
  14.  
  15. >In article <1992Jul21.214115.28569@tamsun.tamu.edu> tsmith@cs.tamu.edu writes:
  16. >...
  17. >>I am working on a moderate size (~10000 lines so far) system on an SGI
  18. >>workstation running UNIX system V.3, and I am wondering about some
  19. >>memory allocation issues. [Rest deleted]
  20.  
  21. >Beware of using memory allocation on SGI computers!
  22.  
  23. >We recently discovered a "feature" of the default SGI kernel that makes
  24. >dynamic memory allocation unreliable - it never turns down a request for
  25. >memory!
  26.  
  27. >Since IRIX 3.3.2, the default SGI kernel will cause malloc/realloc
  28. >(via sbrk) to return a non-zero pointer even if the requested memory size is
  29. >greater than the sum of physical memory and swap space! If your app tries
  30. >to use enough of this memory, the kernel sends a SIGKILL to kill your app
  31. >and puts a message on the console about running out of swap space.
  32.  
  33. This does increase the probability of crashes due to running out of
  34. swap space.  But the traditional way of checking malloc results is
  35. already somewhat unreliable under most circumstances.  Consider
  36. the following scenario:
  37.  
  38. malloc(enough space to barely fit in swap space);
  39. call deeply recursive procedure;
  40.  
  41. On most systems that I know of, your process now gets sent a bus error due
  42. to the inability of the kernel to grow your process stack sufficiently.
  43. You can try to avoid this by growing the stack sufficiently in the beginning,
  44. and catching any bus errors that occur; but if it weren't for the
  45. particularly poor choice of SIGKILL, you could do the analogous thing
  46. for malloc.  (AIX gives you a warning signal first, before it sends
  47. SIGKILL, I believe.  This initially struck me as silly, but I'm begginning
  48. to believe that it's more useful than any of the other alternatives,
  49. including the one in which malloc preallocates swap space.)
  50.  
  51. Note that similar problems occur if there are other crucial processes
  52. allocating swap space on the same machine.  Copy-on-write pages for
  53. shared libararies are yet another problem.  Malloc is only one consumer
  54. of swap space.
  55.  
  56. Hans-J. Boehm
  57. (boehm@parc.xerox.com)
  58.  
  59.