728x90
- 실행된 프로그램은 메모리에 적재됨
- 메모리에 적재되는 데이터 : 명령어, parameter, parameter가 저장된 주소
- 메모리가 처리하는 data stream
- read : address
- write : address + data
- 보통 레지스터 접근은 1 clock 내에 처리
- 메모리 접근은 레지스터 대비 긴 시간이 걸리기 때문에, 중간에 캐시 메모리를 이용하여 병목 현상을 보완
- 메모리 보호
- 프로세스가 접근 가능한 주소에 제한
- ex. 프로세스 할당 시 주소(base) 레지스터와 함께 할당 공간의 제한(limit) 레지스터를 같이 할당
- base 아래 혹은 base + limit 위의 주소 접근 시 인터럽트를 호출하여 process 삭제
Address Binding
- 프로그램 생성마다의 address binding 단계
- 소스 코드 : 변수 주소를 symbolic하게 표현
- 컴파일된 코드는 주소를 relocatable address로 bind
- relocatable addreess : 프로그램 시작 지점에서의 상대적 offset 주소
- 링커 / 로더 : 메모리에 적재된 프로그램에 실제 주소 할당
- 주소가 결정되는 단계
- compile time : 만약 이 단계에서 static한 주소 명시가 된 경우 compile 단계에서 주소 할당
- Load time : compile time에서 할당되지 않은 주소를 relocatable address로 할당
- Execution time : 실행 중 새롭게 할당되는 주소 관리
MMU(Memory-Management Unit)
- Logical Address : 프로세스가 바라보는 주소, 가상 주소라고도 함
- Physical Address : 메모리상의 실제 주소
- CPU에서 명령 수행 시 logical address에 접근
- MMU에서 logical address-physical address를 변환
- simple scheme
- MMU에는 relocation register에 값이 할당
- CPU에서 logical address 접근 시, relocation register 값만큼 offset을 주어 physical address에 접근하게 함
- ex. relocation register에 10000이 저장, CPU에서 ld 365 명령 실행 시 실제로는 10365 주소의 메모리에 접근
- dynamic relocation : 만약 해당 주소에 접근 불가할 경우 relocation register 값을 변경
- static linking
- binary 코드 생성 시 라이브러리를 모두 포함
- 프로그램이 무거워지고, 라이브러리가 중복 사용되는 경우 메모리 비효율성
- Dynamic Linking
- 중복 사용되는 라이브러리는 메모리에 미리 적재
- 해당 라이브러리를 사용하는 프로세스는 필요할 때마다 별도로 호출
- stub : Dynmic link를 찾는 루틴
Variable Partition
- hole : 가능한 메모리 블럭
- 프로세스를 단순히 연속 할당 시 메모리 관리가 비효율적이 될 수 있음
- Dynamic Storage Allocation
- First fit : 할당 가능한 첫번째 hole에 프로세스 할당
- Best fit : 할당 가능한 최적의 hole에 프로세스 할당
- Worst fit : 가장 큰 hole에 프로세스 할당
- Fragmentation : 할당으로 인해 생기는 메모리 비효율
- external fragmentation : 전체 메모리 여유 공간은 충분하나, 연속적이지 않아 할당이 불가능한 경우
- internal fragmentation : 요청받은 프로세스 크기보다 할당 공간이 약간 큰 경우, 메모리 차이만큼의 공간은 너무 작아서 활용이 불가능
- 50% rule : 메모리를 N개 block으로 할당한다고 할 때, 절반 가량은 fragmentation에 의해 사용 불가
- Compactation : external fragmentation의 제거
- 모든 hole을 하나의 공간으로 합침
- relocation이 동적일 때, excution time에 동작함
Segmentation
- 메모리를 segment라는 논리적 단위로 할당
- segmentation 구조 : <segment-number, offset>
- segment table : 각 segment의 base, limit 주소를 저장, segment number로 접근
- base : segment의 시작 주소
- limit : segment의 길이, 이 주소를 초과하여 접근시 error
- segment table : 각 segment의 base, limit 주소를 저장, segment number로 접근
- segment number(s)는 segment table로 접근
- offset은 segmnet table의 limit과 비교
- limit 초과 시 addressing error
- segment table의 base와 offset이 합쳐져 실제 메모리로 접근하게 됨
Paging
- 메모리의 주소를 고정 크기로 나누어 할당하는 것
- 연속적 할당이 아니므로 fragmentation 문제가 없음
- frame : 물리적 메모리에 접근하는 block 단위
- page : 가상의 메모리에 접근하는 block 단위
- page 요청 > frame 요청 > OS는 빈 frame를 찾아 할당
- addresss translation
- CPU에 의해 생성되는 주소는 page number / offset으로 구분
- page number : page table에 접근하기 위한 index >> frame number를 탐색하여 page offset과 조합
- page offset : 실제 메모리 주소에 접근하기 위해 사용
- page size를 4kb(2^12)라 가정
- 32bit system에서 page offset d = 12가 되고, page number p = 20이 됨
- CPU가 logical 접근
- page table에 p index 값을 접근, 해당 값을 frame에 전달
- offset d만큼의 주소를 더해 접근
- frame offset d만큼의 주소를 더해 메모리 접근
- internal fragmentation = page size - page 할당 후 남는 크기만큼
- worst fragmentation = 1 frame - 1 byte
- average fragmentation = frame size * 0.5
- Page table
- page table base register(PTBR) : page table 위치를 가리킴
- page table length register(PTLR) : page table의 크기를 나타냄
- TLB(Transition look-aside buffer)
- CPU에서 메모리 접근 시 page table을 거치기 때문에 속도 문제가 발생
- associative memory라고도 하며, 논리 - 물리 메모리 주소의 변환 결과를 미리 저장
- TLB에 데이터 존재시(hit) 메모리 접근, 없을 경우 page table 접근
- Effective Access TIme(EAT)
- hit ratio : TLB에서 데이터를 찾아올 수 있는 비율 (ex. hit ratio 80% : 100번 탐색 중 80번은 TLB로 접근)
- EAT = hit ratio * TLB access time + (1 - hit ratio) * memory access time
- memory protection
- page table에 read/write bit를 설정하여 프로세스 접근 시 읽기/쓰기 가능 여부를 설정
- valid-invalid : 페이지가 프로세스의 주소 공간에 할당되었는지 여부를 확인
Page Table Structure
- hirearchial page table
- page table 탐색의 overhead 감소
- page table의 page table을 구성
- logical address는 inner page + outer page + offset과 같이 구성
- hased page table
- page table을 hash table로 구성
- inverted page table
- 논리 주소가 아닌 물리적 주소로 page table 구성
- virtual address를 이용하여 shared page 구현
Swapping
- 사용되지 않는 프로세스를 보조 저장장치에 저장하여 메모리를 관리
- context switching time = 전송 시각 * process 크기 * 2
728x90