home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / hp / 9670 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  6.3 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!usc!sdd.hp.com!hp-cv!hp-pcd!hpfcso!mjs
  2. From: mjs@hpfcso.FC.HP.COM (Marc Sabatella)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: Shared libraries have me very confused!
  5. Message-ID: <7371254@hpfcso.FC.HP.COM>
  6. Date: 25 Aug 92 19:29:20 GMT
  7. References: <1992Aug25.053800.24067@news.uiowa.edu>
  8. Organization: Hewlett-Packard, Fort Collins, CO, USA
  9. Lines: 110
  10.  
  11. In comp.sys.hp, dsiebert@icaen.uiowa.edu (Doug Siebert) writes:
  12.  
  13. > I've got an application running on an HP 9000/710 with 48M of RAM under HP-UX
  14. > 8.07 that is run by up to 80 users at a time (and adding more would always be
  15. > an advantage) each running a separate copy of the application.
  16.  
  17. When you say "running a separate copy", do you literally mean a separate copy
  18. of the executable file?  If so, step one is to make sure everyone runs the same
  19. copy of the application, so you can shared text.
  20.  
  21. > I recompiled
  22. > again, this time with the option "-Wl,-a,archive" to the linker, which should
  23. > use the archive libraries instead of the shared libraries.  I figured I would
  24. > be using up more real memory by not using the shared libraries, but am in fact
  25. > using less!  How can this be?!
  26.  
  27. How did you measure real memory usage?  I don't think any of the available
  28. tools like "ps", "monitor", "glance", or anything using "pstat" are
  29. particularly smart about shared libraries.  I can easily imagine that they
  30. would think each instantiation of the program was using its own copy of the
  31. library.
  32.  
  33. If you are counting swap space, then you should *not* expect to see usage go
  34. down with shared libraries.  Swap is never used for text segments (it is paged
  35. in directly from the filesystem), so only data is an issue.  With archive
  36. libraries, a program will have swap reserved/allocated for all the data in the
  37. program, plus all the data copied out of archives libraries.  A typical Motif
  38. program accesses only 60% (or some other relatviely small amount) of the data
  39. in the libraries it is linked with, so only that amount of data is copied into
  40. the program.  With shared libraries, however, you are allocated swap for all
  41. the data in all the libraries you are linked with.  Plus, you are allocated
  42. swap for the data structures used by the dynamic loader.  Thus, a program
  43. typically needs more swap space when linked with shared libraries than archive
  44. libraries.  This does not mean it needs more real memory, however - most of
  45. the swap is allocated "just in case", but still only those pages that are used
  46. are allocated in memory, so a given process would use almost exactly the same
  47. amount of memory with shared as archive libraries.  Possibly a little more due
  48. to fragmentation of the data it is using (the 60% of the data it uses from a
  49. library may be scattered over 80% of the library's pages).
  50.  
  51. > 1)  How come NOT using shared libraries allowed my application to use up less
  52. > real memory per process?  If this is so, what is the point of shared libraries?
  53.  
  54. Possibility number one is that the program really isn't using less real memory
  55. with archive libraries - the tools that report memory usage may be flawed, or
  56. you may have been measuring the wrong thing (swap space).  As I observed above,
  57. any given process will appear to need slightly more (due to fragmentation, and
  58. dynamic loader overhead) real memory with shared libraries than with archive
  59. libraries.  The savings comes as soon as there is sharing - memory pages used
  60. for library text can be shared processes.  But note that program text is shared
  61. anyhow.  If your program is linked against libfoobar, and it is the only
  62. program linked against libfoobar, then its text pages will be shared among all
  63. users regardless of whether it is a shared library or not.  The shared library
  64. is only a win if some other program is also linked against libfoobar - then
  65. the pages will be shared among all users of both programs, rather than having
  66. one set of pages for users of one program and another set for users of the
  67. other.
  68.  
  69. To recap, you should expect any individual process to need significantly more
  70. swap when using shared libraries, and slightly more memory.  If you have
  71. several invocations of the same program at once (as you do), this only
  72. magnifies those differences.  The savings come when you also have *other*
  73. programs that use the same libraries.
  74.  
  75. Do we expect these savings to be realized in the average case?  I don't know.
  76. I know for a fact that in my environment, where the only programs I ever have
  77. running at once are several shells and several "hpterm"'s, there is no memory
  78. savings - the shells were built with archives libraries, and the hpterm's
  79. all share the Motif & X11 library code among themselves either way.  Now that
  80. I've started using VUE, maybe there is a savings; I don't know.
  81.  
  82. The real reason we implemented shared libraries is to save disk space for the
  83. delivered HP-UX - by not linking libc into every command, and libX11 into every
  84. tool, we cut the size of HP-UX itself down tremendously.
  85.  
  86. > 2)  How can I compile my application so as to make it share memory better among
  87. > the 80 copies of it that may be simultaneously running?  Is there something
  88. > big I'm missing?  Or would I have to tear it apart and put most of its
  89. > functions in a library of my own creation?  (And would I then want to make that
  90. > shareable or not?)
  91.  
  92. Assuming the application really is shared - all 80 users are running from the
  93. same i-node, I think you've done all you can.  If you're wondering just how
  94. much difference the libraries are making, try the following experiment:
  95.  
  96. 1. link your application normally, with something that presumably looks like:
  97.  
  98.     cc -o program.shared $(OBJS) $(LIBS)
  99.  
  100. 2. link it with archive libraries:
  101.  
  102.     cc -o program.archive $(OBJS) -Wl,-a,archive $(LIBS)
  103.  
  104. 3. link it with no libraries (result will not be executable):
  105.  
  106.     cc -o program.none $(OBJS)
  107.  
  108. Now run "size" on each of the resultant executables, and compare.  #2 and #3
  109. should be similar - #2 should be slightly larger due to shared library
  110. overhead.  #1 should be larger.  If it is "a lot" larger, it means you are
  111. using a lot of library code, and any tuning should indeed be in your use of
  112. libraries.  If is "only a little" larger, then most of the memory you are using
  113. is in your application code, and the libraries don't really make much
  114. difference.
  115.  
  116. --------------
  117. Marc Sabatella (marc@hpmonk.fc.hp.com)
  118. Disclaimers:
  119.     2 + 2 = 3, for suitably small values of 2
  120.     Bill (H.) and Dave (P.) may not always agree with me
  121.