home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 160.lha / Fragit / POSTER < prev    next >
Text File  |  1988-04-27  |  4KB  |  72 lines

  1.   Well, all this talk about memory fragmentation got me motivated to write
  2. a little program to deliberately fragment memory.  I named it Fragit 8-)
  3.  
  4.   Fragit seems to have uncovered a subtle "window of vunerability" in
  5. Exec's memory management.  First, let me describe what Fragit does
  6. exactly.
  7.  
  8.   Fragit allocates random sized blocks of memory, using RangeRand() to
  9. generate psuedo-random size values that range from 24 bytes to 10000 bytes.
  10. Thus, both odd and even fragment sizes are generated, but all sizes are
  11. "legal" from a Kernal viewpoint -- it just rounds them up to the next
  12. 8 byte size boundary.
  13.  
  14.   These random sized fragments are linked together into a dynamically
  15. allocated linked-list of Exec style MinNodes.  AddHead() is used to insert
  16. a new node (called a FragNode) at the head of the list.
  17.  
  18.   Fragit checks AvailMem(MEMF_PUBLIC) before it allocates a new random
  19. fragment; if the available memory has dropped below the threshold set
  20. (which defaults to 100K), Fragit _randomly_ deallocates one of the nodes
  21. in the MinList of FragNodes.  This is done by generating a random number
  22. N such that 0 <= N < 100, then skipping through the FragNode list to the
  23. Nth node in the list.  If Fragit hits the end of the list, it merely
  24. wraps around to the head of the list again.  The node is then Remove()'ed
  25. from the list and deallocated.  Of course, Fragit checks to see if the list
  26. is empty before trying to remove or deallocate a node!
  27.  
  28.   Thus, if AvailMem(MEMF_PUBLIC) is less than the low memory threshold,
  29. Fragit starts deallocating random fragments in the list until there is
  30. enough memory to attempt allocating another fragment.  When AvailMem()
  31. shows that there is more system memory than the low memory threshold,
  32. it attempts to allocate and add another fragment to the head of the
  33. list.
  34.  
  35.   The result is a dynamic allocation nightmare: thousands of memory
  36. fragments are being created and destroyed every minute.  In a matter
  37. of moments, you can fragment free memory so badly that you can't even
  38. resize a window!  The idea was to put stress on the AllocMem()/FreeMem()
  39. parts of an application undergoing debugging by simulating a very busy,
  40. highly fragmented memory environment.
  41.  
  42.   Unfortunately, Fragit seems to have demonstrated even if you have plenty
  43. of RAM and a good sized MEMF_LARGEST, that merely calling AllocMem() can crash
  44. the system with a GURU 3 or 4!  This only seems to happen when you
  45. set a fairly high value for the low memory threshold (1meg seems to do it)
  46. combined with a large random allocation size (asking AllocMem() for blocks
  47. that are between 20K and 50K in size.)
  48.  
  49.   I don't think Fragit is at fault -- if I change the code so that
  50. fragmentation never occurs (i.e., always AddHead()/RemHead()), then the
  51. program never fails.  Fragit always returns every byte allocated, uses no
  52. special tricks, and is using Exec calls for the list management.  Also,
  53. it runs for hours using the default values supplied: 100K low memory threshold,
  54. 24 byte lower limit and a 10000 byte upper limit on fragment sizes.
  55. (NOTE: if I run NoFastMem, it WILL crash occasionally with these defaults)
  56. I've reproduced this problem on both my 1-Meg 500 and my 9-Meg 2000 - it
  57. _might_ be the expansion ram, but I sort of doubt it.  With the verbose
  58. flag set, I can tell that the program is either croaking on AllocMem() or
  59. soon after that -- no telling where since it is just about impossible
  60. to trace it with a debugger.
  61.  
  62.   I've posted the source code (MANX 3.6a) and the executable in
  63. amiga.dev/listings as "fragit.arc".  Please download and try this program
  64. out on other hardware configurations with various parameter settings and
  65. see if you can reproduce this problem!  Either my code, Exec, or the hardware
  66. is at fault, and I can't sleep soundly until I know which one is the
  67. culprit.  Needless to say, if the problem is in Exec, I'm going to blame
  68. all GURU 3's and 4's generated by my commercial code on Carl. 8-(
  69.  
  70.  
  71.     Justin V. McCormick
  72.