An Analysis of How Static and Shared Libraries Affect Memory Usage on an IP-STB
Total Page:16
File Type:pdf, Size:1020Kb
An analysis of how static and shared libraries affect memory usage on an IP-STB Master of Science Thesis in the Programme Networks and Distributed Systems Dongping Huang Chalmers University of Technology University of Gothenburg Department of Computer Science and Engineering Göteborg, Sweden, September 2010 The Author grants to Chalmers University of Technology and University of Gothenburg the non-exclusive right to publish the Work electronically and in a non-commercial purpose make it accessible on the Internet. The Author warrants that he/she is the author to the Work, and warrants that the Work does not contain text, pictures or other material that violates copyright law. The Author shall, when transferring the rights of the Work to a third party (for example a publisher or a company), acknowledge the third party about this agreement. If the Author has signed a copyright agreement with a third party regarding the Work, the Author warrants hereby that he/she has obtained any necessary permission from this third party to let Chalmers University of Technology and University of Gothenburg store the Work electronically and make it accessible on the Internet. An analysis of how code locality affects the dynamic memory usage on an embedded set- top box running Linux Dongping Huang © Dongping Huang, September 2010. Examiner: Björn von Sydow Chalmers University of Technology University of Gothenburg Department of Computer Science and Engineering SE-412 96 Göteborg Sweden Telephone + 46 (0)31-772 1000 Department of Computer Science and Engineering Göteborg, Sweden September 2010 Abstract An IP-STB is a small and stand alone embedded system which is able to provide a series of advanced entertaining services. However, like an ordinary embedded system, an IP-STB still has to bear with extremely main memory constraints and no disk space. Normally, advanced features provided by an IP-STB require a large amount of limited main memory, therefore how to maintain a small static memory footprint and low memory usage becomes very important. Libraries composed of shared code contribute to a significant amount of memory consumption. Libraries can be categorized into two types: static libraries and shared libraries. Both of them have their pros and cons in terms of memory usage and system performance. However, there is no existing generic method to determine when and why to choose one type over the other one. To address this problem, a series of tools were implemented to give a quantitative analysis of how different types of libraries affect the system memory usage. Besides, their advantages and disadvantages were discussed and compared. In addition to the above, the optimization of shared libraries was also investigated. Acknowledgement First of all, I would like to express my deepest gratitude to Motorola for giving me this opportunity to accomplish this thesis. I would particularly like to acknowledge my supervisor Patrik Almqvist for his patient guidance and assistance. Finally, I would like to thank my examiner Björn von Sydow at Chalmers University of Technology for his valuable guidance and feedback. Table of Contents 1 Introduction..............................................................................................................................1 1.1 Background.......................................................................................................................1 1.2 Problems description........................................................................................................1 1.3 Objective...........................................................................................................................1 1.4 Glossary............................................................................................................................2 1.5 Thesis organization...........................................................................................................3 2 The System...............................................................................................................................4 2.1 Hardware..........................................................................................................................4 2.2 Software............................................................................................................................4 2.3 IP-STB installation packages............................................................................................4 2.4 Boot images......................................................................................................................4 2.5 Boot procedure.................................................................................................................5 2.6 File systems......................................................................................................................5 3 Libraries and tools....................................................................................................................7 3.1 ELF...................................................................................................................................7 3.2 Static libraries...................................................................................................................9 3.3 Shared libraries...............................................................................................................10 3.4 Linux memory mapping.................................................................................................11 3.5 GNU compiler and binutils.............................................................................................11 3.5.1 The /proc file system...............................................................................................12 4 Measuring memory usage: methodology ..............................................................................15 4.1 Prerequisites....................................................................................................................15 4.2 Listing dependencies......................................................................................................15 4.3 Measuring memory usage...............................................................................................16 4.4 The specific procedure of measurement.........................................................................18 5 Discussion..............................................................................................................................20 5.1 Shortcomings of static libraries......................................................................................20 5.2 Shortcomings of shared libraries....................................................................................21 5.3 Static libraries or shared libraries ..................................................................................25 5.3.1 Memory usage.........................................................................................................25 5.3.2 System performance................................................................................................25 5.3.3 Compatibility and extendibility..............................................................................26 5.3.4 General proposals ...................................................................................................26 5.4 How to remove unused material.....................................................................................27 5.5 Position independent code (PIC)....................................................................................28 5.5.1 Differences between -fPIC and -fpic .....................................................................28 5.5.2 Relocation processing.............................................................................................29 5.5.3 Cost of position independent code..........................................................................29 5.5.4 Why not use PIC for all applications?....................................................................31 6 Summary................................................................................................................................32 6.1 Conclusion......................................................................................................................32 6.2 Future work.....................................................................................................................32 7 References..............................................................................................................................33 8 Appendix A............................................................................................................................34 9 Appendix B.............................................................................................................................35 1 Introduction 1.1 Background An ordinary set-top box is a device that connects to a television to display digital TV and receives digital signal from external sources such as satellites, cables and antennas. An IP based set-top box (IP-STB), as its name implies, connects and receives digital signals from IP based networks. Taking full advantages of broadband networks, an IP-STB is able to provide a range of advanced services such as video on demand (VOD), time-shifting video, muliticast TV, as well as some Internet applications, including web surfing and so on. The IP-STB used