Linux Kernel Development (9)
2011-06-16 17:23
375 查看
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.
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.
相关文章推荐
- Building AMDGPU Development Linux 4.15 Kernel on Ubuntu 17.04
- HOWTO do Linux kernel development - take 3 (中文版)
- Linux Kernel development (4)
- Linux Kernel Development——内存管理
- 【读书笔记】【linux kernel development】【从内核出发】
- 【读书笔记】【linux kernel development】【进程管理】
- Linux Kernel Development——虚拟文件系统
- Linux Kernel Development 3rd Edition 读书笔记(5)
- Linux Kernel Development——定时器和时间管理
- Linux Kernel development (4)
- Linux Kernel development (5)
- HOWTO do Linux kernel development (zt)
- 下载Linux kernel development了英文版2
- Linux Kernel and Driver Development Training
- Linux Kernel development (3)
- 怎样开发linux内核(HOWTO do Linux kernel development - take 3 (中文版))
- Linux Kernel Development 笔记(九)内核同步方法
- Linux Kernel Development (6)
- Linux Kernel Development Notes - 1
- Linux Kernel Development——中断