Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Memory Management 1. Readings r Silbershatz et al: chapters 8.1-8.3 2.

Similar presentations


Presentation on theme: "Basic Memory Management 1. Readings r Silbershatz et al: chapters 8.1-8.3 2."— Presentation transcript:

1 Basic Memory Management 1

2 Readings r Silbershatz et al: chapters 8.1-8.3 2

3 Outline r Memory Hierarchy r Memory management requirements r Basic memory management r Fixed Partitions r Dynamic Partitions 3

4 Introduction r Our machines today have 10,000 times more memory than the IBM 7094 – leading edge machine of the 1960’s r Cost of memory has dropped dramatically r Bill Gates (former chair of Microsoft) once said “640K should be enough” 4

5 Introduction r Software tends to expand to fill the memory available r Technology does not allow for each program to have infinitely large and fast memory r Operating systems must manage memory 5

6 Instruction-Execution Cycle r You can think of memory as a large array of bytes m Each byte has its own address r Fetch an instruction from memory r Instruction is decoded m May cause operands to be fetched from memory r After instruction execution m Results may be stored back in memory r Each of these operations require memory addresses 6

7 Registers On-chip Cache Main Memory Magnetic (Hard) Disk Memory Hierarchy r Registers built into the CPU are generally accessible within one cycle of the CPU clock r Completing a memory access may take many cycles of the CPU clock 7

8 Memory Hierarchy r A processor waiting for data from main memory is not desired r Remedy: Add fast memory between the CPU and main memory called a cache 8

9 Address Binding r Program execution requires that a program be brought into memory from the disk r The process can reside in any part of the physical memory r Address space starts at 00000 but the first address of a user need not be 00000 9

10 Address Binding r Addresses in source program are generally symbolic e.g., count r Compiler will bind these symbolic addresses to relocatable addresses m Example: “14 bytes from the beginning of this module” r Binding to physical addresses is typically delayed until run-time 10

11 Address Binding r Programmer does not know where the program will be placed in memory when it is executed r While the program is executing, it may be placed in disk and returned to main memory at a different location (swapping) r Memory references in the code (virtual or logical) must be translated to actual physical memory addresses r Run-time Mapping from virtual to physical addresses is done by a hardware device called the memory-management unit (MMU) 11

12 Simple MMU r Simple mapping r Relocation register: Value is added to every address generated by a user process 12

13 Contiguous Memory Allocation r We will start out with the most basic method used that allows multiple processes to reside in memory r With contiguous memory allocation each process is contained in a single section of memory that is contiguous 13

14 Fixed Partitioning r Main memory use is inefficient. r Any program, no matter how small, occupies an entire partition. m This is internal fragmentation. 8 M Operating System 14

15 Fixed Partitioning r Unequal-size partitions m Lessens the problem with equal-size partitions Operating System 8 M 12 M 8 M 6 M 4 M 2 M 15

16 Placement Algorithm with Partitions r Equal-size partitions m Since all partitions are of equal size, it does not matter which partition is used r Unequal-size partitions m Each process can be assigned to the smallest partition within which it will fit 16

17 One Process Queue per Partition New Processes Operating System 17

18 One Common Process Queue r When its time to load a process into main memory the smallest available partition that will hold the process is selected Operating System New Processes 18

19 Questions r Single Queue: m What is the problem with taking the first job that fits into the partition? m What is the problem with taking the largest job that fits into the partition? r Multiple Queues: m What is the disadvantage? 19

20 Multiprogramming with Fixed Partitions r Was used by OS/360 on large IBM mainframes for many years r Incoming jobs were queued until a suitable partition was available r Today no modern OS uses fixed partitions 20

21 Dynamic Partitioning r Partitions are of variable length and number r Process is allocated exactly as much memory as required r Eventually get holes in the memory. This is called external fragmentation r Compaction is required to obtain a large block at the end of memory m Shift processes so they are contiguous and all free memory is in one block 21

22 Example Dynamic Partitioning Operating System Process 1 320 K Process 2 Process 3 224 K 288 K 64 K Operating System Process 1 320 K Process 3 224 K 288 K 64 K Operating System Process 1 320 K Process 3288 K 64 K Process 4 128 K 96 K 22

23 Example Dynamic Partitioning Operating System 320 K Process 3288 K 64 K Process 4 128 K 96 K Operating System Process 3288 K 64 K Process 4 128 K 96 K Process 2224 k 96 K 23

24 Dynamic Partitioning Placement Algorithm r Operating system must decide which free block to allocate to a process r Best-fit algorithm m Choose the block that is closest in size to the request m This has the worst overall performance m The smallest block is found for a process The smallest amount of fragmentation is left; Memory compaction must be done more often 24

25 Dynamic Partitioning Placement Algorithm r First-fit algorithm m Starts scanning memory from the beginning and chooses the first available block that is large enough. r Next-fit m Starts scanning memory from the location of the last placement and chooses the next available block that is large enough 25

26 Summary r This section studied basic memory allocation techniques 26


Download ppt "Basic Memory Management 1. Readings r Silbershatz et al: chapters 8.1-8.3 2."

Similar presentations


Ads by Google