15
Linux Memory Management Initialization

Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Embed Size (px)

Citation preview

Page 1: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Linux Memory Management

Initialization

Page 2: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Some concept Address translation -logical address User space vs Kernel space

- linear address 0~4GB (x86) ie.Alpha 2^64 byte

- physical address ie: logical linear physical

User view

Physicalsituation

Page 3: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

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 decide a segment descriptor in LDT/GDT

Page 4: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

selector

Seg descriptor ,,

,,

Seg descriptor

GDTR

LDTR

memory

base limit

CS /DS

offsetEIP

LDT[0]=nullLDT[1]=user code seg descriptorLDT{2]=user data seg descriptor

GDT[0]=nullGDT[1]=kernel code seg descriptorGDT[1]=kernel data

logical

Page 5: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Logicasl address to Linear adderss - user space segment descriptor=(0 ,0xc0000000) Task_size 變數 = 0xc00000000

linear address=0x000000000xc00000000

- kernel space : segment descriptor=(0xc0000000,4GB) linear address=3GB4GB

Page 6: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Task

3GB

4GB

0GB

Linear address

Userspace

KernelSpace

Segmenthardware

Logical address

Page 7: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Linear to Physical - paging hardware mechanisinm - x86 is two layer

DIR TABLE OFFSET

10bit 10bit 12bit

Page 8: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Physcial memory

Linear address

DIR TABLE

page

table

directoryindex

Dir base

index

pageindex

Page hardware

Page 9: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

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

Page 10: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

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

Page 11: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

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)

Page 12: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

Memory initialization arch/i386/kernel/HEAD.S int/main.c start_kernel() { . . paging_init(); call free_area_init() . mem_init(); . . }

Page 13: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

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

Page 14: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

- mem_init() contruct the mem_map in the memory to reflect the physcal memory usage start_memory , end_memory paremeter

Page 15: Linux Memory Management Initialization. Some concept Address translation -logical address User space vs Kernel space - linear address 0~4GB (x86) ie.Alpha

0x110000 FREE memory_end or high_memory

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

Map of physcial memory before any user process are executed

address terms Relevant routine or variable or explains

Kernel can’t look page[0]