home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / fj / maillis / xwindow / 17588 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  4.2 KB

  1. Path: sparky!uunet!stanford.edu!sun-barr!sh.wide!wnoc-tyo-news!scslwide!wsgw!wsservra!daemon
  2. From: jimf@centerline.com (Jim Frost)
  3. Newsgroups: fj.mail-lists.x-window
  4. Subject: Re: FLAME, FLAME ON X!!!
  5. Message-ID: <1992Nov18.121338.13827@sm.sony.co.jp>
  6. Date: 18 Nov 92 12:13:38 GMT
  7. Sender: daemon@sm.sony.co.jp (The devil himself)
  8. Distribution: fj
  9. Organization: CenterLine Software, Inc.
  10. Lines: 76
  11. Approved: michael@sm.sony.co.jp
  12.  
  13. Date: 17 Nov 92 22:37:47 GMT
  14. Message-Id: <1ebs7rINNp9k@armory.centerline.com>
  15. Newsgroups: comp.windows.x
  16. References: <1992Nov9.235741.25166@dsd.es.com>, <RJC.92Nov13144522@daiches.cogsci.ed.ac.uk>, <1992Nov16.162457.2923@osf.org>
  17. Sender: xpert-request@expo.lcs.mit.edu
  18.  
  19. drand@spinner.osf.org (Douglas S. Rand) writes:
  20. >|> The word is `Fragmentation'. 
  21.  
  22. >There are a number of reasonable solutions to memory fragmentation.  It really
  23. >is up to a decent malloc implementation to attempt to avoid fragmentation.
  24. >I'll illustrate with a well known method which we used on Prime's EMACS and
  25. >which I believe libg++ uses.  
  26.  
  27. >Allocate all memory in set size chunks.  Sizes can be on powers of two, for
  28. >example.  Freeing a block places it on a free list for that size.  Allocation
  29. >requests first go to the most natural next size block and progress upward in
  30. >size.  Optionally break larger blocks if no smaller blocks are available.
  31. >Optionally run the block lists on occation and join smaller contiguous
  32. >blocks into larger blocks.  
  33.  
  34. Unfortunately power-of-two allocation is remarkably wasteful of
  35. virtual memory (which means wasteful of real live swap space on many
  36. systems).  It works fine for very tiny allocations but once you start
  37. allocating those "unusual" sizes like 80-byte segments you start
  38. seeing major memory waste as well as relatively slow free-element
  39. location compared to several other techniques.
  40.  
  41. The two best generic allocation systems I've run into are
  42. limited-cluster (usually just called cluster) and a nifty tree system
  43. done by a research guy at IBM.
  44.  
  45. Limited-cluster systems predict that most programs do a lot of little
  46. allocations of the same size (up to, say, 128 bytes) but fewer large
  47. ones of widely varying sizes, and therefore allocate a lot of little
  48. allocations up front.  Managing allocations and frees of the little
  49. allocations is dirt cheap and you get very little fragmentation (and a
  50. lot of locality to boot).  Some systems I've seen use power-of-two
  51. fitting for the clustered allocations, but I personally believe that
  52. you get better overall behavior by using linear increases since they
  53. are far less wasteful after the first few power steps (and in fact
  54. most linear fitting schemes are practically the same as power fitting
  55. for the first few power steps).  Large allocations are done as
  56. necessary and fitted as exactly as possible.  The big win is keeping
  57. the many small allocations in most programs away from the few big
  58. ones, which keeps fragmentation down.
  59.  
  60. Limited-cluster allocation systems are commonly used when memory is
  61. not a major issue but heap maintenance overhead is.
  62.  
  63. The tree allocation system done at IBM is more complicated, ordering a
  64. tree of memory fragments by both address and size.  Address ordering
  65. makes defragmentation a snap since adjacent allocations will always
  66. share adjacent nodes, and size ordering makes finding a good fit easy.
  67.  
  68. It's an interesting system -- interesting enough that IBM shifted from
  69. a power-of-two allocation system to their research system between
  70. release 3.1 and 3.2 of AIX, largely due to customer complaints about
  71. overwhelming memory waste in the 3.1 malloc(*).  There's an article in
  72. the IBM Journal of Research and Development on the topic but I don't
  73. have the issue handy.
  74.  
  75. Informationally yours,
  76.  
  77. jim frost
  78. jimf@centerline.com
  79.  
  80. (*) Many of the observed performance problems may have been due to
  81. their technique of recycling allocations when the available heap is
  82. exhausted rather than using a more aggressive system.  Long recycle
  83. times lead to poor heap locality and much-higher-than-necessary paging
  84. rates.  A power-of-two allocator that aggressively reuses allocations
  85. would have fewer problems in this regard although locality would still
  86. be hurt for multiple allocations which were not particularly well
  87. fitted to a power-of-two.  The AIX 3.2 system is far more aggressive
  88. at reuse.
  89.