Presentation is loading. Please wait.

Presentation is loading. Please wait.

Day 18 Memory Management.

Similar presentations


Presentation on theme: "Day 18 Memory Management."— Presentation transcript:

1 Day 18 Memory Management

2 Main Memory Holds user programs and operating system code
Memory management involves managing how main memory is shared among the various processes. The OS performs this function with support from hardware. A program that is running or ready or blocked exists in main memory.

3 Requirements of memory management
Relocation Protection Sharing Logical organization Physical organization

4 Assumptions An entire program exists in main memory.
A program is stored as one contiguous block in main memory.

5 Hardware support for memory management
How to partition memory. How to keep track of which partition belongs to which process. How to prevent a process from accessing a partition that has not been allocated to it.

6 Fragmentation Internal – space within an allocation block is not completely used Typical in allocation schemes that have fixed block sizes. Can be reduced by making the block size small. External – holes created between blocks that cannot be used Typical in allocation schemes where block sizes are not fixed and are determined by the request. Compaction must be performed frequently.

7

8 Fixed partitioning => fixed size blocks
Equal sized All partitions are the same size. Un-equal sized Partitions are of un-equal sizes.

9

10 Fixed partitioning - disadvantages
Fixed partitioning is simple and very little OS support is required. However, Since number of partitions is fixed, it limits the degree of multi-programming It is inefficient with small processes. If the sizes of processes are known beforehand then a reasonable size can be decided on.

11 Dynamic partitioning Partitions are created dynamically
Sizes are not fixed and are determined based on the request. The number of partitions is also not fixed. Disadvantages: More external fragmentation Placement is more complicated

12 Could you now find space for a process of size 7M? Placement – If a process of size 3M is to be placed, where would you place it?

13 Placement algorithms First fit – start searching from the beginning and allocate the first available block. Next fit – start searching from the last allocation and allocate the first available block. Best fit – start searching from the beginning and allocate the available block that will result in the smallest hole Which do you think will keep the fragmentation to the minimum?

14 In the following memory configuration,
where would a 16MB block be placed with a. First Fit algorithm b. Next Fit algorithm c. Best Fit algorithm Mark your answers on the diagram Placement Algorithm

15 Keeping track of memory
From “Operating Systems” by Tannenbaum

16 Buddy System Fixed partitioning Dynamic partitioning Buddy system
Limits # of active processes Uses space inefficiently if the sizes of the processes don’t match with that of the partitions. Dynamic partitioning More complex to maintain Includes overhead of compaction Buddy system Blocks available are of size 2K, L <= K <=U 2L is the smallest block allocated 2U the largest block allocated and is the size of the entire memory available for allocation. When a request is made, if the request is 2U-1 <= s <= 2U, then the entire block is allocated. Else, split into 2U-1 sized buddy blocks If 2U-2 <= s <= 2U-1, then allocate an entire 2U-1 buddy block. Else, split one of the 2U-1 blocks into 2U-2 sized buddy blocks And so… When two buddies become available (after a block is de-allocated), they are coalesced together into one hole.

17 Buddy system Using the Buddy algorithm, show how the memory block will partitioned after each request/release. 3. Request C=64 K 4. Request D=256K 5. Release B 6. Release A 7. Request E=75K 8. Release C 9. Release E 10. Release D Used in UNIX kernel management. Uses Lazy buddy i.e don’t coalesce imediately ato reduce the workload.

18 Relocation When a process is brought back to memory, it can be placed anywhere and not its original location. Address translation is therefore required. Logical address – Address irrespective of where the program is currently placed. Relative address – an example of a logical address typically relative to a value in a register or the beginning of a program. Physical address/absolute address – the actual address in memory. Dynamic run-time loading is required.

19


Download ppt "Day 18 Memory Management."

Similar presentations


Ads by Google