Topic 12 – Memory management Flashcards
describe what
reloaction
is
this is a mechanism provided by the memory management module that enables a process to be loaded anywhere in memory and still be able to function
note
- this is essential in cases where programs may be written to use the same addresses in memory
- to enable this there will ususally be some implementation of a virtual memory system
name 4
tasks that the memory management modue
must carry out in order to provide a multitasking environment
the tasks this carrys out are:
- Allocating memory
- Relocation
- Protection
- Dealing with limited memory size
describe the linux file
/proc/swaps
this is a file that contains details about the swap spaces that are available such as partition and file swaps.
describe the following state:
Modify bit
Reference bit
1
1
what state are the modify bit and reference bit in when:
Page modified and referenced
(dont swap highly likely to be used again)
what is
paged virtual memory
this is a modern approach that operating systems use to handle memory
it invloves slicing memory into what are known as pages typically one page will be 4KiB
it also involves processes being alloacted virtual memory and the MMU will always translate to physical addressses
TRUE
each process will have its own page table
true/false
each process has its own page table
this is a memory address that is used by an application program and executed by the processor
it does not correspond to the real location of the resource in memory but will later be mapped to a physical memory address represnting where the resource actually exists in memory
what is a
logical/virtual address
this involves:
- logical/virtual memory addresses being sent to the processor by an application programs
- the processor executes and sends the logical address to a component built into the processor known as the memory mangement unit (MMU)
- the memory management unit (MMU) will translate the logical memory addresss to the physical memory address
how does a
virtual memory system
operate in 3 steps
false
the contents of the Translation look-aside buffer (TLB) is not saved upon a context switch.
instead it is flushed and repopulated for the new process
true/false
is the contents of the
Translation look-aside buffer (TLB)
saved on a context switch
name 2 instances upon which a
page fault can occur
this can occur when either:
- The page entry is part of the logical address space but it is currently in swap space
- The page may not be in the logical address space of the process; for example, a bug may cause a reference to an address outside the process’s address limit.
describe the following state
Modify bit
Reference bit
1
0
what state are the modify bit and reference bit in when:
Page is modified and not referenced
(can be written to swap as is unlikely to be used again, this could be initialisation instructions or error handling instructions page)
when this occurs:
- an interrupt will occur
- the page fault handler will deal with the page fault
what events are called when a page table entry is marked as invladid
this is a part of the operating system kernel and is charged with the management of memory
what is the
Memory Management Module
This command is used to show information about virtual memory and various events such as interrupts
describe the linux command
vmstat
what is the default unit
used by the linux free command
the default unit that this uses is
kibibyte
this is cache that is dedicated to holding entries from a page table.
it is used by the Memory Management Unit so that it can translate pages from here instead of from main memory.
if the MMU always had to go to main memory then it would be a bottlneck for the CPU
what is the
Translation look-aside buffer (TLB)
the execution process for this is as follows:
- All processes will be allocated logical memory and they will access their data using logical addresses
- When a program executes a logical address on the CPU the MMU will translate it using a page table
- If the logical address was 3D49 then the MMU would use the page number 3 as an index to the page table
- index 3 of the page table will tell the MMU the physical page number inside physical memory
- The MMU then combines the found physical page number with the offset of the logical address to reveal the true physical address in memory
describe the execution process of
paged virtual memory
what events are called when a page table entry is marked as invladid
when this occurs:
- an interrupt will occur
- the page fault handler will deal with the page fault
this is overcome by the operating system by
making use of a modify bit (dirty bit) and a reference bit which are stored with each entry in the page table and is updated by the MMU
how does the operating system appropriately decide which pages should be swapped in order to overcome swapping problems
what are 4 advantages and 1 disadvantage of paged virtual memory
advantages
- efficeient swapping -Swapping occurs in small chunks instead of entire processes
- better space utilization - Memory is allocated in small chunks so space is not wasted
- flexible reloction - Relocation is more flexible since it can be done on a page by page basis. instead of relocating an entire block of instructions the instructions that overlap can be paged and moved and the rest of the instructions that do not overlap can be left as is
- increased protection - protection can also be applied on a page by page basis and allow shared access to specific pages reducing scope for error or malicious code to attack
Disadvantages:
- page table size - Because page sizes are so small a page table for a process can grow extremely large. However some MMU hardware will allow for larger page sizes such as 1MiB or 1GiB.
this is a file that contains details about the swap spaces that are available such as partition and file swaps.
describe the linux file
/proc/swaps
if this was the case it would be catastrophic and a bottlneck for the cpu since the memory management unit would have to make two trips to main memory every time an instruction was executed
- To translate the logical address to the physical address using the page table in main memory
- To extract the instruction or data from main memory once the physical address has been translated by the MMU
what would happen if the
Memory Mangement Unit (MMU) did not have the dedicated Translation look-aside buffer (TLB)
what is the
Translation look-aside buffer (TLB)
this is cache that is dedicated to holding entries from a page table.
it is used by the Memory Management Unit so that it can translate pages from here instead of from main memory.
if the MMU always had to go to main memory then it would be a bottlneck for the CPU
what were the
base and length registers
historically used for
these were historically used so that a virtual memory system could be implemented
how does the
Translation look-aside buffer (TLB)
manage holding only a fraction of a page table
this can be pulled of by the Translation look-aside buffer (TLB) because of a phenomenom known as locality of reference.
the TLB can be updated as locality changes
what is the
page table
this is a table that is used by the Mmeory Management Unit (MMU) in order to translate logical page addresses to physcal page addresses
describe the linux directory
/proc
this directory within linux is used to hold any data that is generated on the fly by the operating system during its session. The contents is created on boot and is discarded at shut down
describe the following state:
Modify bit
Reference bit
0
1
what state are the modify bit and reference bit in when:
Page not modified but has been referenced
(dont swap is likely to be used again as could be a data page)
how does a
virtual memory system
operate in 3 steps
this involves:
- logical/virtual memory addresses being sent to the processor by an application programs
- the processor executes and sends the logical address to a component built into the processor known as the memory mangement unit (MMU)
- the memory management unit (MMU) will translate the logical memory addresss to the physical memory address
what is the
length register
this was used to hold the value of the maximum virtual address that the program used. This value ensured that the program could not access address space outside of what it had been allocated
what problem that the memory mangement module must handle does a
virtual memory system
solve
the problem that this solves for the memory management module is the problem of reloaction
these were historically included inside the processor so that they could be used to implement a virtual memory system
what are
base and length registers
used for
what is the outcome of typing the linux command
Vmstat -s
this will display a table providing information such as memory usage and other system events
this will display a table providing information such as memory usage and other system events
what is the outcome of typing the linux command
Vmstat -s
what is a
page fault
this is an event that occurs when a logical memory address cannot be translated to a physical memory address
in this case:
such as malware or buggy code the Memory Management Unit (MMU) would be able to detect it and generate an invalid address fault which is handled similarly to an interrupt so that the operating system can regain control of the processor
describe what would happen if the:
Memory Management Unit (MMU)
compared a virtual address with the length register and
discovered that it was outside the address range for the process
this is a modern approach that operating systems use to handle memory
it invloves slicing memory into what are known as pages typically one page will be 4KiB
it also involves processes being alloacted virtual memory and the MMU will always translate to physical addressses
what is
paged virtual memory
true/false
is the contents of the
Translation look-aside buffer (TLB)
saved on a context switch
false
the contents of the Translation look-aside buffer (TLB) is not saved upon a context switch.
instead it is flushed and repopulated for the new process
This is initially set to 0 and is rest to 0 any time:
- that the page is swapped
- a page fault occurs
- being scheduled for a reset by an interrupt
. When this is set to 1 it means that this page has been read
what is the
reference bit
describe the steps that the page fault handler will take after a page fault interrupt has been sent to the processor
the steps for this event include:
- It will check to see if the logical address is actually within the limits of what the process was allocated by referencing the processes control block (context block). if it is out of range then the operating system can terminate the process with an error message
- If the logical address is valid then the page entry must be in swap space and so the operating system begins the process of retrieving the page from the swap space to main memory the steps involved are:
- The operating system will find a free page in memory
- Schedule a disk operation to transfer the page from secondary storage to main memory
- place the process in a blocked state
- On completion update the page table with the physical address and mark it as valid
- Restart the instruction that caused the page fault
this is a memory address that corresponds to the real location in memory of a resource
what is a
Physical address
within this system
- virtual memory - is allocated to every process in which it will have its instructions loaded in a contigous manner as usual, this memory will also be divided into pages
- physical memory - this is the actual place where the resource can be found the available memory is split up into pages and pages may be scattered across memory, though this is no problem for the execution since the process will be executing virtual addresses in contigious order and they will be translated
within a paged virtual memory system describe
- virtual memory
- physical memory
this is a mechanism provided by the memory management module that enables a process to be loaded anywhere in memory and still be able to function
example
if two processes were written so they always made use of the same memory address and these two processes just happend to use the same addresses then thier would be a collision. this mechanism solves this problem. one solution is the use of logical memory addresses
describe the function of
relocation
that the memory management module provides
- What happens if memory is completely full but a page must be swapped in?
- In this case a page is first swapped out and then another page is swapped in. This has doubled the amount of swaps that otherwise would have been if memory wasn’t completely full
- What happens if a page is swapped but then shortly needed again and what if this occurs on a regular basis?
- If this occurs then the operating system has no choice but to keep making swaps and if this occurs on a regular basis then processing time is being wasted on non productive operations the result is an issue known as thrashing or disk thrashing where the secondary storage is frequently being accessed for pages that are needed in memory this slows the system down significantly
what are two
issues of swapping that must be solved
what state are the modify bit and reference bit in when:
Page not modified but has been referenced
(dont swap is likely to be used again as could be a data page)
describe the following state:
Modify bit
Reference bit
0
1
name an advantage and disadvantage of
swapping
- advantage - this method effectively creates more memory than there actually is meaning more processes or data can be used at a time
- disadvantage - the process of transferring data from memory to secondary storage is very time consuming and so this technique must use well thought out techniques to increase efficiency