리눅스커널-06

Similar documents
Microsoft PowerPoint - LN_7_Linux_MM.ppt [호환 모드]

Microsoft PowerPoint - o8.pptx

Microsoft PowerPoint - Chapter_03.pptx

untitled

교육지원 IT시스템 선진화

Microsoft PowerPoint - Chapter_02.pptx


06Àå

Sena Technologies, Inc. HelloDevice Super 1.1.0

Embeddedsystem(8).PDF

chap7.key

K&R2 Reference Manual 번역본

Microsoft PowerPoint - lab14.pptx

강의10

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Microsoft PowerPoint - LN_5_Linux_Task.ppt [호환 모드]

PowerPoint 프레젠테이션

13주-14주proc.PDF

BMP 파일 처리

04( ) CSTV15-23.hwp

chap10.PDF

PowerPoint 프레젠테이션

hlogin7

chap8.PDF

본 강의에 들어가기 전

10.

hlogin2

임베디드시스템설계강의자료 6 system call 1/2 (2014 년도 1 학기 ) 김영진 아주대학교전자공학과

Microsoft PowerPoint - Lecture_Note_7.ppt [Compatibility Mode]

Microsoft PowerPoint - chap6 [호환 모드]

PowerPoint 프레젠테이션

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

6주차.key

Chapter #01 Subject

歯9장.PDF

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

vi 사용법

슬라이드 1

PowerPoint 프레젠테이션

Chap06(Interprocess Communication).PDF

Microsoft Word - Network Programming_NewVersion_01_.docx

Microsoft PowerPoint - lab15.pptx

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

C++-¿Ïº®Çؼ³10Àå

Microsoft PowerPoint - IOControl [호환 모드]

<4D F736F F F696E74202D205BBAB0C3B75D20B8AEB4AABDBA20B5F0B9D9C0CCBDBA20B5E5B6F3C0CCB9F620B8F0B5A82E >

Microsoft Word doc

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

untitled

11장 포인터

슬라이드 1

1217 WebTrafMon II

/chroot/lib/ /chroot/etc/

untitled

ECE30076 Embedded System Programming - LED Device Driver

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Xen으로 배우는 가상화 기술의 이해 - CPU 가상화

Microsoft Word - FS_ZigBee_Manual_V1.3.docx

KEY 디바이스 드라이버

03장.스택.key

untitled

untitled

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CBED0C3E0C7C1B7CEB1D7B7A55C D616E2E637070>

歯7장.PDF

슬라이드 1

chap7.PDF

untitled

Microsoft PowerPoint - chap12-고급기능.pptx

歯MW-1000AP_Manual_Kor_HJS.PDF

PowerPoint 프레젠테이션


Microsoft Word - KPMC-400,401 SW 사용 설명서

A Hierarchical Approach to Interactive Motion Editing for Human-like Figures

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2

MPLAB C18 C

2009년 상반기 사업계획

Microsoft PowerPoint - 10-EmbedSW-11-모듈

商用

커알못의 커널 탐방기 이 세상의 모든 커알못을 위해서

Microsoft PowerPoint os9.ppt

학번 : 이름 : 1. 다음파일트리구조를가진유닉스시스템이있다고가정하자. / /bin/ /home/ /home/taesoo/ /usr/ /usr/lib/ /usr/local/lib /media 모든폴더에파일이하나도없다고가정했을때사용자가터미널에서다음 ls 명령입력시화면출력

Microsoft Word doc

2009년 상반기 사업계획

6.24-9년 6월

PowerPoint 프레젠테이션


슬라이드 1

PowerPoint 프레젠테이션

제1장 Unix란 무엇인가?

PowerPoint 프레젠테이션

<4D F736F F F696E74202D FB8DEB8F0B8AE20B8C5C7CE205BC8A3C8AF20B8F0B5E55D>

제1장 Unix란 무엇인가?

C 언어 프로그래밊 과제 풀이

로봇SW교육원 강의자료

Transcription:

C h a p t e r 06

CPU CPU CPU 1MB 600KB 500KB 4GB 512MB 1GB 230

231

Virtual Memory Physical Memory Virtual address Physical address 0 CPU 4GB 3GB 1GB 61 init proc1maps cat 0x08048000 0xC0000000 0x08048000 3GB paging 232

CPU CPU MMUMemory Management Unit MMU 233

taskstruct struct mmstruct mm mmstruct includelinuxschedh struct mm_struct { struct vm_area_struct * mmap; rb_root_t mm_rb; struct vm_area_struct * mmap_cache; pgd_t * pgd; atomic_t mm_users; atomic_t mm_count; int map_count; struct rw_semaphore mmap_sem; spinlock_t page_table_lock; struct list_head mmlist; unsigned long start_code, end_code, start_data, end_data; unsigned long start_brk, brk, start_stack; unsigned long arg_start, arg_end, env_start, env_end; unsigned long rss, total_vm, locked_vm; unsigned long def_flags; unsigned long cpu_vm_mask; unsigned long swap_address; unsigned dumpable:1; mm_context_t context; }; 234

struct vmareastruct mmap vmareastruct vmareastruct mmap 61 vmareastruct vmareastruct includelinuxmmh struct vm_area_struct { struct mm_struct * vm_mm; unsigned long vm_start; unsigned long vm_end; struct vm_area_struct *vm_next; unsigned long vm_flags;... }; vmmm mmstruct vmstart vmend 61 vmflags vmnext vmnext NULL pgdt pgd pgd startcodeendcode 235

startdataenddata BSSBlock Started by Symbol startbrkbrk heap malloc free brk startstack envstartenvendargstartargend 3GB envstart envend argstart argend main env argv argend main sysshmget 62 236

63 237

01 #include<stdio.h> 02 #include<malloc.h> 03 #include<unistd.h> 04 #include<linux/unistd.h> 05 #include<errno.h> 06 #define NR_getvminfo 259 07 int vbss; 08 int vdata=1; 09 10 struct vminfo { 11 unsigned long startcode; 12 unsigned long endcode; 13 unsigned long startdata; 14 unsigned long enddata; 15 unsigned long startbrk; 16 unsigned long brk; 17 unsigned long startstack; 18 }; 19 20 _syscall2(int, getvminfo, int, pid, struct vminfo*, vm) 238

21 22 int main() 23 { 24 25 int i, pid, vstack=2; 26 struct vminfo vm; 27 28 pid = getpid(); 29 i = getvminfo(pid, &vm); 30 31 printf("processs memory information\n"); 32 printf("location of main Function in Code Segment: %p(%lx~%lx)\n",main, vm.startcode, vm.endcode); 33 printf("=============================================\n"); 34 printf("location of Initialied Data in Data Area: %p(%lx~%lx)\n",&vdata, vm.startdata, vm.enddata); 35 printf("=============================================\n"); 36 printf("location of uninitialized Data in BSS Area: %p(%lx~%lx)\n",&vbss, vm.enddata, vm.startbrk); 37 printf("=============================================\n"); 38 printf("stack Location:%p(%lx~)\n",&vstack, vm.startstack); 39 printf("=============================================\n"); 40 41 sbrk(3); 42 char*b = sbrk(0); 43 i = getvminfo(pid, &vm); 44 printf("heap Location:%p(%lx~%lx)\n",b, vm.startbrk, vm.brk); 45 printf("=============================================\n"); 46 return 0; 47 } 239

01 #include <linux/kernel.h> 02 #include <linux/module.h> 03 #include <sys/syscall.h> 04 #include <asm/uaccess.h> 05 #include <linux/mm.h> 06 07 #define NR_getvminfo 259 08 09 asmlinkage int (*saved_entry)(void); 10 extern void *sys_call_table[]; 11 12 struct vminfo { 13 unsigned long startcode; 14 unsigned long endcode; 15 unsigned long startdata; 16 unsigned long enddata; 17 unsigned long startbrk; 18 unsigned long brk; 19 unsigned long startstack; 20 21 }; 22 23 asmlinkage int sys_getvminfo(int pid, struct vminfo *uvm) 24 { 25 26 struct vminfo vm; 27 struct task_struct *t; 240

28 struct mm_struct *mm; 29 30 t = find_task_by_pid(pid); 31 mm = t->active_mm; 32 33 vm.startcode = mm->start_code; 34 vm.endcode = mm->end_code; 35 vm.startdata = mm->start_data; 36 vm.enddata = mm->end_data; 37 vm.startbrk = mm->start_brk; 38 vm.brk = mm->brk; 39 vm.endenv = mm->env_end; 40 vm.startstack = mm->start_stack; 41 42 copy_to_user(uvm, &vm, sizeof(struct vminfo)); 43 return 0; 44 } 45 46 int module_start() 47 { 48 49 saved_entry = sys_call_table[ NR_getvminfo]; 50 sys_call_table[ NR_getvminfo] = sys_getvminfo; 51 return 0; 52 } 53 54 void module_end(void) 55 { 56 sys_call_table[ NR_getvminfo] = saved_entry; 57 } 58 59 module_init(module_start); 60 module_exit(module_end); 61 62 MODULE_LICENSE("GPL"); 241

TARGET = getvminfo INCLUDE = -isystem /usr/src/linux-2.4.32/include CFLAGS = -O2 -D KERNEL -DMODULE $(INCLUDE) //CFLAGS = -O2 $(INCLUDE) CC = gcc ${TARGET}.o: ${TARGET}.c clean: rm -rf ${TARGET}.o #gcc -o app_getvminfo app_getvminfo.c #insmod getvminfo.o #./app_getvminfo 242

243

4GB 4KB 8KB 512MB 512MB4KB 4GB 4KB n n n 244

64Task itask j page table 3 245

65 64 Task i 023 PFNPage Frame Number PPresent 0 1 0 1 2 i1 CPU 32bit 20bit 12bit 246

65 0x100 0x100 2 0000 0000 0000 0000 0000 0001 0000 00002 0 0x100 0 4K0x1000 0x11004KB 0x100 0x1001 0x1001 2 0000 0000 0000 0000 0001 0000 0000 0001220bit 1 P 0 page fault Demand Paging 4GB 4KB 1048756 4byte 4MB 1M 4M 2 3 26 4 247

CPU MMU 2 x86 CPU 80386 8086 protected mode 16bit 16bit 20bit 1MB 80286 8086 real mode 80286 24bit 16bit 16MB selector 24bit base address descriptor table 80286 8086 16bit 64KB 80286 80386 80386 32bit 4GB 8086 CPU 80386 i386 80386 66 MMU 248

1 i386 67 MMU linear address 16bit 32bit 68 TITable Indicator RPLRequested Privilege Level 3 249

64bit 32bit 20bit 4GB GDTGlobal Descriptor Table LDTLocal Descriptor Table GDT GDTR LDT LDTR 2bit DPLDescriptor Privilege Level 03 4 0 3 CPU CPLCurrent Privilege Level RPL CPL DPL CPL 32bit 3 10bit 10bit 12bit 69 250

69 CR3 10bit 03FF 1024 32bit 4byte 4KB 1024 1024 10bit 4KB 1024 251

4KB 12bit 69 12bit 1024 1024 4KB 4GB MMU TLBTranslation Lookaside Buffer TLB TLB TLB 2 610 32bit 0x100 0000 0000 0000 0000 0000 0001 0000 00002 10bit 0000 0000 00 10bit 00 0000 0000 12bit 0001 0000 0000 CR3 CR364KB 64K 10bit 0 0 128K 10bit 10bit 0 0 4K 12bit 252

253

3 i386 Alpha CPU 64bit 2 3 611 26 4 3 2 64bit 32bit i386 2 3 254

i386 3 2 3 pgdtpmdtptet pgdoffset pmdoffset pteoffset CR3 pgdoffset pmdoffset pteoffset pgdoffsetmmaddress pmdoffsetdiraddress pteoffsetdiraddress pgdnonepgdpmdnonepmdptenonex 0 1 255

pgdpresentpgdpmdpresentpmdptepresentpte Present 1 pgdclearpgdpmdclearpmdpteclearpte pgdpagepgd pmdpagepmd ptepagex page 256

01 asmlinkage int sys_getmeminfo(int pid) 02 { 03 struct task_struct *t; 04 struct mm_struct *mm; 05 struct vm_area_struct *mmap; 06 struct file *file; 07 08 char *filename; 09 char *buf; 10 11 t = find_task_by_pid(pid); 12 mm = t->active_mm; 13 mmap = mm->mmap; 14 buf = (char*)kmalloc( 512, GFP_KERNEL); 15 16 while(mmap) { 17 printk("%08lx - %08lx", mmap->vm_start, mmap->vm_end ); 18 file = mmap->vm_file; 19 if(file){ 20 filename = d_path(file->f_dentry, file->f_vfsmnt, buf, 512); 21 printk("%s \n", filename ); 22 } 23 else{ 24 printk("\n"); 25 } 26 mmap = mmap->vm_next; 27 } 28 return 0; 29 } 257

01 /* app_displaymeminfo.c */ 02... 03 #define NR_getmeminfo 258 04 _syscall1(int, getmeminfo, int, pid) 05 06 int main(int argc, int *argv[]) 07 { 08 int i, pid; 09 10 pid = atoi(argv[1]); 11 i = getmeminfo(pid); 12 } TARGET = getmeminfo INCLUDE = -isystem /usr/src/linux-2.4.32/include CFLAGS = -O2 -D KERNEL -DMODULE $(INCLUDE) //CFLAGS = -O2 $(INCLUDE) CC = gcc ${TARGET}.o: ${TARGET}.c 258

clean: rm -rf ${TARGET}.o #gcc -o app_displaymeminfo app_displaymeminfo.c #insmod getmeminfo.o #./app_displaymeminfo 259

613 cat procslabinfo gfpmask allocpagesgfpmaskorder 2 order page 260

allocpagegfpmask allocpages order 0 getfreepagesgfpmaskorder 2 order getfreepagegfpmask getzeroedpagegfpmask 0 getdmapagesgfpmaskorder DMA getfreepages gfpmask GFPDMA kmallocsizeflags size vmallocsize size freepagespageorder 2 order freepagesaddrorder 2 order freepagepage freepageaddr kfreeobjp kmalloc vfreeaddr vmalloc 261

FIFOOPTOptimal Page replacementlru Least Recently UsedLFULeast Frequently UsedMFUMost Frequently Used FIFO OPT LFU MFU LRU LRU LRU LRU LRU LRU LRU LRU Approximation Page Replacement Accessed Dirty 262

614 kswapd kswapd 615 kswapdinit kswapdcansleep kswapdbalance 263

kswapdbalance kswapdbalancepgdat trytofreepageszone shrinkcaches LRU activelist inactivelist swapouttrytofreepageszone 616 trytoswap out 1 0 616 swapout mmstruct swapoutvma swapoutpgd swapoutpmd trytoswapout 264

1 2 3 4 5 6 7 265

1 2 266