0% found this document useful (0 votes)
6 views19 pages

Os Report

Uploaded by

ramsrini533
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)
6 views19 pages

Os Report

Uploaded by

ramsrini533
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/ 19

MEMORY FRAGMENTATION AND DEFRAGMENTATION

TECHNIQUES

21CSC202J - OPERATING SYSTEMS

A MINI-PROJECT REPORT

Submitted By

Adithya.V [RA2311027020118]
Jatin.D [RA12311027020104]
Manav [RA2311027020078]

in partial fulfilment for the award of the degree


of
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE AND ENGINEERING
of
FACULTY OF ENGINEERING AND TECHNOLOGY

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY RAMAPURAM


CAMPUS, CHENNAI-600089
OCTOBER 2024
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
(Deemed to be University U/S 3 of UGC Act, 1956)
BONAFIDE CERTIFICATE

Certified that this mini project report titled “MEMORY FREGMENTATION


AND DEFRAGMENTATION TECHNIQUES” is the bonafide work of
“ADITHYS (RA2311027020118),JATIN. D(RA2311027020104),
MANAVYAS(RA2311027020078)

SIGNATURE
Dr. Usha Ruby

Assistant Professor,

Computer Science and Engineering,


SRM Institute of Science and Technology,
Ramapuram Campus, Chennai.
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

RAMAPURAM, CHENNAI -600089

DECLARATION

We hereby declare that the entire work contained in this mini project report titled
“MEMORY FRAGMENTATION AND DEFRAGMENTATION
TECHNIQUES ” has been carried out by ADITHYA.V (RA2311027020118),
JATIN.D (RA2311027020104), MANAV (RA23110270120078) at SRM Institute
of Science and Technology, Ramapuram Campus, Chennai - 600089,

Place: Chennai

Date:
ABSTRACT

Memory fragmentation is a common issue in computing, where memory is

inefficiently allocated, leading to wasted space and reduced performance. This

report discusses memory fragmentation, its causes, and various defragmentation

techniques to optimize memory utilization. The project’s objective is to explore

defragmentation algorithms, evaluate their efficiency, and present practical

implementations. The scope covers both software and hardware requirements for

effectively managing memory. This project uses a simulated environment to

illustrate defragmentation techniques and their performance results.


TABLE OF CONTENTS
Chapter No. Title Page No.
ABSTRACT
INTRODUCTION 1
1 1.1 Overview 1
1.2 Problem Statement 1
1.3 Objective of the Project 2
1.4 Scope of the Project 2
SOFTWARE AND HARDWARE 10
SPECIFICATIONS
2 2.1 Hardware Requirements 10
2.2 Software Requirements 10
PROJECT DESCRIPTION 12
3 3.1 Introduction 12
3.2 Architecture Diagram 13
3.3 Algorithm Used 14
3.4 Advantages of Algorithm used 16
3.5 Explanation of the Project 39
3.6 Output Results 42
APPENDIX
CODE 49
CONCLUSION 49
MEMORY FRAGMENTATION AND DEFRAGMENTATION

TECHNIQUES

INTRODUCTION

1.1Overview

Memory fragmentation is a condition in computer memory management where

available memory is split into small, non-contiguous blocks, making it difficult to

allocate large chunks of memory. This phenomenon can lead to inefficient

utilization of memory, as the system might fail to allocate memory even when

enough free memory exists due to fragmentation.

Fragmentation can occur in two forms:

Internal Fragmentation: Happens when allocated memory blocks are larger than

requested, leaving unused space within allocated blocks.

External Fragmentation: Occurs when free memory is scattered in small blocks

across the memory, preventing the allocation of large contiguous blocks.

To combat fragmentation, various defragmentation techniques are employed to

consolidate free memory blocks.


1.2Problem Statement

Memory fragmentation poses significant challenges in systems requiring high

performance and efficient memory utilization. It can degrade system performance,

lead to crashes, or cause the system to slow down due to frequent memory

allocation failures. Thus, defragmentation techniques are necessary to optimize

memory usage and improve system stability and efficiency.

1.3 Objective of the Project

The primary objective of this project is to analyze memory fragmentation issues

and explore different defragmentation techniques. This includes understanding the

causes and consequences of memory fragmentation, evaluating algorithms to

address it, and implementing a solution that efficiently manages memory to reduce

or eliminate fragmentation.

1.4 Scope of the Project


This project focuses on understanding and solving memory fragmentation issues in

computer systems. It will cover the different types of fragmentation, examine

multiple defragmentation algorithms, and present a practical implementation that

optimizes memory usage. The project’s scope extends to modern operating

systems, embedded systems, and environments where memory is a limited

resource.

SOFTWARE AND HARDWARE SPECIFICATIONS

2.1 Hardware Requirements

Processor: Intel i5 or equivalent

Memory: 8GB RAM

Storage: 256GB SSD

Other: Standard keyboard, mouse, and display monitor

2.2 Software Requirements

Operating System: Windows 10 or Linux-based OS

Programming Language: C/C++ or Python


Compiler/Interpreter: GCC or Python InterpreterIDE: Visual Studio Code or

PyCharm

Version Control: Git (optional)

PROJECT DESCRIPTION

3.1 Introduction

The project aims to demonstrate how memory fragmentation occurs and how

defragmentation techniques can be used to optimize memory usage. The solution

involves simulating memory allocation and deallocation, observing fragmentation

patterns, and applying defragmentation algorithms to consolidate free space.

3.2 Architecture Diagram

The architecture diagram typically consists of three main components:

Memory Manager: Responsible for allocating and deallocating memory blocks.

Fragmentation Detector: Monitors and identifies fragmentation in memory.

Defragmentation Module: Implements algorithms to reorganize and consolidate

memory.
3.3 Algorithm Used

In this project, we use a Best Fit Algorithm to allocate memory and a Compaction

Algorithm for defragmentation:

Best Fit Algorithm: It finds the smallest free block that is large enough to

accommodate the requested memory size, thus minimizing internal fragmentation.

Compaction Algorithm: This algorithm moves allocated memory blocks to create

larger contiguous free memory regions, reducing external fragmentation.

3.4 Advantages of Algorithm Used

Best Fit Algorithm:

Efficient memory utilization by minimizing internal fragmentation.

Suitable for environments with varying allocation sizes.

Compaction Algorithm:

Reduces external fragmentation by consolidating free memory blocks.


Improves the ability to allocate larger memory blocks without encountering

memory allocation failures.

3.5 Explanation of the Project

Memory Allocation Simulation: The project simulates dynamic memory allocation,

where memory blocks are allocated and deallocated in real-time.

Fragmentation Monitoring: After several allocations and deallocations, the system

analyzes the state of the memory to detect fragmentation.

Defragmentation Process: Once fragmentation is detected, the defragmentation

module is triggered to reorganize memory, consolidating free spaces to allow for

larger allocations.

3.6 Output Results

The output of the project will include:

Visual representation of memory before and after fragmentation.

Detailed logs showing how memory blocks were allocated and deallocated.
Performance metrics before and after applying the defragmentation algorithm,

including memory usage efficiency and time taken to complete the

defragmentation process.

APPENDIX

Source Code

The source code for the project includes modules for memory management,

fragmentation detection, and defragmentation. Here is a simplified version of the

core logic:

CODE

#include <stdio.h>

#include <stdlib.h>

#define MAX_BLOCKS 10

Typedef struct {
Int size;

Int allocated;

} Block;

Block memory[MAX_BLOCKS];

// Function to initialize memory blocks

Void init_memory(int sizes[]) {

For (int i = 0; i < MAX_BLOCKS; i++) {

Memory[i].size = sizes[i];

Memory[i].allocated = 0;

// Best fit allocation function

Void best_fit(int request_size) {


Int best_index = -1;

Int best_fit_size = 10000;

For (int i = 0; i < MAX_BLOCKS; i++) {

If (!memory[i].allocated && memory[i].size >= request_size &&

memory[i].size < best_fit_size) {

Best_index = i;

Best_fit_size = memory[i].size;

If (best_index != -1) {

Memory[best_index].allocated = 1;

Printf(“Memory allocated at block %d\n”, best_index);

} else {

Printf(“Memory allocation failed\n”);


}

// Function to simulate defragmentation

Void defragment() {

Int last_allocated = -1;

For (int i = 0; i < MAX_BLOCKS; i++) {

If (memory[i].allocated && last_allocated != -1) {

Memory[last_allocated].size += memory[i].size;

Memory[i].size = 0;

If (memory[i].allocated) {

Last_allocated = i;

Printf(“Memory defragmented\n”);
}

Int main() {

Int sizes[MAX_BLOCKS] = {100, 200, 300, 400, 500, 600, 700, 800, 900,

1000};

Init_memory(sizes);

Best_fit(350);

Best_fit(450);

Defragment();

return 0;

}
Output:

Memory allocated at block 3

Memory allocated at block 4

Memory defragmented

=== Code Execution Successful ===

This is a simple implementation that demonstrates memory allocation using the

Best Fit algorithm and defragmentation through memory compaction.


Conclusion

The project successfully demonstrates how memory fragmentation occurs and the

effectiveness of defragmentation techniques in optimizing memory usage. By

employing the Best Fit and Compaction algorithms, the system achieves better

memory allocation efficiency and reduces fragmentation over time. The

implemented solution can be further extended to include more advanced memory

management techniques in future developments.

You might also like