470 likes | 821 Views
Memory Management. Memory or Storage. Real Memory physical main memory Virtual Memory storage conceived by users. Problem of Memory Management (1). How many jobs in memory at one time programs or processes Storage amount per job same size different size.
E N D
Memory Management SunMoon University
Memory or Storage • Real Memory • physical main memory • Virtual Memory • storage conceived by users SunMoon University
Problem of Memory Management(1) • How many jobs in memory at one time • programs or processes • Storage amount per job • same size • different size SunMoon University
Problem of Memory Management(2) • Location to run a job • Fixed absolute binding and loading • Variable relocate binding and loading • binding • loading • linking • compiler SunMoon University
주소 번역 j int tiger; int lion; int cat; int dog; main() { L1: tiger++; lion++; goto L1; } main: mov ax, bx mov cx, dx L1: mov ax, tiger add ax mov _tiger, ax mov bx, _lion add bx mov _lion, bx goto L1 end 1011 1110 1111 1011 1110 1000 1110 1000 1110 1101 1000 1111 1101 (D) Text Load Data (A) C source program (C)binary code Stack (B) 가상 assembly program SunMoon University
Instruction Cycle Address … … 104 108 … … C P U Main : … … mov a1, b1 mov a2, b2 … … P C 104 108 I R Mov a1, b1 Mov a2, b2 < Assembly file> SunMoon University
Instruction Cycle j (D) (A) (B) < Memory > SunMoon University
OSvs.Compilervs.Loader u Compiler Loader OS Memory Manager Kernel OS XXXX (C)binary code 적재 (C)binary code (A) C source program (B) assembly program < Memory > < H/D > 적재될 Memory 주소 XXXX가 어느곳인가? SunMoon University
적재할 메모리 주소를 알고 있는 경우 n Compiler Loader (A) (D) Compiler가 OS의 Memory 관리자로부터 메모리에 적재할 주소(ex)1000번지)를 미리 통보 받아 알고 있다. 컴파일러가 직접 메모리상의 주소를 생성 로더는 단순 적재(Absolute loader) SunMoon University < Memory >
적재할 메모리 주소를 모르는 경우1 g Compiler는 가상의 주소(ex) 0번지)에 적재된다고 가정하고 주소 생성 Loader가 적재되는 시점에 OS로부터 가용한 메모리 주소(ex)3500번지)를 통보 받는다. Loader는 새로운 주소로 바꾸고 (Relocatable Loader)적재한다. SunMoon University
적재할 메모리 주소를 모르는 경우2 g 컴파일러는 X(0번지)에서 시작하는것으로 생각하고 주소를 생성한다. 실제 주소는 X에서 3500을 더한다. X main: mov ax, bx mov cx, dx L1: mov ax, tiger add ax mov _tiger, ax mov bx, _lion add bx mov _lion, bx goto L1 end Compiler Loader 새로운 주소로 바꾼다. (A) (D) SunMoon University < Memory >
Problem of Memory Management(3) • Memory Partition Method • Static (fixed) binding • Dynamic(variable) binding • Placement Method for a job • Contiguous • Noncontiguous SunMoon University
Storage Hierarchy • Cache memory • Associative memory • RAM(Random Access Memory) • Hard Disk • etc. • Dfigure 7.1 SunMoon University
Memory Management Strategies(1) • Obtaining the best possible use of main memory resources 1. Fetch Strategies 2. Placement Strategies 3. Replacement Startegies SunMoon University
Fetch Strategies • Definition : • when to obtain the next piece of program or data to transfer from secondary storage to main memory • Demand Fetch • when it is referenced by a running program • Anticipatory Fetch • improve system performance SunMoon University
Placement Strategies • Definition • where in main memory to place an incoming program • First-fit • Best-fit • Worst-fit SunMoon University
Replacement Strategies • Definition : • which piece of program or data to displace to make room for incoming program • FiFO, LRU, … • vs.) swapping • develop to ‘paging’ or ‘segmentation’ SunMoon University
Storage Allocation • Contiguous Storage Allocation • easy • Noncontiguous Storage Allocation • partition a program into several block or segment • efficient SunMoon University
Single User Allocation(1) • Single user • Dfigure 7.2 • Waste resources • Size of program < size of memory • overlay • main memory 보다 큰 size의 프로그램을 실행시킨다. • Dfigure 7.3 • develop to “Virtual Memory” SunMoon University
Single User Allocation(2) • Protection • protection for OS : no protection in XT, AT • boundary register • whenever program reference the main memory • supervisor call • Dfigure 7.4 SunMoon University
Fixed Partition Multiprogramming(1) • In general, more memory than single user system • CPU utilization on a single user system • better utilization of the CPU • Dfigure 7.5 • Definition : • devide main memory into fixed size partition • each partition has a single job SunMoon University
Fixed Partition Multiprogramming(2) • Absolute loader • Absolute translation and loading • Dfigure 7.6/7.7 • Assign the job to a special partition • Storage waste • Wait a job when the other partition are available • Easy SunMoon University
Fixed Partition Multiprogramming(3) • Relocatable loader • relocatable translation and loading • assign a job to any available partition • Dfigure 7.8 • Protection in multiprogramming • Use several boundary register • Dfigure 7.9 • Fragmentation in fixed partition multiprogramming • Unused space in each partition SunMoon University
Variable Partition Multiprogramming(1) • Minimize fragmentation • No fixed boundary • Contiguous allocation of each job • Partition of each job • Size of partition • No fragmentation in a partition • “hole” • 그림 7.7/7.8/7.10 SunMoon University
Variable Partition Multiprogramming(2) • Solution of fragmentation • Coalescing holes(통합) • borders on other free storage areas • Storage Compaction(집약) • garbage collection • 그림 7.11 / 7.12 • problem • consume system resource(CPU time) • system must stop everything • Interactive , real-time , etc. • relocated once more SunMoon University
Placement Strategies • Dfigure 7.14 • Best-fit • First-fit • Worst-fit SunMoon University