TimeLinux1

Friday, May 20, 2011

OS Concepts - Memory Management - 1

Memory Management:
-towards the goal of maximizing cpu utilization, multiple programs need to be stored in memory.
-memory consits of a large array of words or bytes each with its own address.
-the cpu fetches instructions from the memory according to the value of the program counter.
-the cpu can fetch instructions directly only from:
    . registers built into the cpu
    . main memory.
-in other words, for instructions to be fetched by cpu, they must be brought to the above two first.
-note that cpu cannot directly access secondary storage like disks.
-since registers are built into the cpu, their access is as fast as the cpu itself.
-main memory on the other hand is accessed via the memory bus and therefore is much slower to access.
-to bridge this, a fast memory between cpu and main memory called 'cache' is used.
-apart from speed issues, the multiple processes residing in memory need to be protected from each other.
-this is done using the concept of memory address space.
-address space protection requires hardware support in the cpu.
-memory address space is like an isolated container for the processes.
-the address space is bounded by a base-register and a limit-register.
-base -register defines the smallest address for the address space.
-limit-register defines the range of addresses above the base register, available to the address space.
-the base and limit registers are part of the cpu h/w.
-the cpu compares the address generated in user mode with the registers assigned to a process.
-if there is a mismatch, then the process is trying to access memory outside its address space and that must be stopped.
-this is done by trapping the process in the os and sending an fatal error to the user process.
-the 'os' here is the kernel that runs in kernel mode.
-the os or kernel has unrestricted view and access to the memory assigned to the kernel and the users.
-note: the memory has a fixed area assigned for os kernel space and the remainder for user space.

-swapping is the event in which a process is moved temporarily out of memory to disk or secondary storage.
-this allows the scheduler to put another process in ready queue and available for cpu to work upon.
-address space assigned to a process is usually contiguos.
-if this becomes not possible (eg due to excessive swapping), fragmentation of memory arises.
-the cpu register does not know the absolute memory address of a process.
-this is because cpu register has much smaller size than main memory.
-the address used by the cpu is called 'logical address'.
-the address used by the mem is called 'physical address'.
-the mapping of logical to physical address is managed by the 'mmu' (memory management unit).
-this concept of logical address mapped to a separate physical address is central to proper memory management.

... continued ...

No comments:

Post a Comment