0% found this document useful (0 votes)
18 views4 pages

Memory Management

ns

Uploaded by

Amna Nasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Memory Management

ns

Uploaded by

Amna Nasir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Memory management

Memory management is the function of a computer operating system responsible for managing the
computer's primary memory. This involves providing ways to allocate portions of memory to programs
at their request, and freeing it for reuse when no longer needed. The management of main memory is
critical to the computer system.

The memory management function of OS 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, and 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.

Single contiguous allocation: Single allocation is the simplest memory management technique. All the
computer's memory, usually with the exception of a small portion reserved for the operating system, is
available to the single application.

Partitioned allocation: Partitioned allocation divides primary memory into multiple memory partitions, usually
contiguous areas of memory. Each partition might contain all the information for a specific job or task.
Memory management consists of allocating a partition to a job when it starts and unallocated it when the job
ends.

Garbage collection is the automated allocation and deallocation of computer memory resources for a
program. This is generally implemented at the programming language level and is in opposition to manual
memory management, the explicit allocation and deallocation of computer memory resources. Region-based
memory management is an efficient variant of explicit memory management that can deallocate large groups
of objects simultaneously.

Swapping
Swapping is a mechanism in which a process can be swapped temporarily out of main memory
to a backing store , and then brought back into memory for continued execution.

Backing store is a usually a hard disk drive or any other secondary storage which fast in access
and large enough to accommodate copies of all memory images for all users. It must be capable
of providing direct access to these memory images.

Major time consuming part of swapping is transfer time. Total transfer time is directly
proportional to the amount of memory swapped. Let us assume that the user process is of size
100KB and the backing store is a standard hard disk with transfer rate of 1 MB per second. The
actual transfer of the 100K process to or from memory will take

100KB / 1000KB per second

Engr. Hammad Shahab Page 1


= 1/10 second

= 100 milliseconds

Fragmentation
Fragmentation is a phenomenon in which storage space is used inefficiently, reducing capacity or
performance and often both. The exact consequences of fragmentation depend on the specific system
of storage allocation in use and the particular form of fragmentation. In many cases, fragmentation
leads to storage space being "wasted", and in that case the term also refers to the wasted space itself.

When a computer program requests blocks of memory from the computer system, the blocks are
allocated in chunks. When the computer program is finished with a chunk, it can free the chunk back to
the system, making it available to later be allocated again to another or the same program. The size and
the amount of time a chunk is held by a program varies. During its lifespan, a computer program can
request and free many chunks of memory.

When a program is started, the free memory areas are long and contiguous. Over time and with use, the
long contiguous regions become fragmented into smaller and smaller contiguous areas. Eventually, it
may become impossible for the program to obtain large contiguous chunks of memory.

Engr. Hammad Shahab Page 2


There are three different but related forms of fragmentation: external fragmentation, internal
fragmentation, and data fragmentation, which can be present in isolation or conjunction. Fragmentation
is often accepted in return for improvements in speed or simplicity.

Internal fragmentation

Due to the rules governing memory allocation, more computer memory is sometimes allocated than is
needed. For example, memory can only be provided to programs in chunks divisible by 4, 8 or 16, and as
a result if a program requests perhaps 23 bytes, it will actually get a chunk of 32 bytes. When this
happens, the excess memory goes to
waste. In this scenario, the unusable
memory is contained within an
allocated region. This arrangement,
termed fixed partitions, suffers from
inefficient memory use - any process, no
matter how small, occupies an entire
partition. This waste is called internal
fragmentation.

Unlike other types of fragmentation,


internal fragmentation is difficult to
reclaim; usually the best way to
remove it is with a design change. For
example, in dynamic memory
allocation, memory pools drastically cut internal fragmentation by spreading the space overhead over a
larger number of objects.

External fragmentation

External fragmentation arises when free memory is separated into small blocks and is interspersed by
allocated memory. It is a weakness of certain storage allocation algorithms, when they fail to order
memory used by programs efficiently. The result is that, although free storage is available, it is
effectively unusable because it is divided into pieces that are too small individually to satisfy the
demands of the application. The term "external" refers to the fact that the unusable storage is outside
the allocated regions.

For example, consider a situation where in a program allocates 3 continuous blocks of memory and then
frees the middle block. The memory allocator can use this free block of memory for future allocations.
However, it cannot use this block if the memory to be allocated is larger in size than this free block.

Engr. Hammad Shahab Page 3


External fragmentation also occurs in file systems as many files of different sizes are created, change
size, and are deleted. The effect is even worse if a file which is divided into many small pieces is deleted,
because this leaves similarly small regions of free spaces.

Data fragmentation

Data fragmentation occurs when a collection of data in memory is broken up into many pieces that are
not close together. It is typically the result of attempting to insert a large object into storage that has
already suffered external fragmentation.

Defragmentation

Defragmentation is a process that reduces the amount of fragmentation. It does this by physically
organizing the contents of the mass storage device used to store files into the smallest number
of contiguous regions

Engr. Hammad Shahab Page 4

You might also like