home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / arch / 8468 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  3.8 KB

  1. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!torvalds
  2. From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds)
  3. Newsgroups: comp.arch
  4. Subject: Re: Jump tables for shared libraries
  5. Message-ID: <1992Jul30.162108.28182@klaava.Helsinki.FI>
  6. Date: 30 Jul 92 16:21:08 GMT
  7. References: <1992Jul30.151301.27595@crd.ge.com>
  8. Organization: University of Helsinki
  9. Lines: 67
  10.  
  11. In article <1992Jul30.151301.27595@crd.ge.com> davidsen@crd.ge.com (bill davidsen) writes:
  12. >
  13. >  A recent post to comp.os.linux indicated that there would be a change
  14. >to jump tables for the shared libraries in the next release. WHile I
  15. >understand the convenience features of jump tables, it would seem that
  16. >there would be a better way to avoid relinking programs, which would
  17. >avoid the overhaed of the indirection.
  18.  
  19. [ Note that this has been extensively discussed on the linux kernel and
  20.   gcc mailing-lists..  We've just kept pretty quiet about it on the net,
  21.   as there were some problems with actual implementation.  They seem to
  22.   be mostly solved. ]
  23.  
  24. >  Two thoughts come to mind. The first is to have some form of runtime
  25. >loader, which would do the linking at image activation time, rather than
  26. >at image store time. This would cause startup overhead, but would avoid
  27. >runtime overhead due to the indirect.
  28.  
  29. This means page sharing and demand-loading are impossible (or /very/
  30. hard to implement), so it's actually not a good idea.  The result is a
  31. slower system than one using jump-tables, as binries use up to 2 times
  32. more memory, resulting in more swapping etc. 
  33.  
  34. The current linux page-sharing (of both shared libraries and
  35. executables) results in /much/ lower memory needs for most things
  36. (especially notable under X). Also, when the system runs out of memory,
  37. linux starts discarding clean pages (ie usually code) as well as doing
  38. actual paging to disk: the system knows it can re-demand-load any clean
  39. pages when it needs them.
  40.  
  41. With any kind of dynamic shared libraries, the above would be
  42. essentially impossible: the shared X libraries use the normal C
  43. libraries, so they would have to be dynamically linked, making the
  44. code-pages dirty and unshareable as well as forcing more swapping. 
  45.  
  46. >                 The second would be to have the
  47. >jump table in unmapped memory, and have the o/s catch the call, modify
  48. >the image in memory to use the real address, and then restart the
  49. >program at the point of the call. This moves stuff down into the kernel,
  50. >and imposes a trap for each point in the image at which a library call
  51. >occurs.
  52.  
  53. This is /much/ slower than the one unnecessary indirection. The
  54. indirection is actually just one machine-code instruction: a simple
  55. "jmp" to the correct address.  Trapping to the kernel for each library
  56. call would probably make for a system that is twice (or more) as slow.
  57.  
  58. And modifying the image in memory is impossible (or close to, anyway):
  59. what if the address is in a register variable? And it has the same
  60. page-sharing/demand-loading problem as the previous possibility.
  61.  
  62. >  Is there newer and/or better thinking on this problem? I estimated the
  63. >overhead at up to 5%, and the original poster mentioned that he actually
  64. >measured 2-4% on programs. While that makes me feel good about my
  65. >estimating skills, I'm not overjoyed at the thought of a 2-4% drop in
  66. >performance. Hopefully someone will suggest an alternative method which
  67. >I can pass along for consideration.
  68.  
  69. The overhead shouldn't be too big for any real applications: it does
  70. result in a pre-fetch flush, and the library jump-table pages have to be
  71. loaded in.  With many programs using the shared libraries, the latter is
  72. no problem: the jump-tables are essentially in memory all the time. 
  73. Jump-tables were thought to be the best possible solution: easy updating
  74. of shared libs with pretty minimal performance/memory loss.  Any dynamic
  75. system is liable to be slower, more complicated and have more problems. 
  76.  
  77.         Linus
  78.