Chapter 18: Managing Memory
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 ones such as mtrace
and Valgrind.
We will learn the difference between kernel and user space memory, and how the kernel maps physical pages of memory to the address space of a process. Then we will locate and read the memory maps for individual processes under the proc
filesystem. We will see how the mmap
system call can be used to map a program's memory to a file, so that it can allocate memory in bulk or share it with another process. In the second half...