Operating Systems Memory Management Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

First, lets talk about what a memory is in computer science world. Memory refers to physical device that used to store program sets of instructions or data on a temporary or permanent basis in computer, or other electronic devices in form of chips. Usually the term memory is used as a short hand for physical memory, which refers to the chip installed on the motherboard, and functioning ac high speed (e.g. RAM). But some computers also use virtual memory, which extends the physical memory onto the hard disks, runs slower than physical memory, but offers higher memory capacity.

F:\Documents and Settings\Eremes\My Documents\My Pictures\computer-memory-pyramid.jpeg

"The CPU accesses memory according to a hierarchy, whether it comes from permanent storage (the hard drive) or input (the keyboard), most data goes in random access memory (RAM) first. The CPU then stores pieces of data it will need to access, often in a cache, and maintains certain special instructions in the register" (How Computer memory works, 23 august 2000).

How computer manages memory

A normal computer has level 1 and level 2 caches, normal System RAM, A virtual memory created from a hard disks. A computer needs all those sources in order to get the best performance. If a computer didn't get the needed data, it will stop and waits for the sources to be free. In order to get all available resources, it's best to have maximum amount of virtual memory created from hard disks, as much as it's allowed. But having large amount of memory isn't everything in computing. A computer also needs a management system to manage all these memories. Memory management systems provide protections, memory mapping, fair physical memory allocation, and shared virtual memory. Most modern operating system like Windows XP uses virtual memory. Virtual memory makes it easy for several processes to share memory. "All memory accesses are made via page tables and each process has its own separate page table and for two processes sharing a physical page of memory, its physical page frame number must appear in a page table entry in both of their page tables" (Memory Management, 1996 - 1999).

How an operating system manages memory

The operating system may assign some memory to an application, but not necessarily enough to satisfy that application's every memory access. Instead, some accesses will be detected by hardware, which will reorganize some of the memory structure. "Windows XP-like Windows 2000-regularly checks that the memory assigned to a particular application is actually in use, and maintains an estimate for each application indicating the amount of memory that could reasonably be taken away without affecting performance. A reserve of memory is kept on hand to be used as needed. When this reserve sinks too low it is replenished by trimming working sets. These estimates are used as a guideline to determine where memory should be taken from" (Windows XP Performance, June 01, 2001).

Problems faced during memory management

The basic problem in memory management is how the system knows when to keep the data and when to recycle the memory so it can be used again. It sounds easy, but it's a very hard problem where the entire field of study tries to solve it and makes it optimal. The typical problems in memory management is usually a memory leak, where programs continuously allocate in a memory without ever going to end and eventually system will run out of memory. "Many programs give up memory, but attempt to access it later and crash or behave randomly. This condition is known as premature free, and the surviving reference to the memory is known as a dangling pointer. This is usually confined to manual memory management" (The Memory Management Reference, 2000). When a free memory splits into many small blocks, separated by the memory blocks that is still in use causing the allocator can't gives out big blocks of memories despite having enough memory to spare, this condition is known as external fragmentation. When a large block of memory can't allocate inside a fixed partitions that have an extra memory block which can't be used because of a smaller memory block already allocated that space causing a large gap, this condition is called internal fragment.

1.5.Managing Memory Management problems.

To overcome these problems, one of the solutions can be used is manual memory management, where the programmer has direct control over when a memory is going to be recycled. The programmer will know what's going on their systems, and can quickly deal with the problem. But there are some disadvantages such as, programmer must know and write a lot of codes to do repetitive book keeping of memory. But this disadvantage can be overcome by sub - allocators which can take advantage of special knowledge of program behavior, but it's rather inefficient or unreliable unless it's written by a memory management expert. Another methods used to overcome memory management problems, is Automatic memory management, which is a service, either as a part of the language or as an extension, that automatically recycles memory that a program would not otherwise use again.

Memory management system can swap a process temporally out of the memory to a backing store, do another needed process, and then brought back into memory for continued execution. Similar to round-robin CPU-scheduling algorithm, when a quantum expires, the memory manager will swap out that process to swap another process into the memory space that has been freed.

Memory management can also be done by the allocation of memory. First memory is divided into several fixed - sized partitions, when a partition is free, a process is loaded into the free partition and when it terminates, the partition becomes available for another process. There are 2 type of memory allocation, single - partition allocation and multiple - partition allocation. In single - partition, a single user space memory partition protected with relocation and limited registers, process are swapped in and out to provide for multi programming. Multiple - Partition allocation are available to permit multiple processes to be simultaneously resident in memory. This reduces lost time due to swapping. There are 2 techniques of multiple - partition allocation, which is, fixed size partition and variable partitioning.

Variable partitioning, or also called dynamic memory allocation, is the task of fulfilling an allocation request consists of locating a block of unused memory of sufficient size, the memory management system allocate the process whenever the memory space is available using first fit (Allocate the first space that is big enough, Search from beginning or where the previous first-fit search ended), best fit (Allocate the smallest space that is big enough, must search entire list, unless ordered by size, produces the smallest leftover space), worst fit (Allocate the largest space must also search entire list, while the needed space is small causing to produces the largest leftover space).