Unix / Linux

[ Unix / Linux ] Memory Management Requirement

개발여우 2010. 4. 5. 22:03
 # Memory management issues
 1. placement
 2. protection
 3. replacement
 4. relocation
 5. on-demand loading

 # Classical management schemes
 1. Manage main memory directily ( physical memory ) - 물리메모리 접근
 2. Single programming system - 한순간 1개의 Task만 수행
 3. Fixed partition multiprogramming system - 멀티태스킹 ( 고정 파티션 )
 4. Variable partition multiprogramming system - 멀티태스킹 ( 가변 파티션 )

 ㄱ.단편화
  1)internal fragmentation - 내부단편화   
   - task가 중간에 종료될시 빈공간에 task를 넣어주는 것
  2)external fragmentation - 외부 단편화
   - task가 중간에 종료될 시 아래 넓은 곳에 task를 넣어주는것

 ㄴ.Policies
  1)first-fit
  2)best-fit
  3)worst-fit

  4)coalescing
  5)compaction
  6)overlay

# Virtual memory - 가상메모리
  정의 - Abstract a user perceived virtual memory from a physical memory
  장점 - Supprt larger address space than the equipped main memory
           ON-demand loading

  ㄱ.Type
   1)paging system : fixed size
   2)Segmentation system : variable size
  
  ㄴ.Terms - 32bit 컴으로 가정
   1)virtual memory - programmer's view
   2)physical memory - system's view
  
   virtual memory는 4GB까지 32비트 컴퓨터는 지원한다
 text ( code & 함수 ), data ( 전역변수 ), heap ( 동적할당), stack( 함수인자, 지역변수 ), 3GB~4GB는 커널



  ㄷ.Paging system
   Physical memory : a collection of page frames ( usually 4KB )
   Virtual memory : a collection of pages ( usually 4KB )
  물리 메모리의 기본 단위를 page frame, 가상 메모리의 기본 단위를 page라고 한다!!

  ㄹ.Virtual memory and program image
   ELF : Executable and Linkage Format - a.out
  phdrs - 헤더,  virtual memory 의 영역들은 단위로쪼개4KB 져 binary iamge로 Disk에 작성됨

  virtual memory 는 개념적 존재
 a.out이라는 응용프로그램을 수행 시킨다고 가정할때 text영역은 12KB, data영역은 8KB, stack은 4KB라고 가정하고
 malloc을 사용하지 않을때 

 text영역은 3개의 page frame으로 나뉘고 data영역은 2개, stack 영역은 1개로 저장된다.
 a.out이 수행되려면 디스크에서 메모리로 이동됭야 함 (loading)

 디스크의 내용을물리메모리에로딩   (loading)하면서 위치 정보를 기록하는데
 page table까지 만들어지면 수행가능하다
 page 와 page frame을 연결하는 매개체!

* 가상 메모리 접근 예제
 1)1000번지에 접근하면?
    page를 거쳐 page frame으로 접근 할때 page frame은 4KB단위로 접근하므로 page table에서 첫번째 page 에들어있는 
  t0에 접근하게 되고 t0에 해당하는 pf2 (page frame)으로 연결되어 physical memory 의 물리주소에 접근
  pf2가 8KB위치에 있으므로 그곳에서 1000을더해주면된다 8KB + 1000
  
 2)5000번지에 접근하면?
   역시 page 를 거쳐 page frame에 접근 하려하는데 5000은 4096 ( 4KB )으로 나눠서 바로 2번째 page에 접근함을
 알수 있습니다  2번째 page는 t1을 가리키고 있고 이에 해당하는 pf4의 물리주소로 찾아가게 되면 16KB에 위치함을
 알게 되고 이에따라 16KB + 904 (나머지)

 3)9000번지에 접근하면?
   위문제와 동일하게 접근가능하나 문제는 page에 가리키고있는 page frame이 없다는 사실이다.
   이것을 page fault 라고 한다

*Page fault handling - 프로그램 실행중에 요청이 있을때 로딩하는 기술
 - 위 3번 문제의 해결책으로 나온것인다 page frame을 요청이 있을시 할당하고 다시 수행시키는 방법
 task_struct 마다 page table을 가지고 있는데 이곳으로 page table 을 접근하고 빈곳에 접근하는데
 page fault발생할시 그때 disk와 page frame을 연결하고 다시 수행한다

4장 Memory management - p14까지