Linux Memory Memagement

Download Report

Transcript Linux Memory Memagement

Linux Memory Management
Initialization
Some concept
Address translation
User view -logical address

User space vs Kernel space
- linear address
0~4GB
(x86) ie.Alpha 2^64 byte
- physical address
Physical
situation
ie: logical linear physical

Logical Address
- local descriptor table LDT
for user space
every task has one LDT
ie: struct desc_struct* ldt ;
global descriptor table GDT
for kernel space
- sgment descriptor
entry in LDT/GDT
- selector
GDTR
Seg descriptor
,,
,,
GDT[0]=null
GDT[1]=kernel cod
seg descr
GDT[1]=kernel dat
base
logical
LDTR
Seg descriptor
selector
CS /DS
offset
EIP
memory
limit
LDT[0]=null
LDT[1]=user code
seg descrip
LDT{2]=user data
seg descrip

Logicasl address to Linear adderss
- user space
segment descriptor=(0 ,0xc0000000)
Task_size 變數 = 0xc00000000
linear address=0x000000000xc00000000
- kernel space :
segment descriptor=(0xc0000000,4GB)
linear address=3GB4GB
Logical address
Linear address
0GB
Task
User
space
Kernel
Space
Segment
hardware
3GB
4GB

Linear to Physical
- paging hardware mechanisinm
- x86 is two layer
DIR
10bit
TABLE
10bit
OFFSET
12bit
Physcial
memory
Page
hardware
Linear address
DIR
TABLE
index
page
page
index
table
index
directory
Dir base

Some important points
- swapper_pg_dir
- in th memory initial stats
- the first 768 entry in swapper_pg_dir =0
above 768 , mapping 3GB~4GB to physcial
- all Task’page directory has the “same” value
as swapper_pg_dir from entry 768 to 1024 -why??
768*4MB= 3072000000 ~=3GB
let all task’s kernel space(3GB~4GB)
can map to the same physical memory

Example
- Task from user sapce to kernel
space
1. Prcoess ‘s seg_base= 0x00
page_dir private to process
2. make system call
3.seg_bsae=0xc0000000
page_dir has the same above 768 value as
swapper_pg_dir
4. Noe we run kernel space using the common page
tables
ie: run the same physical space

Concluds
1.when task/process runs in user
sapce ,it can run in arbitrary Physical
space according to it’s page_dir(0~768entry)
2. but runs in kernel space,
process just can run the common
physical space (the place we put kernel)
Memory initialization

arch/i386/kernel/HEAD.S

int/main.c
start_kernel()
{
.
.
paging_init(); call free_area_init()
.
mem_init();

Major work
paging_init()
- Initial the page tables of
swapper_pg_dir (from 768 entry)
free_area_init()
- loacate swap_cache space
initial free_list
- mem_init()
contruct the mem_map in the
memory to reflect the physcal
memory usage
 start_memory , end_memory
paremeter
memory_end or high_memory
0x110000 FREE
mem_map
mem_init()
inode_table
inode_init()
device data
device_init()*
0x100000 more pg_tables
paging_init()
0x0A0000 RESERVED
0x060000 FREE
low_memory_start
0x006000 kernel code + data
floppy_track_buffer
bad_pg_table
bad_page
used by page_fault_handlers to kill processes gracefully when out of memory.
0x002000 pg0
the first kernel page table.
0x001000 swapper_pg_dir
the kernel page directory.
0x000000 null page
address
terms
Kernel can’t look page[0]
Relevant routine or variable or explains
Map of physcial memory before any user process are executed