Memory Management07
Memory Management07
relocation
– physical memory assigned to process may be
different during each run
– physical and absolute adresses should not be
used
protection
– process cannot access another process' memory
area
sharing
– code / data sharing
Memory Management Unit:
Main Aims
logical organization
– in traditional systems: linear adress space
(0max)
– programs: written as modules / procedures
physical organization
– transfers among main memory and secondary
storage
Allocating Memory
adress: (s,d)
– s: segment name
– d: offset
each process has a segment table
– flag: is segment in memory?
– base adress of segment
– segment length (limit)
– protection bits
starting adress of segment table kept in a
register
Segmentation
Memory
segment table (s,d)
register
segment table
segment start
+
s d
(byte) limit
prot.
flag bits limit base + (no of
bytes)
Segmentation
info
on page in page table
page table entry:
– flag: is page in memory ?
– page location (memory/secondary storage
adress)
– protection bits
page table register
– points to start of page table of running process
Paging
page table
page start
+
d
prot.
(byte)
flag bits page adress
Paging
external fragmentation
– empty spaces between blocks
internal fragmentation
– empty spaces within blocks
no external fragmentation with paging
Paging
1500 words
free 1455 words
45 words
500 words
free 455 words
Segmentation with Paging
p
s
Questions to answer:
how is space allocated on the main memory and
secondary storage
– easier with paging
– harder with segmentation due to unequal segment sizes
what to consider when moving pages/segments
between main memory secondary storage ?
if main memory is full, which page/segment should
be removed to secondary storage ?
Allocation of Memory for Unequal Sized
Segments
first-fit
– starting from the beginning of the list, allocate the
first free space whose size is greater than or
equal to the required size
– leftover spaces are again added to the list
next-fit
– start looking for the first appropriate free space
starting from the location of memory space
allocated in the previous request (not from
beginning of list)
– better to have a circular list
Allocation of Memory for Unequal Sized
Segments
best-fit
– try to find the free space whose size fits the
requested size the best (minimum leftover free
space)
– for each time, go through the whole list
worst-fit
– opposite of best-fit
– again go through the whole list for each request
Allocation of Memory for Unequal Sized
Segments
“buddy” system
– divide the whole memory into blocks of size 2k
– assume the whole memory size is 2s
there are (s+1) linked lists
20, 21, 22, ...., 2s
– demand paging
bring pages to main memory only when they are accessed
Page Replacement
if there is no available free space in the main memory,
a page needs to be moved to the secondary storage
– care must be given to possible page traffic
– a page that is just removed from the main memory should not
be accessed
“thrashing”: loss of time
– main aim is to NOT remove USEFUL pages
pages that won’t be accessed in the near future can be removed
– some operating system pages cannot be removed
frame locking is done through setting a bit
– page selection can be at two levels :
local: choose from among the pages of the running process
global: choose from among all the pages
Page Replacement
select randomly
– easy to implement
– USEFUL pages may be selected
first in first out – FIFO
– select page which has been in the main memory the longest
– performance may be bad – the oldest page may not be the page that
won’t be accessed in the near future
BIFO (biased FIFO)
– select from among the ni pages of the i. process, use FIFO for the ni
pages
– different processes may have different number of pages in memory
– ni for each process may change over time
Page Replacement
LRU (Least Recently Used)
– high implementation cost, hardware support needed
– keep a table of records for each page of the time that has
passed since the last access to that page
– at the end of each quantum, all entries are updated
clear the access time counters for the accessed pages
increment the access time counters for all other pages in the
main memory (the ones that were not accessed)
when choosing a page to remove from memory, choose the
one with the highest counter value (means the page has not
been accessed for the longest time)