Chapter 7 Memory Management Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management Paging Segmentation
1 Chapter 7 Memory Management • Basic requirements of Memory Management • Memory Partitioning • Basic blocks of memory management – Paging – Segmentation
The need for memory management Memory is cheap today, and getting cheaper But applications are demanding more and more memory, there is never enough Memory Management involves swapping blocks of data from secondary storage Memory /o is slow compared to a CPu The os must cleverly time the swapping to maximise the CPUs efficiency
2 The need for memory management • Memory is cheap today, and getting cheaper – But applications are demanding more and more memory, there is never enough! • Memory Management involves swapping blocks of data from secondary storage. • Memory I/O is slow compared to a CPU – The OS must cleverly time the swapping to maximise the CPU’s efficiency
Memory Management A program must be loaded into main memory to be executed Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time otherwise, for much of the time all of the processes will be waiting for l/ 0 and the processor W‖ i be idle
3 Memory Management Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time – Otherwise, for much of the time all of the processes will be waiting for I/O and the processor will be idle. A program must be loaded into main memory to be executed
Memory Management Requirements ·Re| ocation Protection Sharing Logical organisation Physical organisation
4 Memory Management Requirements • Relocation • Protection • Sharing • Logical organisation • Physical organisation
REquirements: Relocation The programmer does not know where the program will be placed in memory when it is executed it may be swapped to disk and return to main memory at a different location(relocated But, os knows because it is managing memory and is responsible for bringing this process into main memory
5 Requirements: Relocation • The programmer does not know where the program will be placed in memory when it is executed, – it may be swapped to disk and return to main memory at a different location (relocated) • But, OS knows because it is managing memory and is responsible for bringing this process into main memory
Addressing Process control information Process Control Block Entry pon to program Branch togram Instruction Increasing address valules Reference to data The processor and os must be ata able to translate the memory references found in the code of current top f stack the program into actual physical Stack memory addresses(to be discussed
6 Addressing The processor and OS must be able to translate the memory references found in the code of the program into actual physical memory addresses (to be discussed)
Requirements: Protection Processes should not be able to reference memory locations in another process Without permission Impossible to check absolute addresses at compile time Must be checked at run time
7 Requirements: Protection • Processes should not be able to reference memory locations in another process without permission • Impossible to check absolute addresses at compile time • Must be checked at run time
Requirements: Sharing Allow several processes to access the same portion of memory Better to allow each process executing the same program access to the same copy of the program rather than have their own separate copy Processes that are cooperating on some task may need to share access to the same data structure
8 Requirements: Sharing • Allow several processes to access the same portion of memory – Better to allow each process executing the same program access to the same copy of the program rather than have their own separate copy – Processes that are cooperating on some task may need to share access to the same data structure
Requirements Logical Organization Memory is organized linearly (usually) n contrast, programs are organized into modules Modules can be written and compiled independentl Different degrees of protection can be given to different modules(read-only, execute-only) Modules can be shared among processes Segmentation helps here
9 Requirements: Logical Organization • Memory is organized linearly (usually) • In contrast, programs are organized into modules – Modules can be written and compiled independently – Different degrees of protection can be given to different modules (read-only, execute-only) – Modules can be shared among processes • Segmentation helps here
Requirements: Physical Organization Cannot leave the programmer with the responsibility to manage memory Memory available for a program plus its data may be insufficient Programmer does not know how much space will be available The task of moving information between the two levels of memory should be a system responsibility 10
10 Requirements: Physical Organization • Cannot leave the programmer with the responsibility to manage memory – Memory available for a program plus its data may be insufficient – Programmer does not know how much space will be available • The task of moving information between the two levels of memory should be a system responsibility