Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

SAUGAT ADHIKARI 18029221

Module Code & Module Title

CS5001NA Networks and Operating System

Assessment Weightage & Type

40% Individual Coursework

Year and Semester

2019-20 Autumn

Student Name: Saugat Adhikari

London Met ID: 18029221

College ID: np01nt4a180178

Assignment Due Date: May 29, 2020

Assignment Submission Date: May 22, 2020

Word Count (TASK B): 2270

I confirm that I understand my coursework needs to be submitted online via Google


Classroom under the relevant module page before the deadline for my assignment to be
accepted and marked. I am fully aware that late submissions will be treated as non-
submission and a mark of zero will be awarded.
SAUGAT ADHIKARI 18029221

Table of Contents

1. Task A ........................................................................................................................... 1
1.1 Introduction ................................................................................................................. 1
1.2 Script ........................................................................................................................... 2
1.3 Testing......................................................................................................................... 9
1.4 Contents of three files: (TEXTS)................................................................................ 26
• PK: ....................................................................................................................... 26
• VK: ....................................................................................................................... 26
• RT: ....................................................................................................................... 26
1.5 Conclusion ............................................................................................................ 27
2. Task B............................................................................................................................. 28
2.1 Introduction ............................................................................................................... 28
2.2 Aims and Objectives .................................................................................................. 29
2.3 Background: .............................................................................................................. 30
2.3.1 Hierarchy of Memory Management ..................................................................... 32
2.3.3 Locality of Reference .......................................................................................... 34
2.3.3 Memory Allocation ............................................................................................. 35
2.3.4 Dynamic Storage Allocation ................................................................................ 38
2.3.5 Description of Paging and Segmentation ............................................................. 40
2.4 Conclusion................................................................................................................. 44
3. References ................................................................................................................... 45
4. Bibliography ................................................................................................................ 46
5. Appendix ........................................................................................................................ 47
5.1 Memory Controller ............................................................................................... 47
5.2 Virtual Memory .................................................................................................... 48
5.3 Locality of Reference ............................................................................................ 50
SAUGAT ADHIKARI 18029221

Table of Figures

Figure 1: Introduction to Shell (Guru99, 2020) ...................................................................... 1


Figure 2: Test no. 1 ............................................................................................................... 9
Figure 3: Test no. 2 ............................................................................................................. 10
Figure 4: Test no. 3 ............................................................................................................. 11
Figure 5: Test no. 4 ............................................................................................................. 13
Figure 6: Test no. 5 ............................................................................................................. 14
Figure 7: Test no. 6 ............................................................................................................. 15
Figure 8: Test no. 7 ............................................................................................................. 16
Figure 9: Test no. 8 ............................................................................................................. 17
Figure 10: Test no. 9 ........................................................................................................... 18
Figure 11: Test no. 10 ......................................................................................................... 19
Figure 12: Test no. 11 ......................................................................................................... 20
Figure 13: Test no.12 .......................................................................................................... 21
Figure 14: Test no. 13 ......................................................................................................... 22
Figure 15: Test no. 14 ......................................................................................................... 23
Figure 16: Test no. 15 ......................................................................................................... 24
Figure 17: Test no. 16 ......................................................................................................... 25
Figure 18: Memory Management in Uniprogramming System (Ahmed, 2016) .................... 30
Figure 19: Memory Management in Multiprogramming System (Ahmed, 2016) ................. 31
Figure 20: Memory Hierarchy (Jain et al., 2018) ................................................................. 32
Figure 21: Random Access Memory (RAM) (Villinger, 2019) ............................................ 33
Figure 22: Memory Allocation (Mali et al., 2019) ............................................................... 35
Figure 23: Memory Management Techniques Comparison (Muazzam & Nauman, 2013) .... 37
Figure 24: Sequential memory blocks (Muhammad , 2016) ................................................. 39
Figure 25: Paged Memory Management (Bower, 2015)....................................................... 41
Figure 26: Segmentation in OS (M. et al., 2016) .................................................................. 42
Figure 27:DDR4 Memory Controller (Montage Technology, 2019) .................................... 47
Figure 28: General Layout of Virtual Memory (Abraham et al., 2012) ................................ 49
SAUGAT ADHIKARI 18029221

Table of Tables

Table 1: Testing no. 1............................................................................................................ 9


Table 2: Testing no. 2.......................................................................................................... 10
Table 3: Testing no. 3.......................................................................................................... 11
Table 4: Testing no. 4.......................................................................................................... 12
Table 5: Testing no. 5.......................................................................................................... 14
Table 6: Testing no. 6.......................................................................................................... 15
Table 7: Testing no. 7.......................................................................................................... 16
Table 8: Testing no. 8.......................................................................................................... 17
Table 9: Testing no. 9.......................................................................................................... 18
Table 10: Testing no. 10 ...................................................................................................... 19
Table 11: Testing no. 11 ...................................................................................................... 20
Table 12: Testing no. 12 ...................................................................................................... 21
Table 13: Testing no. 13 ...................................................................................................... 22
Table 14: Testing no. 14 ...................................................................................................... 23
Table 15: Testing no. 15 ...................................................................................................... 24
Table 16: Testing no. 16 ...................................................................................................... 25
Table 17: Comparison between Static and Dynamic Memory Allocation (Mali et al., 2019) 36
SAUGAT ADHIKARI 18029221

1. Task A
1.1 Introduction

A shell script is a Computer program that is supposed to be managed by the UNIX shell which
is a charge line translator. Standard shell-script activities include record management, program
execution, and text printing. A shell script can offer an advantageous variety of a system order
where special context conditions, paying alternatives, or post-transforming are added, but in a
way that also enables the new script to go around like a fully normal UNIX request. (Kaushik
et al., 2014) There are many advantages of shell programming; such as it is easy to use and has
an interactive debugging and shell scripts can be executed effortlessly between many modern
UNIX/ Linux/ BSD/ Mac OS X operating systems. (Kaushik et al., 2014)

Figure 1: Introduction to Shell (Guru99, 2020)

The objective of this coursework is to develop a program using a bash shell script that
implements interaction with the UNIX environment in a friendly manner and shows proper
knowledge of input/output operations. There are various types of shells available inside the
UNIX system; such as Bash Shell, Bourne Shell, Korn Shell, Z Shell, C Shell, etc. The code in
this coursework will be developed in a bash shell inside a Debian command-line environment.
Bourne again shell or Bash shell is used for this coursework as it supports Job control,
command-line editing, unlimited size command history, etc.

1|Page
SAUGAT ADHIKARI 18029221

1.2 Script

#!/bin/bash
#
SAUGAT ADHIKARI L2N7 [18029221]

# Storing the user arguments in global variables.


user_name=$1
user_id=$2

# Validating the number and nature of arguments passed into the function by
the user. The program will exit everytime until the correct
# number of parameters are passed.
# Declaring a regural expresssion that holds any number from 0 to 9.
re='^[0-9]+$'

# If both the username and id are left blank, the following message will
pop up.
if [[ $user_name == "" && $user_id == "" ]]
then
echo -e "\n No parameters found. Please enter first name and then the ID
number sperated by a space. \n"
exit
# Checking if the user provides more than two arguments.
elif [[ $# -gt 2 ]]
then
echo -e "\n Invalid number of parameters found.Please enter first name
and then the ID number sperated by a space. \n"
exit
# Checking if the user provides less than two arguments.
elif [[ $# -lt 2 ]]
then
echo -e "\n Invalid number of parameters found.Please enter first name
and then the ID number sperated by a space. \n"
exit
# Checking the username input of the user against the regular expression.
If it is true, then a invalid input message pops up.
elif [[ $user_name =~ $re ]]
then
echo -e "Invalid input. Username cannot be a number. \n"
echo -e "Please try again. Please enter first name and then the ID
number sperated by a space. \n"
exit
fi

# Checking if the user inputs number when asked for user ID.
until [[ $user_id =~ $re ]]
do
echo -e "Invalid input. User ID cannot be a string. \n"
echo -e "Please try again. Please enter first name and then the ID
number sperated by a space. \n"
exit
done

# Function to start the program with validation of secret key.


program_starter() {

# Declaring a secret key for user verification.


secret_key=9841

2|Page
SAUGAT ADHIKARI 18029221

# The chances provided for secret key input are five.


# Using while loop that provides user with only five chances.
chance=5
while [ $chance -ge 1 ]
do
echo
echo -e "Please enter the secret key :- \c"
read user_key
# If the user provides a valid secret key, he/she will be greeted and will
enter the program.
if [[ $user_key == $secret_key ]]
then
echo
echo -e "You have been successfully verified. \n"
now=$(date)
echo -e "\t\t\t Welcome [$user_id] Mr/s $user_name to the
program. \n"
echo -e "\t\t\t The current date and time is:- $now \n"
# If the user provides correct secret key, the loop must be broken and the
program must continue.
break
# If the user provides an empty secret key, this message will pop up.
elif [ ${#user_key} == 0 ]
then
echo -e "Invalid input. Please do not leave the key input
blank. \n"
# The chance of user will decrease everytime he/she enters an invalid
secret key.
chance=`expr $chance - 1 `
echo -e "You have $chance chances left. \n"

elif [ $user_key != $secret_key ]


then
echo -e "Sorry, you entered an invalid secret key. \n"
chance=`expr $chance - 1 `
echo -e "You have $chance chances left. \n"
fi

#when all the five chances are exploited, the program exits on the user.
if [ $chance == 0 ]
then
echo -e "Sorry, You cannot be verified. \n"
echo -e "Bye $user_name! \n"
figlet BYE!!
# This lets the program sleep for a second before exiting.
sleep 1
exit
fi
done
}

# Function for storing country names and codes along with verifications.
country_choice() {
# This is a table that depicts all the available countries and codes.
echo -e "These are the available countries and their respective codes. \n"
echo "****************************************"
echo -e "COUNTRY \t\t CODE"
echo "---------------------------------------"
echo -e "Australia \t\t AUS"

3|Page
SAUGAT ADHIKARI 18029221

echo -e "Bangladesh \t\t BAN"


echo -e "Nepal \t\t\t NEP"
echo -e "India \t\t\t IND"
echo -e "England \t\t ENG"
echo -e "*************************************** \n"

# Predeclaring England as the favourite cricket team.


fav_team="ENG"

# Declaring a function that asks user for the best cricket team in order to
decrease redundacy.
team_choice () {
echo -e "Please enter the code(case sensitive) of the best cricket team:-
\c"
read user_team
}

team_choice

# until loop that doesnt break ends until the user input is three
characters.
until [ ${#user_team} == 3 ]
do
echo -e "Invalid input. Please enter the three letter code. \n"
team_choice
done

# Until loops goes on executing until the team selected by the user is
England (favourite team).
until [[ $user_team == $fav_team ]]
do
echo -e "Unfortunately, you have choosed the wrong team. \n"
team_choice
done

# Some information to be displayed when the user selects the correct


cricket team.
echo -e "\t\t\tCongratulations! You have choosed the correct team. \n"
echo -e "Here is some information about England National Cricket Team: \n"
echo -e "\t\t\t\t England National Crictet Team "
echo
echo "---------------------------------------------------------------------
-------------------------------------------"
echo -e "As of 16 February 2020, England have played 1,022 Test matches,
winning 371 and losing 304 (with 347 draws).
\n In Test series against Australia, England play for The Ashes,
one of the most famous trophies in all of sport,
\n and they have won the urn on 32 occasions. England have also
played 746 ODIs, winning 375."
echo -e "------------------------------------------------------------------
---------------------------------------------- \n"

#Function for displaying the cricket players,codes and user input


validations.
player_choice(){
echo -e "These are the available five-star cricket players and their
respective codes. \n"
echo "***************************************"

4|Page
SAUGAT ADHIKARI 18029221

echo -e "PLAYER \t\t\t CODE"


echo "---------------------------------------"
echo -e "Paras Khadka \t\t PK"
echo -e "Virat Kohli \t\t VK"
echo -e "David Warner \t\t DW"
echo -e "Ben Stokes \t\t BS"
echo -e "Ross Taylor \t\t RT"
echo -e "*************************************** \n"

name_loop

# Defining a custom prompt for the select loop inside a shell script, using
the PS3 environment variable.
PS3="Please choose one of the following option:- "
select user_option in $player1 $player2 $player3
do
# This is a case function that matches the user input against various
conditions.
case $user_option in
$player1 )
# the following condition checks if the stated file exists in the current
directory or not.
if [ -e $player1.txt ]
then
# If the file is available, this command reads into the file.
cat $player1.txt
program_replay
else
echo -e "The reuqested file cannot be
found. You will have to start again by the choosing the best cricket team.
\n"
sleep 1
# If the file requested by the user cannot be found, the program restarts
itself back to choosing best team step.
country_choice
player_choice

fi
break
;;

$player2 )
if [ -e $player2.txt ]
then
cat $player2.txt
program_replay
else
echo -e "The reuqested file cannot be
found. You will have to start again by the choosing the best cricket team.
\n"
sleep 1
country_choice
player_choice

fi
break
;;

$player3 )
if [ -e $player3.txt ]
then

5|Page
SAUGAT ADHIKARI 18029221

cat $player3.txt
program_replay
else
echo -e "The reuqested file cannot be
found. You will have to start again by the choosing the best cricket team.
\n"
sleep 1
country_choice
player_choice

fi
break

;;
# Checking for any invalid input by the user other than the provided
options.
* )
echo -e "This an invalid input. Please try again.
Choose from option 1,2 and 3. \n"

;;
# End of case.
esac
# End of select.
done

# Funtion that prompts user to enter the code for three best cricketers.
name_loop(){
echo -e "Enter the codes(case sensitive) for three best cricketers
separated by a space:- \c"
read player1 player2 player3
read player1 player2 player3
# Calling the named function that validates the user input against the
appropriate player codes.
player_valid
}

player_valid () {
# Declaring a flag variable that is used as a counter into the while loop.
flag_var=1
while [ $flag_var = 1 ]
do
# Validating if the user provides all three required codes or leaves any
argument empty.
if [[ -z $player1 ]] | [[ -z $player2 ]] |
[[ -z $player3 ]]
then
echo -e "You have entered invalid
number of codes. Please enter all three codes. \n"
echo -e "NOTE: The codes are case
sensitive and must be sperated by a space. \n"
name_loop
else
# while loop ends with the following declaration.
flag_var=0
fi
done

6|Page
SAUGAT ADHIKARI 18029221

# Validating the user input codes against the available codes of the
cricket players.
until [ $player1 == "VK" ] || [ $player1 == "PK" ]
|| [ $player1 == "DW" ] || [ $player1 == "BS" ] || [ $player1 == "RT" ]
do
echo -e "The first code you have entered is
wrong. Please refer to the table and try again. \n"
name_loop
done

until [ $player2 == "VK" ] || [ $player2 == "PK" ]


|| [ $player3 == "DW" ] || [ $player2 == "BS" ] || [ $player2 == "RT" ]
do
echo -e "The second code you have entered is
wrong. Please refer to the table and try again. \n"
name_loop
done

until [ $player3 == "VK" ] || [ $player3 == "PK" ]


|| [ $player3 == "DW" ] || [ $player3 == "BS" ] || [ $player3 == "RT" ]
do
echo -e "The third code you have entered is
wrong. Please refer to the table and try again. \n"
name_loop
done
}

# Function that prompts the user if he/she wants to restarts the program or
just end it.
program_replay() {

echo -e "Do you want to replay the program?(Y/N) \c"


read user_replay
# Calling the named function that validates the user input on whether or
not he/she wants to replay the program.
replay_verify
}

# Funtion that validates the input of the user.


replay_verify(){
case $user_replay in
"Y" )
echo -e "That's good. Lets go again. \n"
sleep 1
country_choice
player_choice
;;

"N" )
echo -e "Thank you $user_name for running this program. \n"
echo
figlet BYE!
sleep 1
exit
;;

* )

7|Page
SAUGAT ADHIKARI 18029221

echo -e "Invalid input. Please choose between 'Y/N'. \n"


program_replay
;;
esac
}

# Calling all the required functions in the appropriate order.


program_starter
country_choice
player_choice
program_replay

8|Page
SAUGAT ADHIKARI 18029221

1.3 Testing

Test No. 1 Testing if the script runs without the input


of the first name.

Input bash 18029221cw2partii.txt 12

Expected Output The script must not let the user enter the
program and prompt an error message
regarding the missing arguments.

Actual Output The script did not let the user enter the
program and showed an alert message
regarding the missing arguments.
Table 1: Testing no. 1

Figure 2: Test no. 1

9|Page
SAUGAT ADHIKARI 18029221

Test No. 2 Testing if the script executes and asks for


a secret with the username and ID
provided by the user.

Input bash 18029221cw2partii.txt Saugat 12

Expected Output The script must execute and ask for the secret
key to enter the program.

Actual Output The script did execute and asked the user for
the secret key to enter the program.
Table 2: Testing no. 2

Figure 3: Test no. 2

10 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 3 Testing if the program starts without the


valid secret key (9841).

Input 123

Expected Output The program must not start, and the user
must be alerted about the wrong secret key.

Actual Output The program did not start and showed an


invalid secret key alert to the user.
Table 3: Testing no. 3

Figure 4: Test no. 3

11 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 4 Testing if the program exits after the user


enters the wrong secret key for five times.

Input 123, 756, 9871, 8766, 10

Expected Output The program must provide the user with only
five chances and finally exit.

Actual Output The program did provide the user with only five
chances and exit at the end.
Table 4: Testing no. 4

12 | P a g e
SAUGAT ADHIKARI 18029221

Figure 5: Test no. 4

13 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 5 Testing if the program alerts user when the


user inputs wrong format of the code.

Input AS

Expected Output The program must alert the user about the
correct format of the code and let the user try
again until correct.

Actual Output The program did alert the user about the correct
format of the code and let the user try until
correct.
Table 5: Testing no. 5

Figure 6: Test no. 5

14 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 6 Testing if the program alerts user when the


user inputs wrong team.

Input BAN

Expected Output The program must alert the user about the wrong
team selection and let the user try again until
correct.

Actual Output The program did alert the user about the wrong
team selection and let the user try until correct.
Table 6: Testing no. 6

Figure 7: Test no. 6

15 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 7 Testing if the program redirects the user


back to the choice of best team step if the user
chooses the wrong player with no matching
file.

Input 3) BS

Expected Output The program must alert the user about his/her
wrong choice and unavailability of the file and
then redirect the user back to the part where
he/she have to choose the best team.

Actual Output The program did alert the user about the wrong
choice of the player and unavailability of the file
and then redirected the user back to the part
where he/she have to choose the best team.
Table 7: Testing no. 7

Figure 8: Test no. 7

16 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 8 Testing if the program welcomes the user into


the program when the correct secret key is
provided by the user.

Input 9841

Expected Output The program must welcome the user with


his/her id, first name and show the current date
and time.

Actual Output The program did welcome the user into the
program by his/her id, first name and date and
time of execution.
Table 8: Testing no. 8

Figure 9: Test no. 8

17 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 9 Testing if the program displays some


information about the best team(ENG) when
the user enters the correct team.

Input ENG

Expected Output The program must congratulate the user on


choosing the correct team and show some
information about that team.

Actual Output The program did congratulate the user and


displayed information about the best team.
Table 9: Testing no. 9

Figure 10: Test no. 9

18 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 10 Testing if the program alerts the user when


the input is four player codes instead of
required three.

Input PK VK RT DW

Expected Output The program must alert the user about wrong
number of player codes and let him/her try until
correct number of codes are entered.

Actual Output The program did alert the user about wrong
number of player codes and let him/her try until
correct number of codes are entered.
Table 10: Testing no. 10

Figure 11: Test no. 10

19 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 11 Testing if the program shows the information


about the selected player if available from an
external text file.

Input 1) PK

Expected Output The program must show the information about


the selected player (Paras Khadka) from an
external text file (PK).

Actual Output The program did display the information about


the selected player (Paras Khadka) from an
external text file (PK).
Table 11: Testing no. 11

Figure 12: Test no. 11

20 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 12 Testing if the program alerts the user about


the wrong option and let the user try until the
correct option is selected.

Input 5

Expected Output The program must alert the user about the wrong
option and let the user try until the correct option
is selected.

Actual Output The program did alert the user about the wrong
option and let the user try until the correct option
is selected.
Table 12: Testing no. 12

Figure 13: Test no.12

21 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 13 Testing if the program asks the user if he/she


want to replay the program and replay the
program if he/she enters Y.

Input Y

Expected Output The program must ask the user if he/she wants
to replay the program and do so if he/she enters
Y.

Actual Output The program did ask the user if he/she wants to
replay the program and did replayed the
program when the input is Y.
Table 13: Testing no. 13

Figure 14: Test no. 13

22 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 14 Testing if the program exits the program if


the user doesn’t want to replay the program.

Input N

Expected Output The program must exit if the user doesn’t want
to replay the program.

Actual Output The program did exit when the user entered N.

Table 14: Testing no. 14

Figure 15: Test no. 14

23 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 15 Testing if the program alerts the user about


wrong input if the user enters invalid input
when the replay program option is prompted.

Input Nil

Expected Output The program must alert the user about the wrong
input and then ask the question again.

Actual Output The program did alert the user about his/her
wrong input and prompted again about the
replay program.
Table 15: Testing no. 15

Figure 16: Test no. 15

24 | P a g e
SAUGAT ADHIKARI 18029221

Test No. 16 Testing if the program starts when the user


inputs both string in username and userID.

Input bash 18029221cw2partii.txt Saugat Ram

Expected Output The program must alert the user about the wrong
input that userID cannot be a string.

Actual Output The program did alert the user about the wrong
input that userID cannot be a string.
Table 16: Testing no. 16

Figure 17: Test no. 16

25 | P a g e
SAUGAT ADHIKARI 18029221

1.4 Contents of three files: (TEXTS)

• PK:

. Paras Khadka is a Nepalese cricketer and former captain of the Nepalese cricket team.

All-rounder Khadka is a right-handed batsman, a right-arm medium-fast bowler, and


an occasional off-break bowler.

• VK:

Virat Kohli is a famous Indian Cricketer who currently captains the Indian Cricket
Team.

He gained optimum popularity when he married famous Bollywood actress Anushka


Sharma.

• RT:

Luteru Ross Poutoa Lote Taylor is an international cricketer and former captain of the
New Zealand national team.

Batting predominantly at number four, he is the leading run-scorer for New Zealand in
Test cricket.

26 | P a g e
SAUGAT ADHIKARI 18029221

1.5 Conclusion

The report is developed by the culmination of good literature, research and meets the
coursework guidelines. The program developed in this coursework was made and executed in
a bash shell. The shell script follows all the requirements of the coursework; i.e.
implementation of all the required control structures ( if-else, until, while, case and select) and
unhindered running of the program. Similarly, the code is not long and repetitive and is well
commented on required places, uses appropriate variable names, provides complete error
checking for user input and alerts error messages at the user when required. Furthermore,
several functions have been declared and called upon when required. Finally, the
documentation depicts a brief introduction of the shell environment, along with the whole code
and an adequate number of testing scenarios of both valid and invalid input. Thus, this
coursework has helped in developing a shell script that handles and executes simple
input/output operations.

27 | P a g e
SAUGAT ADHIKARI 18029221

2. Task B

2.1 Introduction

Now a days the computer science markets are experiencing major changes as new innovations
are being developed, heading towards big data etc. Modern computer systems must conform to
specifications, such as efficient memory management, resource management, efficient
execution process, virtual memory management, effective inter-process connectivity, decent
user interface, etc (Patil & Irabashetti, 2014). Memory Management is a very complex aspect
of operating system architecture as it is physical level related. It is loosely divided into three
parts: memory management of the hardware, operating system memory management, and
memory management at the application level (Patil & Irabashetti, 2014). Memory management
is a method of allocating memory during runtime of the program, using it, and releasing it when
finished with it. The key aim of this is to control machine level computer memory (Gandotra,
2015).

This is a technical report that covers all the major components of Memory Management; such
as, History of memory management, hierarchy of memory management, memory allocation
and its techniques, virtual memory, etc. The report shows the in-depth working mechanism of
various memory management techniques that are used in a computer system along with
comparisons and analysis.

28 | P a g e
SAUGAT ADHIKARI 18029221

2.2 Aims and Objectives

Aims:
➢ The aim of this report was to facilitate the reader with a technical report that depicts all
the techniques and concepts under Memory Management.
➢ The aim of this report was to demonstrate that genuine and adequate amount of research
materials have been referenced and studied for the completion of this report.

Objectives:
➢ To briefly define the nature and requirements of this technical report.
➢ To provide a brief history of memory management and computer memory in general.
➢ To illustrate the meaning of memory management and its importance in computer
systems.
➢ To demonstrate various memory allocation techniques that are used in memory
management process.
➢ To compare the working mechanism of these techniques along with their pros and cons.
➢ To enlighten reader with the importance of memory management and its requirement
in modern computing advancements.

29 | P a g e
SAUGAT ADHIKARI 18029221

2.3 Background:

In the early days of computers in 1945, John von Neumann wrote a draft of a computer system
called the EDVAC that had a memory device connected to an arithmetic device and a control
unit. The 1960s and 1970s saw the widespread use of magnetic core memory that had no
moving components, unlike drum memories, which allowed unlimited access to every word in
memory (Nair, 2015). During the 1970s, central memory was replaced by memories in
semiconductors. The memory industry has been revolutionized by the advent of the dynamic
random-access memory (DRAM), in particular the single transistor DRAM cell (R. H., 1968).

Two types of systems are typically available, Uniprogramming and Multiprogramming.


Uniprogramming systems are devices that split memory into two parts (Ahmed, 2016). The
first portion of the memory contains operating system and the second section of the memory
includes the programs being executed at the moment. Similar to the Uniprogramming,
multiprogramming systems are devices that split memory into two parts but unlike
Uniprogramming, in this system the user part of the memory is further divided into multiple
sub-parts or sub-portions (Ahmed, 2016).

Figure 18: Memory Management in Uniprogramming System (Ahmed, 2016)

30 | P a g e
SAUGAT ADHIKARI 18029221

Figure 19: Memory Management in Multiprogramming System (Ahmed, 2016)

31 | P a g e
SAUGAT ADHIKARI 18029221

2.3.1 Hierarchy of Memory Management

Memory Hierarchy is an idea necessary for the CPU to control the data. Memory Hierarchy is
a computing concept used by scientists to describe various ways that a program manages
memory, whether it is transient or permanent (Jain et al., 2018). In the Hierarchy below,
computer memory is defined:

Figure 20: Memory Hierarchy (Jain et al., 2018)

1. Registry Files:

Current processors use register files to store the data, and also spread transitional
computation results in Memory Hierarchy. The Registry Files is the maximum amount
in various ways (Jain et al., 2018). Register Files are agreed upon and regulated by
contradictory criteria. The strain on Register Files is strong in many thread processors
such that a huge amount of thread background is billeted Register Files will be shielded
from simple errors and it is also significant as any soft error propagates easily to another
device (Jain et al., 2018).

32 | P a g e
SAUGAT ADHIKARI 18029221

2. Cache Systems:

But with the technology's accuracy, microprocessors are often seen as faster than the
Main Memory. Storage access time is a slow blockage in the application's total
performance (Jain et al., 2018). One way this issue is so complicated is by inserting a
limited high-speed buffer memory between the supercomputer and the main memory.
In short, such a buffer is usually referred to as cache or archive (Jain et al., 2018).
Mainly, cache memory is divided into three levels: Level 1 (L1), Level 2 (L2) and Level
3 (L3).

3. Random Access Memory (RAM):

Random Access Memory is the location (hardware) on a computer where the present
configuration of the operating system, data and application programs is stored so that
the device's processor can easily access them for the actual image used inside the
application (Jain et al., 2018)s. RAM is much faster than all of this in reading and
writing from any form of storage in a computer (hard disk, CD -ROM, and floppy disk)
(Jain et al., 2018).

Figure 21: Random Access Memory (RAM) (Villinger, 2019)

33 | P a g e
SAUGAT ADHIKARI 18029221

4. Hard Disk:

Hard disk drives are energy-independent computer memory, fairly inexpensive and
have a large size. HDD uses one or two disks on a standard spindle, known as the disk
pack. Every plate is covered by a magnetic layer on which a magnetic head stores and
reads information (Toncho & Yordanka, 2018).

2.3.3 Locality of Reference

The word locality of reference refers to the fact that the sequence of memory addresses
accessed by a program during its execution typically has some predictability. Programs are
known to show temporal localization if they several times visit the same memory location
within a short time span (Padua & Pingali, 2011). There are three kinds of locality of reference:
temporal, spatial, and network. Brief introduction of different types of locality of reference is
provided here.

Cache memories exploit the temporal and spatial reference position to provide programmers
with the output features of a massive, powerful memory device but at affordable cost. The key
is a hierarchical management structure, generally known as the hierarchy of memories (Padua
& Pingali, 2011).

34 | P a g e
SAUGAT ADHIKARI 18029221

2.3.3 Memory Allocation

Memory management maintains track of of and every memory position, regardless of whether
it's allocated to any method or free. It determines how much memory to delegate to processes.
It decides at what time which process will get the memory. Whenever some memory is freed
or unallocated, it tracks and updates the status accordingly (Mali et al., 2019). Most computer
systems use two techniques for memory allocation as shown below:

Figure 22: Memory Allocation (Mali et al., 2019)

1. Static Memory Allocation:

In Static memory allocation, the memory is allocated to the variables of the program
at the beginning of execution. In this, even though much of the memory is not used
in a specific program instance or variable, we should not use reserved memory for
any other purpose (Mali et al., 2019).

2. Dynamic Memory Allocation:

Manual Memory Control is also known as Dynamic Memory Allocation. The


memory is reserved to runtime in DMA. It is allocated whenever system, code, data,
variable requests with the necessary number of bytes are needed (Mali et al., 2019).

35 | P a g e
SAUGAT ADHIKARI 18029221

Various memory management strategies can be used: single contiguous allocation,


partitioned allocation, Paged memory management or segmented memory
management (Tamunoomie & Ledisi, 2015).

Static Memory Allocation Dynamic Memory Allocation

Allocation is done before the program is Allocation is done while the program is
executed. executing.

There is no memory reusability. There is abundant memory reusability.

Stack data structure is used for implementing Heap data structure is used for implementing
static memory allocation. dynamic memory allocation.

Faster execution than dynamic. Slower execution than static.

It is best if required size is known in advance. It is best if we don’t have knowledge about
how much memory is required.
Table 17: Comparison between Static and Dynamic Memory Allocation (Mali et al., 2019)

Single Contiguous Allocation:

Single distribution is the easiest method for handling memories. The entire
computer's memory is accessible to the single program, usually except for a limited
portion reserved for the operating system (Tamunoomie & Ledisi, 2015). A device
that uses a single contiguous allocation can also be multitasking by switching
memory contents to differentiate between applications. This method was used in
early versions of the Music operating system (Tamunoomie & Ledisi, 2015).

Partitioned Allocation:

Partitioned division splits the main memory into several partitions of memory,
typically adjacent memory regions. Every partition may contain all of the
information for a particular job or mission. Memory management involves

36 | P a g e
SAUGAT ADHIKARI 18029221

assigning a partition to a task as it begins and unallocating it until the task finishes
(Tamunoomie & Ledisi, 2015).

Figure 21 depicts the differences between various memory allocation techniques


used in memory management.

Figure 23: Memory Management Techniques Comparison (Muazzam & Nauman, 2013)

37 | P a g e
SAUGAT ADHIKARI 18029221

2.3.4 Dynamic Storage Allocation

Because of the importance of dynamic memory management in the operating system, both
conventional and modern memory allocation algorithms use dynamic memory allocation
schemes to assign resources at runtime from the heap (Puaut, 2002). Sequential Fit algorithm,
as the name implies, uses the free blocks of memory in linear order in the form of a list called
free list. And from this free list memory blocks are assigned using pointer in various ways
depending on the condition in hand (Muhammad , 2016). There are four different strategies
used by sequential fit algorithm as discussed below:

First-Fit: First fit is the simplest technique followed by sequential fit, as the first available
memory block that is greater or equal to the required memory is rendered irrelevant
(Muhammad , 2016).

Best-Fit: Searching through the list of available openings, best-fit assigns to the smallest space
that is wide enough to handle the mechanism that is going in (Muhammad , 2016).

Next-Fit: The next fit is identical to the first fit except it begins to scan the list from the place
where the last scan ended and fits the next memory block open (Muhammad , 2016).

Worst-Fit: It is contradictory to best fit because it will always return the maximum available
memory block (Muhammad , 2016).

In the next figure, sequential fit algorithms are shown in action. Red block means the already
used memory blocks that can't be used when the remaining memory blocks are ladled with the
power. After 1k memory first the current pointer location is shown (Muhammad , 2016). In the
figure, we can see the execution of this algorithm if 2k memory is demanded by application.

38 | P a g e
SAUGAT ADHIKARI 18029221

Figure 24: Sequential memory blocks (Muhammad , 2016)

39 | P a g e
SAUGAT ADHIKARI 18029221

2.3.5 Description of Paging and Segmentation

Paged Memory Management:

Paged Allocation partitions the main memory of the machine into units of fixed size called
page frames, and the virtual address space of the program into pages of the same length. The
Memory Management Unit for Hardware maps pages to objects. Although the address space
is continuous, the actual memory may be reserved on a page basis (Tamunoomie & Ledisi,
2015). Paged memory can be demand-paged when the device is able to transfer pages between
primary and secondary memory as required (Tamunoomie & Ledisi, 2015).

Benefits:

➢ There is no need for external fragmentation.


➢ The transition between disks may be at individual pages ‘granularity (Alabdulaly,
2016).

Weaknesses:

➢ There is no correspondence between page protections.


➢ For its internal data structures, configuration and device data structures, which include
tables per process list; typically, the operating system requires additional storage
(Alabdulaly, 2016).

40 | P a g e
SAUGAT ADHIKARI 18029221

Figure 25: Paged Memory Management (Bower, 2015)

41 | P a g e
SAUGAT ADHIKARI 18029221

Segmented Memory Management:

Segmentation is a memory-management scheme which supports user view of the memory (M.
et al., 2016). Segmented memory is the only strategy that does not have a 'linear and contiguous
address space' for the user's program. Segments are memory regions, which typically
correspond to a specific knowledge classification (Tamunoomie & Ledisi, 2015). A segment
is a logical unit such as:

1. Main Program
2. Procedure
3. Function
4. Method
5. Object
6. Stack
7. Arrays
8. Global and Local Variables
9. Common Block

Figure 26: Segmentation in OS (M. et al., 2016)

42 | P a g e
SAUGAT ADHIKARI 18029221

Memory segmentation is the separation into parts or portions of a computer's main memory. A
reference to a memory location in a computer system using segmentation includes a value
which defines a segment and an offset (memory location) within that segment (M. et al., 2016).
Segments typically refer to a program's normal divisions such as function routines or data tables
such that segmentation is often more apparent to the programmer than just paging. Specific
segments may be generated for specific software components, or for particular memory use
classes such as code and data segments (M. et al., 2016).

Benefits:

➢ Segmentation lets you improve processing speed so the processor can get the data from
the memory much quicker.
➢ No internal fragmentation.

Weaknesses:

➢ It reduces the overhead compared to dynamic portioning approach (Alabdulaly, 2016).


➢ Segments of unequal sizes are not suited well for swapping.

43 | P a g e
SAUGAT ADHIKARI 18029221

2.4 Conclusion

Applications and operating systems cannot survive in the recent era of computing without
efficient memory management, particularly if an application has to be under severe load for
unknown long time. Efficient utilization of energy must be made of to boost efficiency. Real
time systems require timely and intelligent memory usage to work effectively otherwise the
purpose of real time systems will be to lose (Muhammad , 2016) . In the meantime, computation
has been ubiquitous over the years. The computing needs cannot be determined any further by
the criteria of a single computer or even a single device (Nair, 2015). Instead today's
computation includes data collection in a wide linked universe. In order to keep up with these
new demands, paradigms for using and programming computers have also shifted, and so the
function of memory also has changed (Nair, 2015).

This paper depicts the true understanding of memory management and various techniques and
algorithms used by modern operating systems for its implementation. Adequate research and
analysis from various journals, conference proceedings, articles and books have been
extensively carried out for the completion of this report. The advantages and disadvantages of
various types of memory management and allocation techniques have been discussed in
detailed manner. Hence, the concluding remark of this paper is that the memory management
techniques must be drastically changed in order to cope with the modern computing
requirements.

44 | P a g e
SAUGAT ADHIKARI 18029221

3. References

Abraham, S., Greg, G. & Peter, B.G. (2012) Operating System Concepts. 9th ed. John Wiley
& Sons, Inc.

Ahmed, F. (2016) A REVIEW OF MEMORY ALLOCATION AND MANAGEMENT IN


COMPUTER SYSTEMS. Computer Science & Engineering: An International Journal
(CSEIJ), 6(4).

Alabdulaly, W. (2016) MemoryManagement techniques and. International Journal of


Scientific & Engineering Research, 7(4).

Bower, T. (2015) Paged Memory Management [Online]. Available from:


http://faculty.salina.k-state.edu/tim/ossg/Memory/paged_mem.html [Accessed 6 April 2020].

Chaplot, D.V. (2016) Virtual Memory Benefits and Uses. International Journal of Advance
Research in Computer Science and Management Studies , 4(9).

Gandotra, S. (2015) Memory Management in Practice. Southern New Hampshire University.

Guru99. (2020) introduction to shell scripting [Online]. Available from:


https://www.guru99.com/introduction-to-shell-scripting.html [Accessed 1 April 2020].

Jain, M., Patil, D., Parikh, T. & Naidu, A. (2018) Review on memory divisions in computer
architecture. International Journal of Advance Research, Ideas and Innovations in Technology
, 4(6).

Kaushik, K., Yadav, J. & Bhatia, K. (2014) Shell Script & Advance Features of Shell
Programming. International Journal of Computer Science and Mobile Computing, 4(4),
pp.458-62.

M., P., A.R., V. & E.M., S. (2016) Segmentation in Operating System with Memory
Management. International Journal of Trend in Research and Development, 3(5).

Mali, S., Dohe, S. & Rangdal, P. (2019) Memory Management Techniques: Static and
Dynamic Memory Allocation. International Journal of Current Engineering and Technology,
9(1).

Montage Technology. (2019) M88DDR4DB01 - Gen1 DDR4 Data Buffer (DB) [Online].
Available from: http://www.montage-tech.com/DDR4/id/6.html [Accessed 6 April 2020].

Muazzam, A.K. & Nauman, N. (2013) Comparison and Review of Memory Allocation and File
Access Techniques and Techniques preferred for Distributed Systems. Islamabad: National
University of Sciences and Technology.

Muhammad , A.A. (2016) Memory Management: Challenges and Techniques for Traditional
Memory Allocation Algorithms in Relation with Today's Real Time Needs. INTERNATIONAL
JOURNAL OF MULTIDISCIPLINARY SCIENCES AND ENGINEERING, 7(3).
45 | P a g e
SAUGAT ADHIKARI 18029221

Nair, R. (2015) Evolution of Memory Architecture., 2015. IEEE.

Padua, D. & Pingali, K. (2011) Locality of Reference and Parallel Processing. In Encyclopedia
of Parallel Computing. Boston: Springer.

Patil, N.V. & Irabashetti, P.S. (2014) Dynamic Memory Allocation: Role in Memory
Management. International Journal of Current Engineering and Technology, 4(2).

Puaut. (2002) Real-Time Perfromance of Dynamic Memory Allocation Algorithms. In 14th


Euromicro Confrence on Real-Time Systems (ECRTS'02)., 2002.

R. H., D. (1968) Field-Effect Transistor Memory. U.S. Patent 3 387 286.

Ramagiri Ramya, N. (2016) ASIC Implementation of DDR SDRAM Memory. International


Journal of Engineering Development and Research, 4(4).

Tamunoomie, G.S. & Ledisi, G.K. (2015) Efficiency of Memory Allocation Algorithms Using
Mathematical. International Journal of Emerging Engineering Research and Technology, 3(9).

Toncho, N.T. & Yordanka, I.Y. (2018) Comparative Analysis Between Hard Disk Drive and
Solid-State Drive. Journal of Physics and Technology, 2(1), pp.41-45.

Villinger, S. (2019) What is RAM and Why is it Important? [Online]. Available from:
https://www.avast.com/c-what-is-ram-memory [Accessed 3 April 2020].

4. Bibliography

Allan, B., Sandy, I. & Prabhakar, R. (1995) Competitive Paging with Locality of Reference.
Journal of Computer and System Sciences, 50, pp.244-58.

Anderson, T. & Dhalin, M. (2015) Operating Systems Principles & Practice. 2nd ed. Recursive
Books, Ltd.

Pavel, Y., Alex, I. & Mark, R.E. (2017) Windows Internals Seventh Edition Part 1. 7th ed.
Washington: Microsoft Press.

46 | P a g e
SAUGAT ADHIKARI 18029221

5. Appendix

5.1 Memory Controller

Memory modules are present in in all applications and high speed and high capacity memories
are in great demand today. The controllers are to be equipped with clock frequency in the
megahertz range for greater performance and efficiency (Ramagiri Ramya, 2016). As the
controller's clock speed increases, so too are the architecture problems becoming complex . In
applications that do not have microprocessors (high-end systems), a Dedicated Memory
Controller is of prime importance. The Memory Controller supplies SDRAM reset, read and
write operation and initialization order signals for the rom (Ramagiri Ramya, 2016). Thanks to
its speed and pipeline capability Synchronous DRAM (SDRAM) is used in embedded device
memory architecture. In high-end devices, such as microprocessors, different peripherals may
be built in to support the SDRAM interface. Yet the system designer will design a different
memory controller for other programs to provide command signals for memory update, read
and write operation, and SDRAM initialization (Ramagiri Ramya, 2016).

Figure 27:DDR4 Memory Controller (Montage Technology, 2019)

47 | P a g e
SAUGAT ADHIKARI 18029221

5.2 Virtual Memory

Virtual memory is secondary memory capable of functioning as a part of the primary memory.
Digital memory is used as RAM until the RAM is used up. The hard disk is much slower than
RAM and the quicker the machine can run the more virtual memory it requires (Chaplot, 2016).
The computer will scan for locations that are not in use on the RAM and then copy it to the
hard disk to free up space on the RAM. Virtual memory keeps the machine 'running' in the
RAM and leaves the processes 'inactive' on the disk's address space. Where an 'inactive' process
is required, the process will be taken back from the disk to the RAM (Chaplot, 2016).

Implementation of Virtual Memory: Demand Paging

The idea of computer memory is applied using the principle of demand paging. In demand
paging a process is separated into separate pages and each page has a specific address and at
one point all the pages of a process are not taken into the main memory only some of the pages
connected to the processes are added as it is presumed that during the given time we do not
require all the processes in the memory for execution of program only some of the pages are
needed, remaining pages can be brought on the demand (Chaplot, 2016). The idea of virtual
memory is very useful in enhancing memory use but often this function is achieved at the
expense of missing some essential records. Through using this idea as a synthetic virtual
memory model, we will use this principle to boost the performance of computer system in a
more practical way (Chaplot, 2016).

Advantages:

➢ Virtual memory allocation is easy and cheap.


➢ Eliminates external fragmentation.
➢ Data (page frames) can be scattered all over PM.
➢ Allows demand paging and preparing.
➢ Allows jobs to be allocated in non-contagious memory locations.
➢ Very efficient swapping.
➢ Larger applications can be running with less amount of RAM.
➢ Applications may be launched faster because of File Mapping (Chaplot, 2016).

48 | P a g e
SAUGAT ADHIKARI 18029221

Figure 28: General Layout of Virtual Memory (Abraham et al., 2012)

Disadvantages:

➢ Longer memory access times.


➢ Reduced system stability.
➢ High Complexity.
➢ It takes more time to switch between applications.
➢ Less hard drive space for use.
➢ Table handling overhead (Chaplot, 2016).

49 | P a g e
SAUGAT ADHIKARI 18029221

5.3 Locality of Reference

1. Temporal Locality:

If the occurrences of a given memory address in its memory trace occur close to each
other, a program execution exhibits temporal localization. A system is assumed to
exhibit temporal locality if its executions exhibit temporal locality for most value inputs
(Padua & Pingali, 2011).

2. Spatial Locality:

An execution of a program demonstrates spatial localization if events in its record of


neighboring memory addresses occur in the record close together. A system is assumed
to exhibit spatial locality if its executions exhibit spatial locality for most inputs of
interest (Padua & Pingali, 2011).

3. Network Locality:

In a parallel computer where memory addresses are spread through processors, a


processor can have quicker access to locally mapped memory locations than to memory
locations assigned to other processors. It is said that a parallel system that aims to
manipulate features of Non-Uniform Memory Access (NUMA) parallel computers
exhibits network locality (Padua & Pingali, 2011).

50 | P a g e

You might also like