CS代考计算机代写 Carnegie Mellon

Carnegie Mellon
Key VM Structures in Linux
 vm_area_struct: describes the properties of a contiguous region of the virtual address space
 Entire region may contain many pages
 Entire region shares properties: permissions and associated
operations
 May be a file, library, group of libraries, etc.
 mm_struct: contains information about the process’ entire virtual address space
 Contains a list of vm_area_struct objects
 Processes have distinct mm_structs, threads share an mm_struct
1

Carnegie Mellon
VM Structures in Linux
task_struct mm_struct vm_area_struct Process virtual memory
vm_end
mm
vm_start
pgd
mmap
vm_prot
vm_flags
vm_next
vm_end
Shared libraries
vm_start
vm_prot
vm_flags
Data
vm_next
vm_end
Code
vm_start
vm_prot
vm_flags
vm_next
0
2

Carnegie Mellon
The fork Function Revisited
 VM and memory mapping explain how fork provides private
address space for each process.
 To create virtual address for new new process
 Create exact copies of current mm_struct, vm_area_struct, and page tables.
 Flag each page in both processes as read-only
 Flag each vm_area_struct in both processes as private COW
 On return, each process has exact copy of virtual memory
 Subsequent writes create new pages using COW mechanism.
3

Carnegie Mellon
The execve Function Revisited
libc.so
.data
User stack
Private, demand-zero
 Toloadandrunanew program a.out in the current process using execve:
 Free vm_area_struct’s and page tables for old areas
 Createvm_area_struct’s and page tables for new areas
 Programs and initialized data backed by object files.
 .bss and stack backed by anonymous files .
 SetPCtoentrypointin .text
 Linux will fault in code and data pages as needed.
Memory mapped region for shared libraries
.text
Shared, file-backed
Runtime heap (via malloc)
a.out
0
Private, demand-zero Private, demand-zero
Private, file-backed
Uninitialized data (.bss)
.data
Initialized data (.data)
.text
Program text (.text)
4