Next:
Basic Memory Management
Up:
Ceng 328 Operating Systems
Previous:
Summary of Deadlock strategies
Contents
Memory Management
The CPU fetches instructions and data of a program from memory; therefore, both the program and its data must reside in the main (RAM and ROM) memory
What is memory Huge linear array of storage
malloc
library call
used to allocate and free memory
finds sufficient contiguous memory
reserves that memory
returns the address of the first byte of the memory
free
library call
give address of the first byte of memory to free
memory becomes available for reallocation
both
malloc
and
free
are implemented using the
brk
system call
Example of allocation (see the Fig.
4.1
)
char *ptr=malloc(4096); //char* is address of a single byte
Figure 4.1:
Allocating Memory.
Modern multiprogramming systems are capable of storing more than one program, together with the data they access, in the main memory
A fundamental task of the
memory management
component of an operating system is to ensure safe execution of programs by providing:
Sharing of memory; issues are
Transparency
; Several processes may co-exist, unaware of each other, in the main memory and run regardless of the number and location of processes.
Efficiency
; CPU utilization must be preserved and memory must be fairly allocated. Want low overheads for memory management.
Relocation
Ability of a program to run in different memory locations.
Memory protection; processes must not corrupt each other (nor the OS!)
Information stored in main memory can be classified in a variety of ways:
Program (
code
) and data (
variables, constants
).
Read-only (
code, constants
) and read-write (
variables
).
Address (
e.g., pointers
) or data (
other variables
); binding (when memory is allocated for the object): static or dynamic
The compiler, linker, loader and run-time libraries all
cooperate to manage this information.
Before a program can be executed by the CPU, it must go through several steps:
Compiling (translating)
-generates the object code.
Linking
-combines the object code into a single self-sufficient
executable code
.
Loading
-copies the executable code into memory. May include run-time linking with libraries.
Execution
-dynamic memory allocation.
Figure 4.2:
From source to executable code.
The process of associating program instructions and data (addresses) to physical memory addresses is called
address binding
, or
relocation
Static
-new locations are determined
before
execution
Compile time: The compiler or assembler translates
symbolic
addresses (e.g., variables) to
absolute
addresses.
Load time: The compiler translates symbolic addresses to
relative
(
relocatable
) addresses. The loader translates these to absolute addresses.
Dynamic
-new locations are determined
during
execution
Run time: The program retains its relative addresses. The absolute addresses are generated by hardware.
Subsections
Basic Memory Management
Monoprogramming without Swapping or Paging (see the Fig. 4.3)
Multiprogramming with Fixed Partitions (see the Fig. 4.4)
Relocation and Protection (see the Fig. 4.5)
Swapping
Memory Management cont.
Virtual Memory
Paging (see the Fig. 4.8)
Page Tables (see Fig. 4.12)
Inverted Page Tables
Basic policies
Page Replacement Algorithms
Page Replacement Cont.
Segmentation
Segmentation with Paging
Segmentation with Paging: MULTICS
Segmentation with Paging: The Intel Pentium (see Fig. 4.18)
Next:
Basic Memory Management
Up:
Ceng 328 Operating Systems
Previous:
Summary of Deadlock strategies
Contents
2004-05-25