Memory Allocation: Techniques and Algorithms - Prof. Indranil Gupta, Study notes of Computer Science

Various memory allocation techniques and algorithms, including demand paging, lru approximation algorithms, fixed allocation, equal allocation, proportional allocation, local replacement, global replacement, page fault frequency allocation, and overcommitting memory. Topics cover page fault handling, thrashing prevention, and working sets.

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-awh-1
koofers-user-awh-1 ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Memory Allocation
Indranil Gupta (Indy)
2
๎˜
Reading: Chapter 22
3
Demand Paging - Reminder
Load M
Free frame
Page
table
VM
ref
Page fault
Frame AddressDRVReference W ERe
Frame AddressDRVReference W ERe
4
LRU Approximation Algorithms
๎˜
Additional Reference Bits Algorithm
๎˜‚
Keep n bits for each page in a table in memory
๎˜‚
Each reference sets highest order bit
๎˜‚
Periodically, shift bits right dropping the lowest
bit)
๎˜‚
Use value as 8 bit unsigned integer
๎˜‚
Victim Selection: Page with the lowest value of
reference counter
๎˜‚
The value may not be unique, so use FIFO to
resolve conflicts
5
LRU Approximation Algorithms
๎˜
Second Chance
๎˜‚
FIFO (clock) replacement algorithm
๎˜‚
Uses reference bit in each page table entry
๎˜
Initially 0, set to 1 on a reference
๎˜‚
Pages are kept in FIFO order using a circular list
๎˜‚
If page is selected as prospective victim, inspect
the reference bit
๎˜
If reference bit = 0, replace the page
๎˜
If page to be replaced (in clock order) has refere nce bit
= 1, then
๎˜‚
Set reference bit to 0
๎˜‚
Leave page in memory
๎˜‚
Replace next page (in clock order) subject to same rules
6
Allocation of Page Frames
๎˜
Scenario
๎˜‚
Several physical pages allocated to processes
A, B, and C. Process B page faults.
๎˜‚
Which page should be replaced?
๎˜
Allocating memory across processes?
๎˜‚
Does every process get the same fraction of
memory?
๎˜‚
Different fractions?
๎˜‚
Should we completely swap some processes out
of memory?
pf3
pf4
pf5

Partial preview of the text

Download Memory Allocation: Techniques and Algorithms - Prof. Indranil Gupta and more Study notes Computer Science in PDF only on Docsity!

1

Memory Allocation

Indranil Gupta (Indy)

2

 Reading: Chapter 22

3

Demand Paging - Reminder

Load M

Free frame

Page table

VM

ref

Page fault

Reference V R D W ReE Frame Address

Re fe re nce VRDW ReE Frame Add re ss

4

LRU Approximation Algorithms

 Additional Reference Bits Algorithm

 Keep n bits for each page in a table in memory

 Each reference sets highest order bit

 Periodically, shift bits right dropping the lowest

bit)

 Use value as 8 bit unsigned integer

 Victim Selection: Page with the lowest value of

reference counter

 The value may not be unique, so use FIFO to

resolve conflicts

LRU Approximation Algorithms

 Second Chance

 FIFO (clock) replacement algorithm

 Uses reference bit in each page table entry

 Initially 0, set to 1 on a reference

 Pages are kept in FIFO order using a circular list

 If page is selected as prospective victim, inspect

the reference bit

 If reference bit = 0, replace the page  If page to be replaced (in clock order) has reference bit = 1, then  Set reference bit to 0  Leave page in memory  Replace next page (in clock order) subject to same rules

Allocation of Page Frames

 Scenario

 Several physical pages allocated to processes

A, B, and C. Process B page faults.

 Which page should be replaced?

 Allocating memory across processes?

 Does every process get the same fraction of

memory?

 Different fractions?

 Should we completely swap some processes out

of memory?

7

Allocation of Page Frames

 Each process needs a minimum number of

pages to function at all

 Want to make sure that all processes that are

loaded into memory can make forward progress

 Example: IBM 370 โ€“ 6 pages to handle SS

MOVE instruction:

 instruction is 6 bytes, might span 2 pages  2 pages to handle from  2 pages to handle to

8

Fixed Allocation

 Allocate a minimum but fixed number of

frames per process

 Consider minimum requirements, e.g. on

previous slide

 Include an extra page for paging out and one for

paging in

9

Equal Allocation

 Allocate an equal number of frames per job

 Example

 100 frames  5 processes  Each process gets 20 frames

 Concerns

 But jobs use memory unequally

 High priority jobs have same number of page

frames and low priority jobs

 Degree of multiprogramming might vary

10

Proportional Allocation

 Allocate a number of frames per job

proportional to โ€œjob sizeโ€

 How do you determine job size

 Run command parameters?  Dynamically?

 Priority Allocation

 May want to give high priority process more

memory than low priority process.

 Use a proportional allocation scheme using

priorities instead of size

 Disadvantage?

Allocation of Page Frames

 Possible Replacement Approaches

 Local replacement

 Global replacement

Local Replacement: Per

Process

 Each process has separate pool of pages  Fixed number of pages (e.g., Digital VMS)  Fixed fraction of physical memory (1/P)  Proportional to size of allocated address space  Page fault in one process only replaces pages of that process  Perform replacement (e.g., LRU) over only those pages  Advantage  No interference across processes  Disadvantage  Potentially inefficient allocation of memory  How to handle sharing of pages across processes?

19

Thrashing

 Studentโ€™s analogy to thrashing: Too many courses

 Drop a course

 OS solution: Admission control

 Determine how much memory each process needs  Long-term scheduling policy  Run only those processes whose memory requirements can be satisfied

20

Working Set

 Question

 How much memory does a process need to

keep the most recent computation in memory

with very few page faults?

 How can we determine this?

 Determine the working set of a process

 The principle of locality

 A program clusters its access to data and text temporally  A recently accessed page is more likely to be accessed again  E.g., sequential ops - reading arrays, code pages

21

Working Set (1968, Denning)

 Need

 Set of pages process needs to avoid thrashing  Requires knowing the future

 Working set: realistic implementation

 Pages referenced by process in last ฮค seconds of execution  Approximates locality principle

22

Working Set (1968, Denning)

 Need

 Set of pages process needs to avoid thrashing  Requires knowing the future

 Working set

 Pages referenced by process in last ฮค seconds of execution  Approximates locality

 Using working set sizes

 Cache partitioning: give each app enough space for WS  Page replacement: preferentially discard non-WS pages  Scheduling: process not executed (ready or running) unless WS in memory

Working Set Size

At least allocate this many frames for this process

Working Set Size

 Choosing T

 T too small

 Will not encompass entire locality

 T too large

 Will encompass several localities

 T = โˆž

 Will encompass entire program

25

Working sets of real programs

 Typical programs have phases

Working set size

transition

stable

transition

stable

transition

stable

26

Working Set in Action to

Prevent Thrashing

 Algorithm

 If number free page frames > working set

of some suspended processi

 Activate processi and map in its working set

 If working set size of some processk

increases and no page frame is free

 suspend processk and release all its pages

27

Working Set Implementation

 Tracking the working set

 Moving window over reference string  Approximate with Interval timer + a reference bit

 Example: T = 10,

 Keep in memory 2 bits for each page  Indicates if page was used within last 10,000 references  Timer interrupts after every 5000 time units  Shift 0 right  If one of the bits in memory = 1  Page is in working set

 Not completely accurate - cannot tell where

reference occurred.

 Improvement - 10 bits and interrupt every 1000 time units (^28)

Page Fault Frequency

Working Set

 Approximation of pure working set

 Assumption

 If the working set is correct  Not many page faults

 Approach

 Control thrashing by establishing acceptable page-fault rate

Page Fault Frequency

Working Set

 Algorithm

 If page fault rate increases beyond assumed knee of curve  Increase number of page frames available to process  If page fault rate decreases below foot of knee of curve  Decrease number of page frames available to process.

Page Size Considerations

 Small pages

 Large page tables  Minimizes internal fragmentation  Good for locality of reference (~256)  Page tables are larger  Disk-seek time dominates transfer time (It takes almost the same time to read a large page as a small page)

 Large pages

 Significant amounts of a page may not be referenced  Enables more data per seek

 Real systems (can be

reconfigured)

 Windows: default 8 KB  Linux: default 4 KB