Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.

Similar presentations


Presentation on theme: "CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido."— Presentation transcript:

1 CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido

2 CS6502 Operating Systems - Dr. J. Garrido Memory Management-- Background A program must be loaded into memory and placed within a process for it to be executed. Input queue – collection of processes on the disk that are waiting to be loaded into memory for execution. User programs go through several steps before being executed.

3 CS6502 Operating Systems - Dr. J. Garrido Program Development Source editing Compilation Linking Loading Executing

4 CS6502 Operating Systems - Dr. J. Garrido Binding Address binding: the association of instructions and data to memory addresses. This can occur at three different stages. Compile time: If the memory locations are known a priori, absolute code can be generated; must recompile code if starting location changes. Load time: Must generate relocatable code if memory location is not known at compile time. Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another.

5 CS6502 Operating Systems - Dr. J. Garrido Dynamic Loading A module is not loaded until it is called Better memory-space utilization; unused module is never loaded. Useful when large amounts of code are needed to handle infrequently occurring cases. No special support from the operating system is required implemented through program design.

6 CS6502 Operating Systems - Dr. J. Garrido Dynamic Linking Linking postponed until execution time. Small piece of code, stub, used to locate the appropriate memory-resident library routine. Stub replaces itself with the address of the module, and executes the module. Operating system needed to check if module is in processes’ memory address.

7 CS6502 Operating Systems - Dr. J. Garrido Logical vs. Physical Address Space Logical address – a reference to a location in the program. It is generated by the compiler or assembler Physical address – an actual location in main memory A logical address space is bound to a separate physical address space when the program is loaded.

8 CS6502 Operating Systems - Dr. J. Garrido Memory Management Classification Memory Management with static loading: Entire program is loaded into memory. Once program is loaded, it stays in memory ‘till execution is complete. Monoprogramming - One program in memory at a time. Multiprogramming - Partition memory: Load more than one program. –Fixed Partitions –Variable Partitions

9 CS6502 Operating Systems - Dr. J. Garrido Memory Management Classification Memory Management with dynamic loading: Swapping –Whole program is in memory during execution. –Whole program is moved to disk when suspended. Overlaying –Only part of program is in memory during execution. –May be moved to disk when suspended. Paging Segmentation Virtual memory -- Only currently executing portion of program is in memory

10 CS6502 Operating Systems - Dr. J. Garrido Swapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images.

11 CS6502 Operating Systems - Dr. J. Garrido Schematic View of Swapping

12 CS6502 Operating Systems - Dr. J. Garrido Static Relocation Different jobs run at different addresses. Addresses are changed at load time. (Relocation) Static relocation modifies instructions that address locations in memory. Static relocation does not solve protection.

13 CS6502 Operating Systems - Dr. J. Garrido Dynamic Relocation Addresses changed at execution time. Facilitates Protection using: –Addressing via Base (&Limit) Register. Additional benefit, program may be moved during execution.

14 CS6502 Operating Systems - Dr. J. Garrido Protection Necessary because malicious or incompetent programs may access the program or data space of another program and contaminate it.

15 CS6502 Operating Systems - Dr. J. Garrido Protection (2) Solution: Divide memory into Blocks of memory, associate a key with each block. Trap or transfer control to the OS when any program attempts to access memory whose key does not agree with its own.

16 CS6502 Operating Systems - Dr. J. Garrido Protection (3) Alternative: Load a Base Register w/ address at which process loaded. Load a Limit Register w/ size of partition. Compare each address generated with the contents of the base and base + limit register.

17 CS6502 Operating Systems - Dr. J. Garrido Contiguous Memory Allocation Main memory is divided into partitions: Single User Partition: –Resident operating system, usually held in low memory with interrupt vector. –User processes then held in high memory. Multiple User Partitions

18 CS6502 Operating Systems - Dr. J. Garrido Single-partition allocation Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register.

19 CS6502 Operating Systems - Dr. J. Garrido Multiple Partitions Fixed partitions (static) – the number and sizes of the partitions do not change Variable partitions (dynamic) – partitions are created dynamically according to: –available memory –the memory requirements of processes

20 CS6502 Operating Systems - Dr. J. Garrido Fixed Partitions Memory is divided into fixed-sized partitions. These are not normally of the same size. The number and the size of the partitions are fixed. One partition is allocated to each active process in the multiprogramming set. There is one special partition, the system partition, in which the memory-resident portion of the operating system is always stored.

21 CS6502 Operating Systems - Dr. J. Garrido Multiple Fixed Partitions Method of organizing memory: Divide memory into n partitions. Rule: Process may not be larger than the partition. If all Partitions of same size: Lots of space lost internally in the Partition. (Internal Fragmentation) Operating System Partition 4 Partition 2 Partition 3 Partition 1 200K 400K 600K 800K Process 4 Process 3 Process 2 Process 1

22 CS6502 Operating Systems - Dr. J. Garrido Fixed Partitions

23 CS6502 Operating Systems - Dr. J. Garrido Fragmentation in Fixed Partition Fragmentation problem Internal fragmentation - A partition is only partially used. The entire partition is allocated to a program

24 CS6502 Operating Systems - Dr. J. Garrido Memory Allocation Problem An important problem in OS is finding a fit between the partition sizes and the actual memory requirements of processes The goal is to minimize fragmentation

25 CS6502 Operating Systems - Dr. J. Garrido Fixed Partitions: Multiple Input Queues Partition 4 Partition 2 Partition 1 Multiple Input Queues 100K 200K 400K 700K Partition 3 Operating System If Partitions are of different sizes: Less space is left unused to Internal Fragmentation. When a job arrives, it can be put into the input queue for the smallest partition which is large enough to hold it. Disadvantage of sorting incoming jobs into separate queues occurs when the queue for small partitions is full, but the queue for large partition is empty and consequently jobs await space when space is available.

26 CS6502 Operating Systems - Dr. J. Garrido Single Input Queue Partition 4 Partition 2 Partition 1 100K 200K 400K 700K Partition 3 Operating System Single Input Queue OS/MFT Used by OS/360 Alternative is to have a single queue for all jobs. When a partition becomes available, assign the job closest to front of queue that will fit. Incoming jobs are queued until suitable partition is available. Then, the process is loaded into the partition and run until terminated.

27 CS6502 Operating Systems - Dr. J. Garrido Variable Partition Allocation The partitions are created dynamically The OS maintains a table of partitions allocated that indicates which parts (location and size) of memory are available and which have been allocated.

28 CS6502 Operating Systems - Dr. J. Garrido Holes in Memory Hole – a contiguous block of available memory When a process requests memory, it is allocated memory from a hole large enough to accommodate it. Operating system maintains data about: –allocated partitions –Available memory blocks (holes)

29 CS6502 Operating Systems - Dr. J. Garrido Allocation with Variable Partitions At any given time, there is a list of available blocks of memory of various sizes (holes) and a queue of processes requesting memory. Memory is allocated contiguously to processes until there is no available block of memory large enough

30 CS6502 Operating Systems - Dr. J. Garrido Dynamic Memory Allocation The memory manager can: Wait until a large enough block of memory is available, or Skip down the queue to find a process with smaller requirements for memory.

31 CS6502 Operating Systems - Dr. J. Garrido Holes and Memory Allocation When a process is to be loaded, the OS searches for a hole large enough for this process and allocates the necessary space. When a process terminates, the OS frees its block of memory. In general, there is at any time, a set of holes, of various sizes, scattered throughout memory. Adjacent holes are merged to form a larger hole.

32 CS6502 Operating Systems - Dr. J. Garrido Memory Allocation First-fit: Allocate the first hole that is big enough. Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. How to satisfy a process request of size n from a list of free holes. First-fit and best-fit better than worst-fit in terms of speed and storage utilization.

33 CS6502 Operating Systems - Dr. J. Garrido Advantages of Variable Partition Memory utilization is generally better for variable-partition schemes. There is little or no internal fragmentation. There can be external fragmentation.

34 CS6502 Operating Systems - Dr. J. Garrido Memory States OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10

35 CS6502 Operating Systems - Dr. J. Garrido Compaction: Solution to Fragmentation External fragmentation is a serious problem. The goal is to shuffle the memory contents to place all free memory together in one large block. This is only possible if relocation is dynamic (binding is done at execution time), using base and limit registers. Can be quite expensive (overhead).

36 CS6502 Operating Systems - Dr. J. Garrido Fragmentation - Recap External fragmentation – total memory space exists to satisfy a request, but it is not contiguous. Internal fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.

37 CS6502 Operating Systems - Dr. J. Garrido Non-contiguous Memory Allocation Paging Segmentation

38 CS6502 Operating Systems - Dr. J. Garrido Pages A page is a unit of logical memory of a program A frame is a unit of physical memory All pages are of the same size All frames are of the same size A frame is of the same size as a page

39 CS6502 Operating Systems - Dr. J. Garrido Paging Physical memory is divided into fixed-sized blocks called frames (size is power of 2 ). Logical memory is divided into blocks of same size called pages. A page of a program is stored on a frame, independently of other pages A logical address on the page is converted to a physical address on the corresponding frame

40 CS6502 Operating Systems - Dr. J. Garrido

41 Paging(2) The OS keeps track of all free (available) frames, and allocated frames in the page table. To run a program of size n pages, the OS needs n free frames to load program. The OS sets up a page table and converts logical to physical addresses. There is a small amount of internal fragmentation.

42 CS6502 Operating Systems - Dr. J. Garrido Memory Allocation with Paging The frames allocated to the pages of a process need not be contiguous; in general, the system can allocate any empty frame to a page of a particular process. There is no external fragmentation There is potentially a small amount of internal fragmentation that would occur on the last page of a process.

43 CS6502 Operating Systems - Dr. J. Garrido Logical Address Any address referenced in a process is defined by the page that the address belongs to and the relative address within that page. A logical address of a process consists of a page number and an offset.


Download ppt "CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido."

Similar presentations


Ads by Google