The Memory Descriptor
Processes may elect to share their address spaces with their children by means of the CLONE_VM flag to clone().The process is then called a thread. Recall from Chapter 3, “Process Management,” that this is essentially the only difference between normal processes and so-called threads in Linux.
Destroying a Memory Descriptor
The mm_struct and Kernel Threads
Kernel threads do not have a process address space and therefore do not have an associated memory descriptor.Thus, the mm field of a kernel thread’s process descriptor is NULL. This is the definition of a kernel thread—processes that have no user context.
Therefore, when a kernel thread is scheduled, the kernel notices that mm is NULL and keeps the previous process’s address space loaded.The kernel then updates the active_mm field of the kernel thread’s process descriptor to refer to the previous process’s memory descriptor.
Virtual Memory Areas
Lists and Trees of Memory Areas
The linked list is used when every node needs to be traversed.The red-black tree is used when locating a specific memory area in the address space
Memory Areas in Real Life
Let’s look at a particular process’s address space and the memory areas inside.This task uses the useful /proc filesystem and the pmap(1) utility
rlove@wolf:~$ pmap 1426
example[1426]
00e80000 (1212 KB) r-xp (03:01 208530) /lib/tls/libc-2.5.1.so
00faf000 (12 KB) rw-p (03:01 208530) /lib/tls/libc-2.5.1.so
00fb2000 (8 KB) rw-p (00:00 0)
08048000 (4 KB) r-xp (03:03 439029) /home/rlove/src/example
08049000 (4 KB) rw-p (03:03 439029) /home/rlove/src/example
40000000 (84 KB) r-xp (03:01 80276) /lib/ld-2.5.1.so
40015000 (4 KB) rw-p (03:01 80276) /lib/ld-2.5.1.so
4001e000 (4 KB) rw-p (00:00 0)
bfffe000 (8 KB) rwxp (00:00 0) [ stack ]
mapped: 1340 KB writable/private: 40 KB shared: 0 KB
Manipulating Memory Areas
mmap() and do_mmap(): Creating an Address Interval 创建连续的内存。
The do_mmap()function is used by the kernel to create a new linear address interval. Saying that this function creates a new VMA is not technically correct, because if the created address interval is adjacent to an existing address interval, and if they share the same permissions, the two intervals are merged into one. If this is not possible, a new VMA is created.
Page Tables
Consequently, when an application accesses a virtual memory address, it must first be converted to a physical address before the processor(CPU) can resolve the request.
Performing this lookup is done via page tables. Page tables work by splitting the virtual address into chunks. Each chunk is used as an index into a table.The table points to either another table or the associated physical page.
most processors implement a translation lookaside buffer, or simply TLB.