Exam 2 Flashcards
Interrupt
The type of exception that is generated by an I/O device. Example: I/O device completes request
Trap
The type of exception that occurs intentionally as a result of executing an instruction. Example: User program opens a file
Fault
If a process causes an access to data or instruction that is not currently in main memory. Example: Read of a instruction not currently in main memory
Abort
If a process causes an access to corrupted data or instructions. Example: Hardware error
Concurrent processing (Multitasking)
Single processor executes multiple processes concurrently. Register values for nonexecuting process saved in memory
Parallel processing (Multiprocessing)
Parallel processing is a type of concurrent processing where more than one set of instructions is executing simultaneously.
Logical control flow
Each program seems to have exclusive use of the CPU, provided by kernel mechanism called context switching.
Private virtual address space
Each program seems to have exclusive use of main memory. Provided by kernel mechanism called virtual memory
User vs. Kernel mode
In User mode, the executing code has no ability to directly access hardware or reference memory.
In Kernel mode, the executing code has complete and unrestricted access to the underlying hardware.
Context Switch
Processes are managed by a shared chunk of memory resident OS code called the kernel. Important: the kernel is not a separate process, but rather runs as part of some existing process. Control flow passes from one process to another via a context switch
zombie
When process terminates, it still consumes system resources. Examples: Exit status, various OS tables. Called a “zombie”. Living corpse, half alive and half dead
Signal
A small message that notifies a process that an event of some type has occurred in the system
Pending Signal
A signal that has been sent but not received yet; there can be at most one pending sending of a particular type. Any more are discarded
Blocked Signal
When a signal is blocked, it can be delivered, but the resulting pending signal will not be received until the process unblocks the signal.
Sending Signals
Every way to send a signal relies on the idea of a process group. Every process belongs to exactly one group, obtained by the getpgrp function. Setpgid can change process ID
Receiving Signals
When the kernel switches a process to user mode, it checks the set of unblocked pending signals, and if there are none, it passes control to the next instruction. If there are pending signals, it forces the process to receive the signal
Catching Signals
Signals have default actions that can be overridden with signal handlers
sigprocmask, sigfillset, sigemptyset, sigaddset, sigdelset
sigprocmask - Changes the set of currently blocked signals
sigfillset - initializes a signal set to contain all signals
sigemptyset - initialize a signal set to contain NO signals
sigaddset - add a signal s to a set S via sigaddset, S=S∪{s}
sigdelset - remove a signal s from a set via sigdelset, S=S{s}
alarm
A function that sends the SIGALRM signal
Arranges for the kernel to send a SIGALRM signal to the calling process in (secs) seconds.
atexit
Executed every time an application is about to shut down
getpid
Returns the process ID of the calling process. This is often used by routines that generate unique temporary filenames.
getppid
Returns the process ID of the parent of the calling process. If the calling process was created by the fork() function and the parent process still exists at the time of the getppid function call, this function returns the process ID of the parent process. Otherwise, this function returns a value of 1 which is the process id for init process.
getpgrp, setpgid
getpgrp - Returns the group ID the process belongs to
setgpid - Sets the group ID of the process
getpgrp, setpgid
getpgrp - Returns the group ID the process belongs to
setgpid - Sets the group ID of the process
setjmp
Saves the current calling environment in the env buffer and returns 0. The calling environment includes the program counter, stack pointer, and GP regs.
longjmp
Restores the calling environment from the env buffer and then triggers a return from the most recent setjmp call that initialized env.
Setjmp now returns with the nonzero return value retval
Benefits of VM
PAGE 812
o Efficiency of main memory usage
o Simplify memory management
o Memory protection: isolate address spaces (avoid process interference)
o Simplify Linking and Loading
Hardware/Software cost of VM
o Address translation
o Page tables (must also be accessed in DRAM cache)
o Translation (both hardware and software if page fault)
Working set
Set of active pages since total pagesize might exceed size of physical memory
Swap file
a space on a hard disk used as the virtual memory extension of a computer’s real memory
Thrasing
When pages are swapped in and out of the working set continuously
TLB (Translation Lookaside Buffer)
A small cache of page table entries located in the MMU. Purpose is to decrease cycles required for translating virtual addresses into physical ones
DRAM cache organization driven by cost of misses, therefore:
§ large block size
§ write-back (rather than write-through)
§ fully-associative (any memory page can load into any page frame)
§ Complex replacement algorithms—must implement in software
How does TLB view a virtual address?
§ VPO – virtual page offset is same as PPO—physical page offset
§ TLBI – TLB index (selects TLB set)
§ TLBT – TLB tag (compare with tags in set)
Page Table Entry
An entry in the page table mapping a virtual address space to a fixed offset
PTE Content
Contains a valid bit and an n-bit address field
How does TLB view a virtual address?
§ VPO – virtual page offset is same as PPO—physical page offset
§ TLBI – TLB index (selects TLB set)
§ TLBT – TLB tag (compare with tags in set)
Program Loading with VM
o VM areas are initialized by associating them with disk objects—memory mapping
§ task_struct -> mm_struct -> list of vm_area_struct
§ what is pgd used for?
§ VM areas allows VM to be non-contiguous.
§ segmentation fault is caused by an address access outside any VM area
§ protection fault is caused by access to a valid area but without valid permissions.
pgd
the page global directory (pgd) which consists of an array of pgd_t types. The entries in the pgd point to entries in the second level directory, the PMD. The second-level page table is the page middle directory (PMD), which is an array of pmd_t types. Entries in the PMD point to entries in the PTE. Final level = page table; consists of page table entries of type pte_t. Page table entries point to physical pages
task_struct
- The OS stores process state in a data structure called process control block. There is one per process
called task_struct in linux
mm_struct
kernel’s representation of a process’s address space
important fields:
-mm_users = # of processes using the address space
-mm_count = main reference count; when the kernel operates on an address space, it bumps up the reference counter. all users = 1 count
-mmap and mm_rb: contain all the memory areas in this address space
pgd_t *pgd: physical address of the first thing in the pgd??? do we add the PGD offset to the start address of the PGD?
all of the mm_struct structures of every process are strung together in a doubly linked list via the mmlist field
vm_area_struct
describes a single memory area over a CONTIGUOUS VIRTUAL ADDRESS INTERVAL in a given address space
each VMA possesses certain permissions and associated operations
each VMA structure can represent different types of memory areas
important struct fields:
-VMA start (lowest address in the interval)
-vm_end (first byte AFTER the highest address in the interval)
length in bytes of memory area = vm_end - vm_start
An area can be backed by
§ regular file
o Initial page byte come from section of disk file
§ anonymous file (e.g. nothing)
o First fault allocates a page full of zeroes called a demand-zero page
o When a page is written to (becomes dirty), like any other page
o Dirty pages are swapped back and forth between memory and a special file called the swap file
mmap
- allows you to comb through a file like it is an array. Asks the kernel to create a new virtual memory area
private copy-on-write
As soon as a process attempts to write to some page in the private area, a write will trigger a protection fault, and the fault handler creates a new copy of the page in physical memory, and restores write permissions.
shared object
Any writes that the process makes to the area are visible to any other processes that have also mapped the shared object into their virtual memory
private object
Changes not visible to other processes, and any writes that the process makes to the area are not reflected back to the object on disk
Why dynamic memory allocation? When is this needed?
More portable, often we don’t know the size of certain data structures until the program runs.
Explicit vs. implicit allocators
Explicit - Requires the application to explicitly free any allocated blocks, for example, the free() function in CC
Implicit - Require the allocator to detect when an allocated block is no longer being used, and then free the block. AKA, garbage collectors
Requirements for explicit allocators
Handling arbitrary request sequences Making immediate responses to requests Using only the heap Aligning blocks Not modifying allocated blocks
Allocator throughput
Number of requests that it completes per unit of time
Peak memory utilization
How efficiently an allocator uses the heap
Aggregate payload
The sum of the payloads of the currently allocated blocks
Internal fragmentation
Occurs when an allocated block is larger than the payload
External fragmentation
Occurs when there is enough aggregate free memory to satisfy an allocate request, but no single free block is large enough to handle the request
Block format
Header, payload, padding.
Header encodes the block size as well as whether the block is allocated or free
Payload - Follows the header and is what the application actually requested
Segregated Free Lists
Each array contains blocks of the same size or class size (i.e. power of two).