MEMORY
MANAGEMENT
The
memory management function keeps track of the status of each memory location,
either allocated or free. It determines
Ø
how memory is allocated among
competing processes
Ø
Deciding who gets memory
Ø
when they receive it
Ø
how much they are allowed
When
memory is allocated it determines which memory locations will be assigned. It
tracks when memory is freed or unallocated
and updates the status.
Memory management is usually divided into three areas:
Ø Hardware
Ø Operating system
Ø Application
Although the distinctions are a little fuzzy. In most computer
systems, all three are present to some extent, forming layers between the
user's program and the actual memory hardware.
Memory
management at the hardware level is concerned with the electronic devices that
actually store data. This includes things like RAM and memory caches.
In
the operating system, memory must be allocated to user programs, and reused by
other programs when it is no longer required. The operating system can pretend
that the computer has more memory than it actually does, and also that each
program has the machine's memory to itself; both of these are features of
virtual memory systems.
Application
memory management involves supplying the memory needed for a program's objects
and data structures from the limited resources available, and recycling that
memory for reuse when it is no longer required. Because application programs
cannot in general predict in advance how much memory they are going to require,
they need additional code to handle their changing memory requirements.
Application
memory management combines two related tasks:
When
the program requests a block of memory, the memory manager must allocate that
block out of the larger blocks it has received from the operating system. The
part of the memory manager that does this is known as the allocator. There are
many ways to perform allocation, a few of which are discussed in Allocation
techniques.
When
memory blocks have been allocated, but the data they contain is no longer
required by the program, then the blocks can be recycled for reuse. There are
two approaches to recycling memory: either the programmer must decide when
memory can be reused (known as manual memory management); or the memory manager
must be able to work it out (known as automatic memory management). These are
both described in more detail below.
An
application memory manager must usually work to several constraints, such as:
CPU overhead
The
additional time taken by the memory manager while the program is running;
Interactive pause times
How
much delay an interactive user observes;
Memory overhead
How
much space is wasted for administration, rounding (known as internal
fragmentation), and poor layout (known as external fragmentation).
What happens when Role of Memory Management Is not considered
The
basic problem in managing memory is knowing when to keep the data it contains,
and when to throw it away so that the memory can be reused. This sounds easy,
but is, in fact, such a hard problem that it is an entire field of study in its
own right. In an ideal world, most programmers wouldn't have to worry about
memory management issues. Unfortunately, there are many ways in which poor
memory management practice can affect the robustness and speed of programs, both
in manual and in automatic memory management.
Typical
problems include:
Premature free or dangling pointer
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.
Memory leak
Some
programs continually allocate memory without ever giving it up and eventually
run out of memory. This condition is known as a memory leak.
External fragmentation
A
poor allocator can do its job of giving out and receiving blocks of memory so
badly that it can no longer give out big enough blocks despite having enough
spare memory. This is because the free memory can become split into many small
blocks, separated by blocks still in use. This condition is known as external
fragmentation.
Poor locality of reference
Another
problem with the layout of allocated blocks comes from the way that modern
hardware and operating system memory managers handle memory: successive memory
accesses are faster if they are to nearby memory locations. If the memory
manager places far apart the blocks a program will use together, then this will
cause performance problems. This condition is known as poor locality of
reference.
Inflexible design
Memory
managers can also cause severe performance problems if they have been designed
with one use in mind, but are used in a different way. These problems occur
because any memory management solution tends to make assumptions about the way
in which the program is going to use memory, such as typical block sizes,
reference patterns, or lifetimes of objects. If these assumptions are wrong,
then the memory manager may spend a lot more time doing bookkeeping work to
keep up with what's happening.
Interface complexity
If
objects are passed between modules, then the interface design must consider the
management of their memory.
Manual memory management
Manual
memory management is where the programmer has direct control over when memory
may be recycled. Usually this is either by explicit calls to heap management
functions (for example,
malloc
/free
in C), or by language
constructs that affect the stack (such as local variables). The key feature of
a manual memory manager is that it provides a way for the program to say,
"Have this memory back; I've finished with it"; the memory manager
does not recycle any memory without such an instruction.
The
advantages of manual memory management are:
Ø It can be easier for the programmer to understand exactly what is
going on;
Ø Some manual memory managers perform better when there is a shortage
of memory.
The
disadvantages of manual memory management are:
Ø The programmer must write a lot of code to do repetitive bookkeeping
of memory;
Ø Memory management must form a significant part of any module
interface;
Ø Manual memory management typically requires more memory overhead per
object;
Ø Memory management bugs are common.
It
is very common for programmers, faced with an inefficient or inadequate manual
memory manager, to write code to duplicate the behavior of a memory manager,
either by allocating large blocks and splitting them for use, or by recycling
blocks internally. Such code is known as a sub allocator. Sub allocators can
take advantage of special knowledge of program behavior, but are less efficient
in general than fixing the underlying allocator. Unless written by a memory
management expert, sub allocators may be inefficient or unreliable.
The
following languages use mainly manual memory management in most
implementations, although many have conservative garbage collection extensions:
Algol; C; C++; COBOL; FORTRAN; Pascal.
Automatic memory management
Automatic
memory management 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. Automatic memory managers (often known as garbage collectors, or simply
collectors) usually do their job by recycling blocks that are unreachable from
the program variables (that is, blocks that cannot be reached by following
pointers).
The
advantages of automatic memory management are:
Ø The programmer is freed to work on the actual problem;
Ø Module interfaces are cleaner;
Ø There are fewer memory management bugs;
Ø Memory management is often more efficient.
The
disadvantages of automatic memory management are:
Ø Memory may be retained because it is reachable, but won't be used
again;
Ø Automatic memory managers (currently) have limited availability.
Most
modern languages use mainly automatic memory management: BASIC, DylanTM, Erlang, Haskell, JavaTM, JavaScriptTM, Lisp, ML, Modula-3,
Perl, the PostScript® language, Prolog, Python, Scheme, Smalltalk, etc.
ROLE OF MEMORY MANAGEMENT IN OPERATING SYSTEM:
Every process that needs to execute in OS,
requires a certain amount of memory. Memory management is one of the tasks
handled by the operating system.
Memory management plays several roles in a computer system:
Ø Every program for its execution requires some
space in computer memory which is provided by memory management unit using virtual memory that
provides the external storage addressing location for the Programs that does
not have too much space in main memory for their execution and saved them in
secondary memory. Memory management
schemes handle the allocation of memory to different processes. On completion
of process execution, the memory is de-allocated and made available to another
process.
Ø Memory management
is used in multitasking operating systems to make it look as if each task has
sole control of the CPU.
The above
figure demonstrates a multitasking system in which three processes are
initially loaded into memory—task A, task B,
and task C. This diagram shows the physical memory or main store where the
programs are located. In figure 1b task B has
been executed to completion and deleted from memory to leave a hole in the memory. In figure 1c a new
process, task D, is loaded in part of the unused
memory and task A deleted.
Finally, in figure 1d a new process, task E, is loaded in memory in two parts
because it can’t fit in any single free block of memory space.
Ø Memory management can be employed to protect one task from being
corrupted by another task. The data which we
are using in our computer is kept in the secondary storage medium that stores
the data permanently in computer memory because it is non volatile in nature
and protection of the stored data in memory is provided by the memory management unit such
that it will automatically repair and fix the errors there in the bad tracks
and sectors.
Moreover, as far as the data security is
concerned then certain programs are protected with the master password that
cannot allow the access of the data without the administrator
confirmation. Moreover, certain programs
are provided with the shell that protects them from malicious matter.
Ø The data is organized in the well defined
manner that provides the easier access of data to the user because sharing is
used in which various processes shares the memory with each other using the
inter process communication that allows the inter communication between the
shared processes and the data stored in memory uses the logical and physical organization in which data are divided into modules
that leads to internal and external fragmentation of the main memory such that
main memory frames are divided into modules for the programs allocation that is
known segmentation.
In this Assignment I tried to
concluded in addition to what studied in the lectures
No comments:
Post a Comment