Introduction to Operating Systems: Unit III: Memory Management

Main Memory

Memory Management - Introduction to Operating Systems

Memory is used to store information. Secondary storage memory is long term persistent memory that is held in storage device such as disk drive.

UNIT III: Memory Management

Chapter: 4

Syllabus

Hod Main Memory - Swapping - Contiguous Memory Allocation - Paging - Structure of the Page Table - Segmentation, Segmentation with paging; Virtual Memory - Demand Paging - Copy on Write- Page Replacement - Allocation of Frames -Thrashing.


Main Memory

Memory is used to store information. Secondary storage memory is long term persistent memory that is held in storage device such as disk drive.

• Primary memory is faster than secondary memory. Memory manager is responsible for allocating primary memory to processes.

• Memory management is performed by both software and special purpose hardware. The memory manager is an operating system component. Managing the sharing of primary memory and minimizing memory access time are the basic goals of the memory manager.

Primary memory requirements

1. Access time: It should be as small as possible. This need influences both software and hardware design.

2. Size: Size must be as large as possible. It can accomodate many programs into memory.

3. Cost: Cost of the memory is less than the total cost of the computer.

Memory Management Function

1. Allocate primary memory space to processes.

2. Minimize access time.

3. Determining allocation policy for memory.

4. Deallocation technique and policy.

Basic Hardware of Memory

• CPU can access content of main memory and register directly. If the data is not available into the memory, it load into memory from disk.

• Registers are built on the processor. Using one cycle of the CPU clock, processor access data from register.

Accessing memory may take many CPU clock cycle. Mismatch of speed between CPU and memory is overcome by using cache memory.

• The use of base and bound (limit) registers are restrict a process memory references upto a certain limit. Hardware is used to protect user address space.

• Each process requires its own address space operating system define legal address for each process. Maximum and minimum limit is also decided so that process can access only these legal address.

• Fig. 4.1.1 shows the protection of process by using registers.

• An address space is the set of addresses that a process/program can use to address main memory. Each process en has its own address space.

• User programs are loaded into consecutive memory locations by using base and limit register. When process is executing, the base register is loaded with the physical address where its program begins in memory and the limit register is loaded with the length of the program.

• Memory protection is used to avoid interference between programs existing in main memory. The memory protection hardware compares every memory address used by the program with the contents of two registers (base and limit) to ensure that it lies with the allocated memory area.

• Multiple hardware memories are used to provide a larger address space.

The simplest method of memory protection is adding two registers to the CPU. This works good for all memory is allocated contiguously. Non-contiguous memory is harder to protect.

• When a process reads from or writes to address, the memory decoder adds on the value of the base register. The actual operation of read or write to address = Base register + limit register.

• If the input address is higher than limit or lower than zero, then the memory hardware generates error. This is informed to the operating system by using not interrupt. Processes can only access memory within these limits.

• Each process has its own pair of base register and limit register.

Address Space Mapping

• Secondary storage device stores program in binary executable format. Before executing, the program is loaded into the main memory.

• Most of the operating systems allow a user process to store in any section of the main memory. Source program uses symbolic addresses.

 Fig. 4.1.2 shows processing of user program.

• Binding of instruction and data to main memory address is following ways:

1. Compile time 2. Load time 3. Execution time

• Compile time: Source program is translated at compile time to produce a relocatable object module. At compile time, the translator generates code to allocate storage for the variable. This storage address is used for code reference. Target address is unknown at compile time, it cannot be bound at compile time. Example of compile time binding is MS, DOS.com programs.

• Load time: Compiler generates relocatable code if compile time binding is not performed. The loader modifies the addresses in the load module at load time to produce the executable image stored in main memory. Final binding is delayed until program load time.

• Execution time: Memory address of the program is changed at execution time, then execution time binding is used. Binding is delayed until the run time of the program. Normally all operating system uses execution time binding. Special hardware is used for execution time binding.

• Memory allocation and deallocation is done using run-time support of the programming language in which a program is coded. Allocation and deallocation requests are made by calling appropriate routines of the run time library.

• Kernel is not involved in this kind of memory management.

Concept of Memory Address

• Logical address is generated by the CPU. This address is also called virtual address.

• Main memory address uses physical address. This address also called real address.

Logical address space : Set of all logical addresses generated by a program.

• Logical address and physical address is identical when load time and compile time address binding is performed. The execution time address binding generates different physical and logical address.

• Memory Management Unit (MMU) is responsible for run time address mapping from vitual to physical address.

Dynamic relocation

• Base register is sometimes called as a relocation register. The value of the relocation register is added to every address generated by a user process at the time it is sent to main memory.

• User can load a process with only absolute addresses for instructions and data, only when those specific addresses are free in main memory. Program's instruction, data and any other data structure required by the process can be accesssed easily if the addresses are relative.

• Fig. 4.1.3 shows dynamic relocation. User programs never reads the main memory physical address.

• Dynamic relocation requires extra hardware. It mapping of the virtual address space to the physical address space at run time.

• Dynamic relocation makes it possible to move a partially executed process from area of main memory into another without affecting other process.

• Problem with relocation is that, it is necessary to perform an addition and a comparison on every memory reference.

• For good memory management, logical address space is bound with a separate physical address space.

Dynamic Loading

• Dynamic loading is used for better memory space utilization. User program size is large as compared to the memory size. Program or process are dynamically loaded into memory as per required.

• With dynamic loading, a routine is not loaded until it is called. All routines are kept on storage disk in a relocatable load format. The main program is loaded into memory and is executed.

Advantages rem

1. Unused routine is never loaded.

2. Special support is not required from OS.

3. Used with error routines.

Introduction to Operating Systems: Unit III: Memory Management : Tag: : Memory Management - Introduction to Operating Systems - Main Memory