virtual memory Flashcards
how does virtual memory work
to give us more memory we use main memory as a cache for the disk/swap space
swap space
contains all the pages corresponding to the process whilst only some of them are in main memory
where do we store the control information
in the spare 12 bits in the page pointer obtained from the page directory
what are some examples of the information in the control information section
dirty flag
accessed flag
present flay
what does the dirty flag show
if the frame is currently different to the one on the disk
means that if we need to free that space then we need to store it to the disk first
what does the present flag show
if the frame is actually in memory
what does the accessed flag show
if the frame has been accessed whilst its been in memory
what are the steps to replacing a frame ( getting it from the disk)
we get a page fault
we choose a victim and update the disk if the dirty flag is set
we remove the old translation and drop the frame from memory
the new frame is added to the place of the old frame and the new translation is mapped
the process is restarted
in which two ways do we choose how many pages to allocate per process and explain them
equal allocation: equal number of pages per process
proportionate allocation: based on the process size
why does equal page allocation not make sense
because each process has different requirements
thrashing
when a process doesnt have enough frames
what are the two negatives of thrashing
high number of page faults
lower cpu utilisation as time is spent paging in and out which is expensive
how does thrashing cause a high number of page faults
not enough frames are allocated
not having enough memory and having too many frames on the disk
how can we limit thrashing
local replacement algorithm: stops a process from being able to take frames from other processes therefore thrashing is limited to the one process
in which two ways can we speed up page replacement
always keeping a frame free
maintain a list of victim frames
how does always keeping a page free speed up page replacement
theres always a page free to be replaced and when its used then the next victim is moved to the disk and their frame is made free
how do we maintain a list of victim frames to speed up page replacement
during idle time the os writes the victim frames to the disk
if a process goes back to a frame on the list we can recover it and add it back to main memory (soft page fault)
soft page fault
the frame isnt part of the page table but its till in memory and not been overwritten
hard page fault
the frame is only on the disk
working set
the pages that the process would want in memory
but not necessarily in memory
resident set
pages actually in memory
page reference string
list of pages accessed over a period of timeu
maximum resident set
max pages at a given time (peak memory usage)
what is the issue with fifo page replacement algorithm
the first pages usually hold key parts of the process e.g. global variables
in which two ways can we keep a record on when each frame was last used in the least recently used page replacement algorithm
keep a count of the number of accesses
have a doubly linked list of frames: when a frame is accessed it goes to the top so all victim frames are at the bottom
what is the negatives of using the least recently used algorithm in page replacement
requires additional hardware which is expensive
what are the four page replacement algorithms
least recently used
fifo
least frequently used
second chance/clock algorithm
how does the second chance/ clock algorithm work
the frames are in a circular list
when we get a page fault we go round until we found a frame with an accessed bit still at 0 which we can overwrite
when going round, all the frames with the access bit set to 1 are set to 0 so that if there were initially no 0 when we go round again then we have a victim
what is the role of the clock hand in the clock/second chance algorithm
the “clock hand” is a pointer to the next victim to keep track of the order ensuring we dont start form the beginning each time
how does the least frequently used algorithm work in page replacement
we have a timer that trigger us to look at the access bits of all frames of the process and push them onto the shift register
the frame with the lowest value is the one that has been least frequently used
in the least frequently used algorithm in page replacement what does the number of bits in the shift register define
defines the working set period
e.g. triggered every ms, 4 bits = 4ms working set period
in the least frequently used algorithm in page replacement what does it mean when all the bits are 0 in the register
the frame is not in the working set so a likely victim
what does it mean when a process has a low page fault frequency
working set is too large
has more frames than necessary
what does it mean when a process has a high page fault frequency
working set is too small which leads to thrashing (not enough frames)
how can we deal with a process with a high page fault frequency
can pause it and push it to the disk
then allow another process to complete before resuming to stop the thrashing