This chapter covers issues related to memory management, which is an important topic for any Linux system but especially for embedded Linux, where system memory is usually in limited supply. After a brief refresher on virtual memory, I will show you how to measure memory usage, how to detect problems with memory allocation, including memory leaks, and what happens when you run out of memory. You will have to understand the tools that are available, from simple tools such as free and top, to complex tools such as mtrace and Valgrind.
In this chapter, we will cover the following topics:
- Virtual memory basics.
- Kernel space memory layout.
- User space memory layout.
- The process memory map.
- Swapping.
- Mapping memory with mmap.
- How much memory does my application use?
- Per-process memory usage.
- Identifying memory leaks.
- Running out of memory.