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

  1. From: mike@hpfcso.FC.HP.COM (Mike McNelly)
  2. Date: Tue, 25 Aug 1992 16:22:57 GMT
  3. Subject: Re: Shared libraries have me very confused!
  4. Message-ID: <7371249@hpfcso.FC.HP.COM>
  5. Organization: Hewlett-Packard, Fort Collins, CO, USA
  6. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!mips!sdd.hp.com!hpscdc!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!mike
  7. Newsgroups: comp.sys.hp
  8. References: <1992Aug25.053800.24067@news.uiowa.edu>
  9. Lines: 62
  10.  
  11. > I've got an application running on an HP 9000/710 with 48M of RAM under HP-UX
  12. > 8.07 that is run by up to 80 users at a time (and adding more would always be
  13. > an advantage) each running a separate copy of the application.  I had compiled
  14. > it with the CFLAGS "+O3 +ESlit", which should, according to TFM for cc(1),
  15. > give me the highest level of optimization and put strings in read-only memory
  16. > for better sharing.  This machine uses shared libraries by default, which I
  17. > figured would save me memory.  Due to a couple bugs in the program, I
  18. > recompiled it without the +O3 and used -g instead, and found that it was dying
  19. > somewhere inside a shared library, which didn't tell me much, so I recompiled
  20. > again, this time with the option "-Wl,-a,archive" to the linker, which should
  21. > use the archive libraries instead of the shared libraries.  I figured I would
  22. > be using up more real memory by not using the shared libraries, but am in fact
  23. > using less!  How can this be?!
  24. > So I have two questions...
  25. > 1)  How come NOT using shared libraries allowed my application to use up less
  26. > real memory per process?  If this is so, what is the point of shared libraries?
  27.  
  28. You may be confusing the concepts of shared executables with shared
  29. libraries.  The Series 700 normally creates a.outs that are shared
  30. executables.  That is, all processes executing the SAME a.out will share
  31. a single text segment in memory.  That text segment will be loaded when
  32. the first using process begins execution and it will be removed from
  33. memory when the last process finishes.  Each process will have its own
  34. versions of the data and bss segments, however.  To minimize the total
  35. amount of memory needed to support many concurrent invocations of the
  36. program, therefore, you should strive to minimize the amount of data,
  37. not the size of the text segment.
  38.  
  39. A shared library is useful in reducing the size of the a.out, primarily
  40. an advantage in reducing the amount of disk storage for lots of
  41. different executables because none of the library routines are stored
  42. with the executable as part of the a.out.  If you have numerous
  43. DIFFERENT executables that run concurrently but which share the same
  44. library (e.g., libc.sl) then shared libraries can help, too.
  45.  
  46. Shared libraries are constructed using compiler options which cause
  47. somewhat less efficient code to be generated.  This is necessary because
  48. the code must be relocatable "on the fly" at execution time.  The code
  49. is not only a little slower but also a little bigger for each library
  50. call.  That's why you see the overall memory size grow slightly.
  51.  
  52. > 2)  How can I compile my application so as to make it share memory better among
  53. > the 80 copies of it that may be simultaneously running?  Is there something
  54. > big I'm missing?  Or would I have to tear it apart and put most of its
  55. > functions in a library of my own creation?  (And would I then want to make that
  56. > shareable or not?)
  57.  
  58. Minimize the size of your data and bss segments which are unique for
  59. each process.  If you have data that can be shared among processes you
  60. might consider the use of shared memory segments.
  61.  
  62. An excellent discussion in depth of the difference between shared
  63. executables and shared libraries is contained in "Programming on HP-UX",
  64. part number B2355-90010.  It may contains some further clues for you.
  65.  
  66. I hope this helps,
  67. Mike McNelly
  68. mike@fc.hp.com
  69. (Not a representative of anybody but myself)
  70.