0% found this document useful (0 votes)
17 views15 pages

1.2.1-Memory Management

The document outlines the key concepts of memory management in operating systems, focusing on paging, segmentation, and virtual memory. It explains how memory is controlled, allocated, and managed to optimize performance and security while minimizing fragmentation. Additionally, it compares the advantages and disadvantages of paging and segmentation, highlighting their respective impacts on memory usage and efficiency.

Uploaded by

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

1.2.1-Memory Management

The document outlines the key concepts of memory management in operating systems, focusing on paging, segmentation, and virtual memory. It explains how memory is controlled, allocated, and managed to optimize performance and security while minimizing fragmentation. Additionally, it compares the advantages and disadvantages of paging and segmentation, highlighting their respective impacts on memory usage and efficiency.

Uploaded by

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

A-LEVEL COMPUTER SCIENCE – YEAR 1

1.2.1 Operating Systems


• SECTION E - DISTRIBUTED, EMBEDDED, MULTI-TASKING, MULTI-USER AND REAL TIME OPERATING SYSTEMS
• SECTION A – THE NEED FOR, FUNCTION AND PURPOSE OF OPERATING SYSTEMS
• SECTION F - BIOS
• SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).
• SECTION G – DEVICE DRIVERS
• SECTION C – INTERRUPTS, THE ROLE OF INTERRUPTS AND INTERRUPT SERVICE ROUTINES (ISR),
• SECTION H - VIRTUAL MACHINES, ANY INSTANCE WHERE SOFTWARE IS USED TO TAKE ON THE FUNCTION OF A MACHINE,
ROLE WITHIN THE FETCH DECODE EXECUTE CYCLE.

INCLUDING EXECUTING INTERMEDIATE CODE OR RUNNING AN OPERATING SYSTEM WITHIN ANOTHER.


• SECTION D – SCHEDULING: ROUND ROBIN, FIRST COME FIRST SERVED, MULTI-LEVEL FEEDBACK

QUEUES, SHORTEST JOB FIRST AND SHORTEST REMAINING TIME.


Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Section B - Memory management (paging, segmentation and virtual memory).

How does it work?


• Controls the efficiency and security of how instructions, programs & data are stored in RAM
• Security - If several programs are running at once, each program can only access its relevant data
stored
• Efficiency – Methods of splitting up stored information or creating more memory from secondary
storage

• It would be wasteful (and memory intensive) to load an entire app into RAM. Therefore only
the necessary processes of the app are loaded into RAM from the HD.
• These processes are split into blocks and then stored in RAM.
• The processes are then are swapped out (put back onto the hard disk) and new processes
are swapped in (transferred from the disk to RAM), according to the necessity of each
process
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

What is involved?
• Memory management is the process of:
• Controlling and coordinating computer memory
• Assigning portions called blocks to various running programs to optimize overall system performance.

• Mostly controlled by the operating system.

• Provide ways to dynamically allocate portions of memory to programs at their request

• Free memory for reuse when no longer needed.

• This is critical to any advanced computer system where more than a single process might be underway at any
time.

• This is important to ensure that each program has a reasonable response time, maximum use is made of the
available memory and programs do not corrupt each other by writing into each other’s memory space
The memory
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).
management
system splits the
block into either
pages or
segments
How does it work?

Information in B
A Empty
B C Empty is used and
swapped out

Information in D
is swapped in,
D D D however D is too
large

Question: C could be moved to the left to make room. Why does this not happen?
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Paging • A single program may consist of many pages but all pages are the
same size
• Allows a program or a process to be stored in
memory in equally sized blocks
• Usually quite small ~kB • The CPU uses an index (logical address) for each page.
• This can however cause internal fragmentation
should the page be smaller than the allocated • Each page has an actual address in RAM and this is called
amount the physical address.
• Details of logical addresses and physical addresses are stored in a
• Stored in a non-contiguous manner
• Not all the pages belonging to the process need to paging table (also stored in RAM)
be stored next to each other in memory. • The OS looks at the logical address and is able to use this index to
• This means that the pages of various processes can find the page at its actual position in the RAM.
‘interleave’ with each other
• Three processes A, B and C, each of which has three • This is like looking for a topic in the index of a book and then going
pages, may be stored in the order A1, B1, A2, C1, B2, to the actual book page number(s) where that topic is in the book.
B3, C2, A3, C3.
• This makes more efficient use of RAM when it needs
to store several programs.

contiguous A A B B B C C F F F

non-contigu A C C F B A F F B B
ous
Fragmentation – This is known as internal fragmentation. The allocated block has not been used up, therefore creating a fragment. This is
now not possible to use because process A is occupying this block
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Paging – How does it work?

• Pages are memory blocks which have been split into physical divisions
• Each page is the same size
• Processes can occupy many pages
• Processes don’t have to be in contiguous pages.
• This system is commonly used in virtual memory.
• Virtual memory is used for processes that are no commonly used, therefore the process
of paging is more efficient than segmentation in this scenario

Question: How much RAM is available in the following module? 4 x 50 = 200KB


Excel Excel Word AVG Excel Word AVG Game Game Game AVG
(50KB) (50KB) (50KB) (50KB) (50KB) (50KB) (50KB) (50KB) (50KB) (50KB) (50KB)
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Paging – How does it work?

Page # Process Size in bytes Fragmentation? % Wasted


Scenario:
1 P1 300 Yes 41
There are five processes running, each with
the following sizes: 2 P2 500 Yes 2
3 P3 512 No 0
P1: 300bytes
P2: 500bytes 4 P4 512 No 0
P3: 800bytes 5 P5 230 Yes 55
P4: 580bytes
6 P3 288 Yes 44
P5: 230bytes
7 P4 68 Yes 87
Arrange these three processes as efficiently 8
as possible using the table provided. Each
9
page is 512 bytes in size
10
Extra:
What is the maximum capacity (in bytes) for this section of memory? 10 x 512 = 5120 bytes = ~5Kb

How much more data (in bytes) can be stored after these processes are assigned pages? 1536bytes – Only pages 8, 9 and 10 can be used
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Paging – Advantages and Disadvantages

• Advantages
• Allows for use of smaller blocks of memory which would otherwise be unused
• Swapping is made easier due to the fixed sizes of each block
• Disadvantages
• Wasted space in precious memory e.g. if a 60 KB section of code needs to be loaded, this
will use two pages (50KB x 2 = 100KB)
• Can split code at a very inappropriate time, for example half way through a branch
• Internal fragmentation is a problem, meaning certain space is inaccessible until the
process has been swapped out
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Segmentation

• Allows a program or a process to be stored in memory in variably sized blocks


• Segments are split logically based on the code written
• This is done by examining the code for each process

• Stored in a non-contiguous manner

• Each segment is sized based on the size of the code

• A single program may consist of many segments

• Information on segments is stored in a segment table (also located in RAM)

• Segments tend to store more so require more space in RAM


Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Segmentation – How it works Process 4 is now initiated but too large to fit


There are currently three processes into one available space in RAM. Therefore
running in RAM; Process 1, Process the memory management system looks at
2 and Process 3 – Some have the code, splits the process up into two
needed splitting due to previous blocks so as not to intercept any procedures
processes which have now been and then distributes both segments
swapped out of RAM accordingly
Pro. 4 Pro. 4Pro. 4

Pro. 1 Pro. 2 Pro. 1 Pro. 3 P3 Pro. 3

Fragmentation – This is known as external fragmentation. The whole RAM module is made up of processes of
variable sizes. The space left over within the whole RAM module is a fragment of unused space
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Segmentation – Advantages and Disadvantages

• Advantages
• Not as much space is wasted when compared with paging
• No internal fragmentation as block sizes are not fixed
• Disadvantages
• Very complex to manage as different segments are different sizes
• As different size segments are loaded in and out of memory, the segments of a
particular process can become scattered all over the memory space.
• This leads to external fragmentation. More memory accesses are needed to find the
segments and this slows down performance
• The sizes are unpredictable therefore the demand on the processing power is
heavier
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Paging vs Segmentation - Summary

Paging Segmentation
Memory is organised into fixed sized blocks. Code is examined and processes are split into
sensible, logical segments
A process occupies many pages. The number of Memory is divided up to fit the segments e.g.
pages required needs to be ‘rounded up’ to the program instructions in segment A and program
process size e.g. if the page size is 50kb and the data into segment G
process size is 120 kb, three pages are needed.
The above is how internal fragmentation occurs The above is how internal fragmentation does not
occur
The CPU generates a logical address for each The amount of space allocated to the process
page. The actual physical address in RAM of each matches the exact size of the process.
page is found by the OS using a page table.
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Virtual Memory
If
So,
A priorities
virtual
What
The
This the
new operating
ishappens
hard
thenthen change
memory
operating
process
drive
frees is
system
if
upthe
repeated
will forRAM
becomes
system
then
space the
receivedwill
should processes
full
says
but
thento
modules
RAM
provide
for the then
athe
there
swap
new and
the
are
set out
becomeallthose
operating
secondary
is no aspace
amount
process stored
process
full?
fullofagain
to thatin
system
storage
in RAM
space
be itvirtual
will
(normally
forpredicts
(defined
accommodated memory
it tooutput
bythe
be stored
will
the aredrive)
inahard
message
not
user)
RAM
more
require
to be frequently
theRAMuser
used asking
is
as much
as requested,
formemory.
required it to be
attention
virtual then
and thatthat
increased
store process
in thewill thenmemory
virtual be swapped on theback
hardinto
drive
RAM
RAM
Excel Internet Excel Word AVG Excel Process Process Word AVG Game Game Process Game

Email Operating
System

Virtual Memory
Excel Excel Excel
Secondary
Storage
Need more RAM!
Memory Management
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Virtual Memory

LESS USED
DATA
HARD DISK Diagram to show how data is
swapped in and out of Virtual
RAM VIRTUAL
MEMORY
Memory based on the
importance of the data stored

MORE
USED
DATA
Questions
SECTION B – MEMORY MANAGEMENT (PAGING, SEGMENTATION AND VIRTUAL MEMORY).

Complete Section B on the worksheet 1.2.1 – Operating Systems

Extra:
• Read through page 19/20 of Revision Guide
• Answer questions 2 and 3

• Read through 1.2.2 – Revision Checklist: Section B and ensure you are
able to check off each point.
• Make a note of any areas you feel you need to work on

You might also like