OS_Lecture4_VU_Final.pptx
Document Details
Uploaded by Deleted User
NSBM Green University
Tags
Related
- Operating Systems Memory Management PDF
- Artificial Intelligence & Data Science S.E. Operating Systems Past Paper PDF - 2019 Pattern
- Operating Systems Fundamentals PDF
- Computer Science: Chapter 3 - Operating Systems (PDF)
- OCR Computer Science A Level 1.2.1 Systems Software Notes PDF
- UNIT 5 MEMORY MANAGEMENT-1 PDF
Full Transcript
Operating Systems Memory Management Lecture 5 Dr. Pabudi Abeyrathne. [email protected] Faculty of Computing NSBM Green University Topic & Structure of the lesson Memory Management Logical and Physica...
Operating Systems Memory Management Lecture 5 Dr. Pabudi Abeyrathne. [email protected] Faculty of Computing NSBM Green University Topic & Structure of the lesson Memory Management Logical and Physical Memory Single Tasking with overlay Memory Partitioning Fragmentation At the end of this Outcomes Learning lecture YOU should be able to: - define memory management concepts - define single tasking with overlay - differentiate between fixed and variable partitioning - differentiate between internal and IfKey youTerms have mastered you must this topic, be able you should to use be able to use the following terms correctly in your assignments and exams: single tasking with overlay fixed partitioning variable partitioning internal fragmentation external fragmentation Address/ AddressThe space Basics Address space Address bytes(8 bits) K bits Definitions Address space: All memory locations a program can name Virtual address: Addresses in process’ address space Physical address: Address of real memory Translation: Map virtual to physical addresses Address Space Example What is B (where a byte is abbreviated as B) B = 1024 B = 1KB ( for memory, 1K= 1024, not 1000) How many bits to address each byte of 4 KB page? 4KB = 4 * 1 KB = 4 * B = bits How much memory can be addressed with 20 bits? 32 bits ? 64 bits? Memory Management Concepts For several processes to be in memory; memory needs to be shared Memory management is the planned organization of programs and data in memory Goals of memory management are: To make it as simple as possible for programs to find space to be loaded and executed To maximize the usage of memory to reduce Slide 8 of 26 Memory Management Responsibilities Keep track of memory usage. Allocate and de-allocate memory as needed. Ensure efficient sharing of memory among multiple processes. Slide 9 of 26 Memory Management A memory manager is responsible to keep track of which parts of the memory are in use and which parts are not, so that they can be de-allocated Slide 10 of 26 Physical and Logical Memory Logical Memory Physical Memory is divided into logical and physical addresses. logical addresses physical addresses Logical Address – an address that is generated by the CPU Physical Address – address seen by the memory unit - loaded into the memory address register Address Mappin Logical Physical g MMU (Hardwar e Device) Slide 11 of 26 Base and Limit Registers A pair of base and limit registers define the logical address space CPU must check every memory access generated in user mode to be sure it is between base and limit for that user Hardware Address Protection Address Binding Address binding maps symbolic addresses to physical memory addresses. Stages: ▶ Compilation: Uses symbolic addresses. (Compile time Binding) ▶ Loading: Program is loaded into memory. (Load time Binding) ▶ Execution: CPU accesses instructions using physical addresses. (Execution time Binding) Address Binding Example ▶ Programs reside on disk as executable files. ▶ Upon execution, they are loaded into memory. ▶ Initial physical address of the first process: 0x0000. Address Binding Example Cont… Swapping ▶ Swapping transfers processes between main memory and secondary storage. ▶ Frees up memory for other processes. Schematic View of Swapping Memory Management Techniques. ▶ Overlays. ▶ Memory Partitioning Overlays ▶ A technique to handle programs larger than the physical memory. ▶ Allows only necessary instructions and data to be loaded into memory. ▶ The rest of the program is loaded as needed and is managed by the user, not the OS. Overlays Cont.. The entire program and data of a process must be in the physical memory for the process to execute. The size of a process is limited to the size of physical memory. If a process is larger than the amount of memory, a technique called overlays can be used. Overlays Cont… Overlays is to keep in memory only those instructions and data that are needed at any given time. When other instructions are needed, they are loaded into space that was occupied previously by instructions that are no longer needed. Overlays are implemented by user, no special support needed from operating system, programming design of overlay structure is complex. Overlays Keep in memory only those instructions and data that are needed at any given time. Single Tasking With Overlay Applies overlays in a single-tasking OS environment. ▶ Only one program runs at a time in a single-tasking system. ▶ Uses overlays to manage memory by loading necessary parts of the running program. ▶ Enables running larger programs in limited memory. Slide 24 of 26 Single Tasking With Overlay Operating System Operating System Operating System Main Program Main Program Free space 250 bytes Overlay 2 Overlay 1 Overlay 3 Data Area Data Area Free space execution 1. Main program (100 4. Overlay 2 (50 bytes) 2. Data Area (50 bytes) 5. Overlay 3 (25 bytes) 3. Overlay 1(100 bytes) Slide 25 of 26 Single Tasking With Overlay Disadvantage A process cannot take advantage of more memory if it is available since the overlays are designed around a given amount of memory Slide 26 of 26 Memory Partitioning The process of dividing the system's memory into separate sections to efficiently allocate space to various processes. Dividing the memory space into partitions is the simplest form of memory management ▶ Fixed Partitioning: Divides memory into fixed-sized partitions. ▶ Variable Partitioning: Divides memory based on process requirements Slide 27 of 26 Memory Partitioning - Fixed Fixed partitioning - dividing the memory into fixed spaces Operating System 100 bytes 200 bytes 250 bytes Slide 28 of 26 Memory Partitioning - Fixed Each partition may contain exactly one process The degree of multiprogramming is bound by the number of partitions When a partition is free, a process is selected from the input queue and is loaded into the free partition when a process terminates, the partition becomes available for another process Slide 29 of 26 Fixed Memory Partitioning Dividing the memory into fixed spaces. Allocate One process for one partition. Slide 30 of 26 Memory Partitioning - Variable When a process arrives and needs memory, we search for a large enough space for this process loads the process wherever the memory space is available using first fit, best fit or worst fit algorithms Operating System 400 k P1 1000 k P2 2000 P3 k 2300 k Free space Slide 31 of 26 Memory Partitioning - Variable Variable Memory Partitioning Memory Allocation First Best Worst fit fitfit the process First fit – Allocates the first space available to fit best fit – Allocates the smallest space that will fit the process worst fit – Allocates the largest space available Slide 32 of 26 Fragmentation Memory partitioning techniques can lead to fragmentation. ▶ Internal Fragmentation: Wasted space within allocated memory blocks. ▶ External Fragmentation: Small free spaces that cannot be used for new allocations. Fragmentation happens when memory spaces are used in such a way that there are small pieces of memory available left unused Fragmentation occurs naturally when you use a disk frequently, creating, deleting, and modifying files Slide 33 of 26 Fragmentation Memory partitioning techniques suffer from fragmentation Fragmentation Internal Fragmentation External Fragmentation Slide 34 of 26 Internal Fragmentation When extra spaces are allocated to a process, the difference between the two numbers results in internal fragmentation Fixed partitioning leads to internal fragmentation as extra memory allocated to a program which is not used cannot be used elsewhere Slide 35 of 26 Internal Fragmentation Job Queue Operating System process memory 100 bytes P1 95 bytes 200 bytes P2 188 bytes P3 230 bytes 250 bytes Operating System 95 bytes free 188 bytes free 230 bytes free Slide 36 of 26 External Fragmentation Too many small sized free space These small spaces can not be used for anything as they are not contiguous Although enough total space exist but because they are not contiguous they cannot be allocated Variable partitioning leads to external fragmentation Slide 37 of 26 External Fragmentation To resolve external fragmentation a technique called compaction is used compaction shuffles all free memory spaces together to form a large block 400 OS OS 400 900 P5 P5 900 1000 1700 P4 P4 1600 2000 P3 1900 2300 P3 2560 2560 Slide 38 of 26 Quick Review Questions Why is memory management important? Name the problems caused by fixed memory partitioning and variable memory partitioning Slide 39 of 26 Follow Up Assignment How does single tasking with overlay work? Explain how variable partitioning leads to external fragmentation and what is done to overcome this Slide 40 of 26 Summary of Main Teaching Points Memory management uses techniques such as single tasking overlay, fixed and variable memory partitioning to manage processes in memory. Single tasking with overlay allows for the loading of processes bigger than physical memory space. Partitioning of memory is done using variable or fixed Slide 41 of 26 partitioning. Q&A Slide 42 of 26