Presentation is loading. Please wait.

Presentation is loading. Please wait.

Memory management Igor Radovanović.

Similar presentations


Presentation on theme: "Memory management Igor Radovanović."— Presentation transcript:

1 Memory management Igor Radovanović

2 Quiz about an Operating system
What is an OS? What is an OS composed of? Why does anyone need an OS? When is an OS efficient? Why are some OS popular and some not? If you are to develop an OS, what must you make sure before you can expect that it can be widely used? 30/11/2018

3 … … … REMINDER: OS provides abstract machines Abstract Machines Idea
Analogy: car driving Idea Result Program Physical Machine Idea Program Result Idea Simplicity-flexibility tradeoff (teller machine) Program Result 30/11/2018

4 REMINDER: OS as resource manager
Process: An executing program Resource: Anything that is needed for a process to run Memory Space on a disk The CPU “An OS creates resource abstractions” “An OS manages resource sharing” 30/11/2018

5 REMINDER: Resource sharing
Space- vs. time-multiplexed sharing To control sharing, must be able to isolate resources OS usually provides mechanism to isolate, then selectively allows sharing How to isolate resources? How to be sure that sharing is acceptable? Concurrency Appearance True concurrency 30/11/2018

6 REMINDER: Logical OS Organization
Process, thread and resource manager File manager Network manager Memory manager Device manager Processor(s) Main memory Devices All modules coordinate Examples: in Virtual Memory PM –MM to coordinate scheduling activity with memory allocation For performance improvement: FM –DM & FM-MM Information from storage device read prior to its being requested by a thread 30/11/2018

7 Memory manager functionalities
Today’s memory manager: Supports multiprogramming by allocating memory space to many processes simultaneously Resource manager for the spaced-multiplexed main memory Robust isolation mechanism to protect process’s allocated memory Ability for processes to share parts of allocated memory Ideally: Keeps programs and data in main memory ONLY while they are being used by CPU Restore the info to secondary memory soon after it has been created Automatically move information back and forth between the primary and secondary memory Virtual memory abstraction 30/11/2018

8 Memory manager functionalities (cnt’d)
Classic memory managers Abstraction Main memory appears to be larger than the physical machine mem. Memory as a large array of contiguously addressed bytes Abstract set of addresses to reference physical primary memory Allocation Allocate primary memory to processes as requested Isolation Exclusive use of memory by processes Sharing Two types: Main memory shared by many processes Block of primary memory shared by many processes 30/11/2018

9 Memory manager non-functional requirements
Performance requirements Minimize main memory access time Maximize main memory size Main memory must be cost-effective 30/11/2018

10 Storage Hierarchies Analogy with the office storage hierarchy
Worker’s desktop File folder File cabinet Warehouse Upper-layers: info more frequently used Lower layers: info less frequently used Less Frequently Used Information More Frequently Used Information 30/11/2018

11 Memory Hierarchy (cnt’d)
CPU register memory fast access (1 clk cycle) but limited in size Primary (executable memory) direct access (a few clk cycles), relatively large, access time is of less importance Secondary memory (storage devices) I/O operations required for access, very large, data stored for longer period of time, access speed is slow (3 orders of a magnitude than the CPU register memory) CPU Registers Less Frequently Used Information Primary Memory (Main Memory) e.g. RAM More Frequently Used Information Secondary Memory e.g. Disk or Tape 30/11/2018

12 Contemporary Memory Hierarchy & Dynamic Loading
\ CPU Registers L1 Cache Memory (Executable) Primary L2 Cache Memory “Main” Memory Rotating Magnetic Memory Larger storage Faster access Optical Memory Secondary Sequentially Accessed Memory 30/11/2018

13 Exploiting the Hierarchy
Upward moves are (usually) copy operations Require allocation in upper memory Image exists in both higher & lower memories Updates are first applied to upper memory Downward move is (usually) destructive Destroy image in upper memory Update image in lower memory Place frequently-used info high and infrequently-used info low in the hierarchy Reconfigure as process changes phases (process switch) 30/11/2018

14 The Address Space Abstraction
Instead of a set of physical, processes are allocated a set of logical primary memory addresses (process address space) Memory manager has to bind logical primary memory addresses to physical primary memory address Hardware Main (Primary) Memory Process Address Space 30/11/2018

15 Virtual and Physical address
Decouple addresses (names) used by a process to identify objects from addresses used by memory to identify storage locations Objects in different processes can have the same name (address), but, must be stored at different locations Process A 0=Δ =◊ =□ Process B Δ ◊ □ Δ ◊ □ processor memory address (name) object 30/11/2018

16 Managing the address space
Compile time Isolated addresses of relocatable object modules Link time Addresses of the absolute module stored in the file in the secondary memory Program instructions Data Stack Load time Binding logical to physical addresses Static binding Source code Symbolic addresses (count) Library code Other objects C Secondary memory Absolute address Link Edit Reloc Object code Primary memory Relative address Process address space Loader 30/11/2018

17 Early systems Single-user configuration Fixed partitions
Dynamic partitions Relocatable Dynamic partitions 30/11/2018

18 Single-user configuration
Each program loaded in its entirety into memory and allocated as much contiguous memory space as needed if a program does not fit the memory it cannot be executed Hardware needed register to store base address accumulator to track size of program as it is loaded into memory (limit) Once in main memory, program stays there until the end of execution No multiprogramming supported 30/11/2018

19 Early systems Single-user configuration Fixed partitions
Dynamic partitions Relocatable Dynamic partitions 30/11/2018

20 Fixed partitions Advantage: Disadvantage: Design issue: Partition size
attempt at multiprogramming using fixed partitions 1 process per partition Issue: protection of the task’s memory space Disadvantage: entire program was stored contiguously in memory during entire execution Problem: Internal fragmentation Design issue: Partition size Choosing the right partition size was a problem Too small – long turnaround time Too big – wasted memory Partition allocation: first-fit 30/11/2018

21 Fixed partition -an example-
Process List : P1 30K P2 50K P3 30K P4 25K Conclusion: Process 3 has to wait even though 70K of free space is available After Process Entry Process 1 (30K) Partition 1 Process 4 (25K) Partition 2 Partition 3 Process 2 (50K) Partition 4 wasted memory Original State 100K Partition 1 25K Partition 2 25K Partition 3 50K Partition 4 30/11/2018

22 Early systems Single-user configuration Fixed partitions
Dynamic partitions allocation deallocation Relocatable Dynamic partitions 30/11/2018

23 Dynamic partitions Partition size not fixed but determined based on the size of a process Advantage: less memory waste Disadvantages: Memory waste not solved completely Performance deteriorates as new processes enter the system External fragmentation Programs still have to be stored contiguously 30/11/2018

24 Dynamic partitions -an example-
First-fit allocation scheme Conclusion: Job 8 has to wait even though there is 35K of free memory space available 30/11/2018

25 Dynamic partition -allocation schemes-
Allocation schemes issues: decrease time, increase utilization First-fit Allocate the first partition that is big enough Advantage: Faster in making the allocation Disadvantage: Waste of memory Best-fit The smallest partition fitting the requirements Advantages: Produces the smallest leftover partition Makes best use of memory Takes more time Analogy: lending library Q: How to organize free/busy list in both cases? 30/11/2018

26 First-fit allocation -an example-
P1 10K P2 20K P3 30K* P4 10K Memory Memory Process Process Internal location block size number size Status fragmentation K P K Busy K K P K Busy K K P K Busy K K Free Total Available:115K Total Used: 40K location organization 30/11/2018

27 Best-fit allocation -an example-
P1 10K P2 20K P3 30K P4 10K Memory Memory Process Process Internal location block size number size Status fragmentation K P K Busy K K P K Busy None K P K Busy None K P K Busy K Total Available: 115K Total Used: 70K size organization 30/11/2018

28 Smaller free space - sliver -
Exercise It is required to put a process that occupies 200 spaces in the memory. The table of free memory spaces is given below. Show how this table will look like after allocating 200 spaces using the best-fit algorithm. Smaller free space sliver - 30/11/2018

29 Best-Fit vs. First-Fit First-Fit Best-Fit Next-fit
Increases memory use Memory allocation takes less time Reduces internal fragmentation Memory waste not solved Best-Fit Worse memory utilization than First-it Results in a smaller “free” space (sliver) Memory waste not solved More complex algorithm Searches entire table before allocating memory Other allocation schemes: Worst-fit Next-fit Slightly worse memory utilization than First-Fit 30/11/2018

30 Early systems Single-user configuration Fixed partitions
Dynamic partitions allocation deallocation Relocatable Dynamic partitions 30/11/2018

31 Release of memory space -deallocation-
Deallocation for fixed partitions is simple Memory Manager resets status of memory block to “free”. Deallocation for dynamic partitions tries to combine free areas of memory whenever possible Is the block adjacent to another free block? If yes, combine the 2 blocks Is the block between 2 free blocks? If yes, combine those 3 blocks Is the block isolated from other free blocks? If yes, put it in the table entry 30/11/2018

32 Deallocation -an example-
30/11/2018

33 Early systems Single-user configuration Fixed partitions
Dynamic partitions Relocatable Dynamic partitions 30/11/2018

34 Relocatable Dynamic partitions
Solves problem of both internal and external fragmentation Compaction and reallocation (increased throughput) no memory waste Memory Manager relocates programs to gather all empty blocks and compact them to make 1 memory block Memory compaction (garbage collection, defragmentation) performed by OS to reclaim fragmented sections of memory space 30/11/2018

35 Compaction Steps Relocate every program in memory so they’re contiguous Adjust every address, and every reference to an address, within each program to account for program’s new location in memory Must leave alone all other values within the program (e.g., data values) Q: When should compaction be done? When a certain percent of memory becomes busy (e.g. 75%), When there are processes pending, or After a prescribed amount of time Note: Compaction cannot be done if the relocation is static 30/11/2018

36 Compaction -an example-
Memory before and after compaction 30/11/2018

37 Memory compaction (cnt’d)
2 3 3 2 3 2 2 3 4 5 11 11 2 5 20 5 5 5 9 9 9 (a) (b) (c) (d) (a) initial state; (b) complete compaction (c) partial compaction; (d) minimal data movement 30/11/2018

38 Memory compaction (cnt’d)
Schemes are very costly Require each word of memory to be read from and written into memory May take several seconds Few contemporary systems implement memory compaction 30/11/2018

39 Relocation Introduces overhead Q:
Who keeps track of how each job has moved from its original storage area? What lists have to be updated? A: Special-purpose registers Bounds register Stores highest (or lowest) location of memory accessible by each program Relocation register Contains value to be added to each address referenced in the program Both free and the busy lists are updated 30/11/2018

40 Relocation -an example-
Job loaded into memory location 30K (30720) It requires memory block of 32K (32768) At memory location an instruction: LOAD 4, ANSWER Answer is the value 37 30/11/2018

41 Conclusions Single-user configuration Fixed partitions
Dynamic partitions Relocatable Dynamic partitions Comments: All require that the entire program be loaded into memory be stored contiguously remain in memory until a process is completed Severe restrictions to the process size 30/11/2018


Download ppt "Memory management Igor Radovanović."

Similar presentations


Ads by Google