Download Main Memory - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!
Main Memory
Chapter 8
Objectives
- To provide a detailed description of various ways of
organizing memory hardware
- To discuss various memory-management techniques,
including paging and segmentation
- To provide a detailed description of the Intel
Pentium, which supports both pure segmentation
and segmentation with paging
Address Binding
- Programs must be brought into memory and placed
within a process for it to be run.
- The process resides in physical memory defined by
it’s address
- Addresses in the source program are generally symbolic, a compiler will bind these symbolic addresses to relocatable addresses
- The linker-loader will in turn bind these relocatable addresses to absolute addresses
CS 433 5
Multi-step Processing of a User Program
Logical vs. Physical Address Space
- The concept of a logical address space that is
bound to a separate physical address space is central to proper memory management
- Logical address – generated by the CPU; also referred
to as virtual address
- Physical address – address seen by the memory unit
- Logical and physical addresses are the same in
compile-time and load-time address-binding schemes;
- logical (virtual) and physical addresses differ in
execution-time address-binding scheme
Memory-Management Unit (MMU)
- Hardware device that maps virtual to physical
address
- In MMU scheme, the value in the relocation
register is added to every address generated by a user process at the time it is sent to memory
- The user program deals with logical addresses; it
never sees the real physical addresses
Dynamic Loading
- If the entire program and data must be placed in
physical memory for execution, then the size of the
process is limited by the physical memory size.
- With dynamic loading , Routine is not loaded until it
is called
- Better memory-space utilization; unused routine 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
Dynamic Linking
- In static linking the system libraries are combined by the loader into the binary program image.
- This can be wasteful of space if many programs use the same libraries.
- With 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 routine, and executes the routine
- Operating system needed to check if routine is in processes’ memory address
- Dynamic linking is particularly useful for libraries
- Dynamic linking libraries also known as shared libraries in Unix
- Dynamic linking requires help from the operating system. Operating system needed to check if routine is in another processes’ memory address, and to allow multiple processes to share memory space.
Schematic View of Swapping
Contiguous Allocation
- Main memory usually into two partitions:
- Resident operating system, usually held in low memory with interrupt vector
- User processes then held in high memory
- Relocation registers used to protect user processes from each other, and from changing operating-system code and data - Base register contains value of smallest physical address - Limit register contains range of logical addresses – each logical address must be less than the limit register - MMU maps logical address dynamically
CS 433 16
HW address protection with base and limit
registers
Contiguous Allocation (Cont.)
- Multiple-partition allocation
- Hole – block of available memory; holes of various size are scattered throughout memory
- When a process arrives, it is allocated memory from a hole large enough to accommodate it
- Operating system maintains information about: a) allocated partitions b) free partitions (hole)
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
External Fragmentation
- As memory is allocated to processes and freed as
processes terminate, the free memory space is
broken into small pieces.
- External Fragmentation – total memory space exists
to satisfy a request, but it is not contiguous.
- Statistical analysis reveals that with the first fit
memory allocation rule, given N allocated blocks,
another 0.5N blocks may be lost due to
fragmentation (50 percent rule).
- This means 1/3 of memory is unusable!
Internal Fragmentation
- One method of allocating memory is to break memory into fixed sized blocks.
- Memory is allocated in units of block sizes.
- The memory allocated may be slightly larger than the size needed by the process. This is Internal Fragmentation.
- With Internal Fragmentation, the size difference between the process size and the allocated memory is memory internal to a partition, but not being used.
- Example: Block size 1024 bytes. Process size: 4048 bytes.
What is the internal fragmentation size?