Exam 2 Practice Questions Flashcards

1
Q

Why is physical memory typically smaller than virtual memory?

A

Physical memory is limited to the size of the RAM used in a system. Virtual memory is stored on disk and is typically larger.

Today, typically a virtual address is 32 or 64 bits. 32 bits allows each process to have 2^32 bytes or 4GB of virtual memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the problem that virtual memory solves?

A

We often have programs that are too large to fit into memory at the same time. Or – we might want to fit multiple programs into memory at once.

So, the basic idea behind virtual memory (Fotheringham, 1961) is that each program has its own address space, which is broken up into chunks called pages. Each page is a contiguous range of addresses. These pages are mapped onto physical memory, but not all pages have to be in physical memory at the same time to run the program. When the program references a part of its address space that is in physical memory, the hardware performs the necessary mapping on the fly.

Virtual memory works in a multiprogramming system, with bits and pieces of many programs in memory at once. While a program is waiting for pieces of itself to be read in, the CPU can be given to another process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe the paging architecture using this image.

A

On the left, we see the hardware on our motherboard where we have the CPU and MMU (or memory management unit).

Assembly language instructions such as MOV, R, M will cause the CPU to move a value from its register R into physical memory M.

M initially is a virtual address. The role of the MMU is to translate this virtual address into a physical address. We can directly access the value stored at M, which is stored in physical memory frames shown in the middle.

The frames are the same size as virtual memory pages. They are analogous to slots in a parking lot where a car would be a page and one of these frames would be a space to park your car in.

Last, we look at the disk controller and the swap file. The swap partition is like spillover space. The memory pages that cannot fit into physical memory will spillover to the swap file, which you can communicate with through the disk controller.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you design a new processor architecture with 16-bit addresses, what is the total size of the virtual address space? (Think back to LC-4!!)

A

65536 Bytes

2^16 bytes because we can address 2^16 different byte addresses with 16 bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In a 32 bit computer with a page size of 4KB, what is the number of offset bits in the virtual address?

A

12

the page size is 4 KB (2^12 bytes)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a 32-bit computer with a page size of 4KB, how many pages does the virtual memory have?

A

1048576
The computer is 32-bit, which means the size of the virtual address space is 2^32 Bytes. The page size is 4 KB, which is 2^12 Bytes. So the number of pages is 2^32 / 2^12 = 2^20 = 1048576. In other words, there are 20 bits of the memory address are used to present the page numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Briefly describe how paging and offset work.

A

During paging, the virtual page is extracted from the virtual address. This will be used to index into a page table. The page table will contain a pointer to the actual physical frame if the page is currently in physical memory. The physical frame is then retrieved and the offset is then used to point to the specific word that we’re trying to read in memory that corresponds to the virtual address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given the page table and virtual address, what is the physical address after the table translation?

A

10100101000010
There are 16 rows in the page table, so the first 4 bits in the virtual address are shaded as the index bits. Binary 1001 is equal to 9 in decimal. so, the first three bits of physical address should be 101. The offset bits are copied directly from the virtual address. Therefore the physical address should be 10100101000010.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Given the page table of process A and the swap file, please enter the page numbers mapped to each block in the swap file correspondingly.

A

free, A(1), free, A(2)
Based on the bitmap, the first and third blocks are empty. So they should be filled with “free”. In the page table, page 1 is mapped to the B1 in the swap file and page 2 is mapped to the B3 in the. Therefore the answer should be free, A(1), free, A(2).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Multi-Level Paging

  1. Describe the problem that multi-level paging solves.
  2. Describe how multi-level paging works.
A
  1. In a 32-bit computer with a 4KB page size, we need a page table with 2^20 entries. This is too big! And the problem is even worse on 64-bit computers.
  2. Insight: make page tables hierarchical, load only needed portions to memory.
    Break virtual page number into 10-bit chunks:
    –first 10 bits index into a top-level page-entry table T1 (1024 entries)
    –each entry in T1 points to another (second-level) page table with its own 1K entries (4 MB of memory since each page is 4KB)
    –next 10-bits of virtual address index into the second level page table selected by the first 10 bits
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In a 32-bit operating system with an 8 KB page size, there are 8 bits in the top-level table and 10 bits in the second-level table. If a process uses 128 MB virtual memory, how many entries it will accept in the top-level table?

A

16
There are 10 bits in the second-level table and the page size is 8 KB. So, each second-level table can index 8 MB memory. The process needs 128 MB memory, so it needs to be able to index 16 second-level tables. Therefore, there will be 16 entries in the top-level page table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a downside to multi-level paging?

A

While this approach is memory efficient, one issue is that instead of having one memory access, we need multiple memory accesses. This is one potential downside of multi-level paging. In fact, the global and the middle level directory may sometimes even be stored on disk. If we use them frequently, there’s a high likelihood they would have been swapped to physical memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. Describe what problem Translation Lookaside Buffers (TLB) solve.
  2. Describe the TLB solution.
A
  1. Problem: page tables are stored in main memory, and access to main memory is about 10 times slower compared to clock cycle of CPU.
  2. TLB in MMU:
    - TLB stores small cache of page table entries to avoid the usual page-table lookup
    - TLB is associative memory (content addressable memory) that contains pairs of the form (page-no, page-frame)
    - special hardware compares incoming page number in parallel with all entries in TLB to retrieve page-frame
    - if no match found in TLB, we do standard lookup via main memory
    - like hardware cache for MMU
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is one solution to the problem discussed about multi-level paging?

A

Inverted Page Table:
inverted page table is bounded by physical memory size
popular in 64 bit machines

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the steps involved in paging?

A
  1. input to MMU: virtual address = (page p, offset o)
  2. check if there is a frame f with (p,f) in TLB
  3. if so, physical address is (f, o)
  4. if not, lookup page-table in main memory
    - - requires slow accesses due to multi-level paging
  5. if page is present, compute physical address
  6. if not, issue page fault interrupt to OS kernel
    - - even slower
  7. update TLB / page-table entries (e.g. Modified Bit)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why is swapping a page an expensive process?

A

Swapping is an expensive process and will even block the current process. If a page in memory is “dirty” (i.e., it contains recent writes), and this block is selected for eviction, the changes need to be written to disk and the new page needs to be brought to memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Why is the FIFO replacement scheme not a theoretically optimal algorithm?

A

According to the FIFO scheme, on a page fault, the frame that has been in memory the longest is replaced. This is not an optimal algorithm, in fact FIFO suffers from Bélády’s anomaly, the phenomenon in which increasing the number of page frames results in an increase in the number of page faults for certain memory access patterns. In FIFO, the page fault may or may not increase as the page frames increase, but in Optimal algorithms, as the page frames increase the page fault decreases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Describe how the Second Chance Algorithm looks for a candidate to evict.

A

The second chance algorithm looks in the queue for the first page with reference bit set to 0, this page is the candidate for eviction. If it finds a page with reference bit set to 1 it will decrement this value to 0 and add the page to the back of the queue.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is an improvement on the Second Chance Algorithm?

A

Clock Algorithm

    • keep a circular list with current pointer
    • if current page has R=0 the replace, else set R to 0 and move current pointer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

In LRU (least recently used), what is the page that was most recently accessed? Least recently accessed? (stack algorithm)

A

Most: the page with the highest value of the 8-bit counter
Least: the page with the lowest value of the 8-bit counter
(the least is evicted)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Briefly describe I/O Architecture.

A

At the user space, you have your application and the API that is exposed is the virtual file system API.
Underneath that, we have the actual file system API that will translate all the read and write to files, and this is then sent to the device driver, and the device driver will do another level of conversion into actual bytes to be sent and received from the external device.
The way your device driver interacts with the device controller is through the device registers and the data buffers. For example, the device driver can read or write to the device controller status value. This can allow the device driver to figure out whether the external device such as your hard disk, is ready to accept new input, and any data that we write to the disk or read from the disk, is first buffered in the data buffers of the device controller and then can be read by the device drivers themselves.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Describe the two approaches used for processes to access devices.
Which one is more elegant?

A
  1. port-mapped I/O
    – IN register, port (assembly instruction)
    • reads value from I/O port into register
  2. Memory mapped (more elegant)
    – part of virtual address space really goes to devices
    • advantages
    • device drivers can be written in high level languages like C
    • protection managed by pages accessible in each user space
    • disadvantages
    • caching must be disabled for I/O pages (write-through to devices)
    • MMU need to distinguish I/O requests from legitimate memory accesses
23
Q

Describe the problem that I/O with Direct Memory Access (DMA) solves.

A

CPU is kept busy with both port-mapped and memory-mapped I/O. Even though memory-mapped can be made more (by using interrupts instead of busy-waiting) efficient, it’s still a waste of CPU compute power.

So, DMA controller:
• separate hardware co-processor dedicated for I/O
• co-processor helps the CPU copy data between memory and device
• frees up the CPU to do other work
• DMA controller interrupts CPU only after the entire transfer

DMA can be integrated with device controller, but usually one (on parentboard) for all devices

24
Q

What are device drivers?

A

Device drivers are the interface between the OS and a device
• new device, OS installs new device drivers
• device driver includes device-specific interrupt handlers
• device specific I/O routines
• device-specific control routines (ioctl)

25
Q

Describe what is happening here.

A

Your user application sits in user space. It interacts with the operating system through the file system API. Then for each device we have a device driver. In this case, for the printer, the camera recorder, and the CD ROM. Each device driver interacts with the corresponding hardware controller which is typically implemented in firmware. The controller then connects to the device itself.

26
Q

What information do we need to identify an endpoint in the networked system?

A

IP address
port number
The IP address allows us to identify that particular machine the application is running on. The port number let us identify the application to deliver the message.

27
Q

Describe differences between stream sockets (aka TCP) and datagram sockets (aka UDP).

A
stream:
• connection-oriented (includes establishment + termination
• reliable, in order delivery
• at-most-once delivery, no duplicates
• ssh, http
datagram:
• connectionless (just data-transfer)
• "best-effort" delivery, possibly lower variance in delay
• IP Telephony, streaming audio
• lower overhead
28
Q

Which type of socket should you use if you want a reliable and in-order communication?

A

TCP. TCP is connection-oriented. There is an establishment and termination process of setting up the connection. Thus the connection tends to be reliable and provide in-order delivery. UDP, on the other hand, is fast but has no guarantee for the reliability.

29
Q

What methods can be used to avoid blocking system calls?

A

multithreading & event driven asynchronous programming

these solve the blocking system calls issue, which occurs in the singled threaded process method

30
Q

What are the problems associated with multi-threaded servers?

A
  1. high resource usage, context switch overhead, contended locks
  2. too many threads can lead to throughput meltdown, response time explosion
  3. difficulty in reasoning about concurrency (requires mutexes, semaphores, etc.) – deadlocks!

alternative: event-driven asynchronous programming

31
Q

When is event-driven programming a good choice?

A
  • for I/O bound applications, where event-handlers are short-lived, such as in a user-interface
  • network protocols, bc there are many I/O events involved
32
Q

3 properties of layers

A

service: what a layer does

service interface: how to access the service (interface for layer above)

protocol: how peers communicate; set of rules and formats that govern the communication between two network boxes; how the layer is implemented between machines

33
Q

Describe the partition table of a disk.

A

One for all partitions
At a fixed place on disk, gives layout
Each partition may contain:
• boot block: loads OS in kernel space
• superblock: contains basic info about file system which is read into memory at boot time
• free space data structure
• list of I-nodes (or other data structure) giving info about individual files
• allocatable blocks for directory and file data

34
Q

How is memory allocation similar and different to disk space allocation?
What are the goals of disk space allocation?

A

Similar: how to represent free vs. allocated blocks, how to allocate and free up blocks
Different: performance of disk isn’t like memory (slower), access patterns may be different

Goals:

  1. fast sequential access
  2. fast random access
  3. ability to dynamically grow
  4. minimize fragmentation
35
Q

What are the four allocation schemes we studied? Briefly describe each.

A
  1. Contiguous allocation (fixed)
    CD ROMs
    • each file occupies a contiguous region of blocks
    advantages:
    • fast RAM (only one seek needed)
    • useful for read-only devices (where we make and then only read)
    • management is easy
    disadvantages:
    • management is inflexible
    • fragmentation is a problem if delete are allowed or if files grow in size
    • after disk is full, new files need to fit into holes
  2. Linked list allocation
    • linked list of blocks for each file; each block begins with a pointer to the next block
    • logically, each file has contiguous blocks, but physically the file is spread out into different physical blocks

advantages: no external fragmentation
disadvantages: RAM is slow; to get to block n, n-1 blocks have to be read up front

  1. Linked list with file allocation table (FAT)
    MS-DOS FAT file system
    • addresses the slowness of RAM in previous LL allocation scheme
    • idea: consolidate all the LLs and put them somewhere at the beginning of the file system
    –> FAT is an array indexed by blocks
    –> each array entry is a pointer to next block
    –> when you boot up OS, copy of FAT is put into main memory
    • because FAT is in main memory, traversing this LL is much faster bc no disk I/O is needed
    disadvantage: the entire FAT must be in memory, and as disk size increases so does FAT
  2. Linked list with indexing (I-nodes)
    Unix file system
    • addresses the problem of the FAT growing too large to fit in main memory
    • idea: operating system only needs to load in i-nodes that are currently open and used
    • each file has an i-node record associated with it
    • i-node contains all attributes of the file
    • i-node also has fixed sized array of block addresses
    • additional levels of indexing possible to accommodate larger files (last address reserved for pointer to another block of addresses)
    • memory required is much less than FAT
    • time required to access specific block varies depending on the size of the file
36
Q

Why does it take so much longer to access really large files with i-nodes?

A

Big file access can take longer time due to the needed to use the indirect blocks:

37
Q

What is linking? Explain the difference between a hard link and a symbolic link.

A

Linking: a technique that allows a file to appear in more than one directory.

hard link: the link system call specifies an existing file path and a path name, and creates a link from the existing file to the name specified by the path. this kind of link, which increments the counter in the file’s i-node (to keep track of the number of directory entries containing the file) is a hard link.

symbolic link: instead of having two names point to the same internal data structure representing a file, a name can be created that points to a tiny file naming another file; when the first file is used, for example, opened, the file system follows the path and finds the name at the end; then it starts the lookup process all over using the new name

advantage: they can cross disk boundaries and even name files on remote computers
disadvantage: less efficient implementation

38
Q

What are the two methods we learned for managing free disk space?

A

Linked Lists
• a list of blocks containing addresses of free blocks (e.g., each block address is 32 bits (4 bytes)
• a 1 KB block used can hold addresses of 255 free blocks and an address of the next block in the list for free space management
• note: list can be stored in free blocks

Bitmap Method
• an array of bits, one entry per block, indicating whether that block is free or not
• 16 GB disk has 16 million 1 KB blocks
–storing bitmap requires 16 million bits or 2048 blocks

39
Q

How do the linked list method and the bitmap method (for managing free space) compare in terms of space requirements?

A

If a disk is getting full and you have few free blocks, then the Linked List method is more efficient. Otherwise, the bitmap is more efficient. The bitmap method will require number of bits equivalent to the total number of blocks.

40
Q

Why is caching useful? Describe why we need to use write-through technique to synchronize state.

A

With caching we don’t need to access the disk for every read and write, which makes both processes much faster. But in this case, the blocks that are cached in memory may not be reflected on disk. And hence we will have an inconsistent state. Thus, if we modify important data, we need to use write-through technique to synchronize the state on the disk with the one in the main memory, which will reduce the speed of writing into the file but is still able to optimize read.

41
Q

Physical vs. Logical Backup

A

In a physical backup, we would actually copy physically block by block from one disk to another.
Logical backup or logical dump does it more at a file system level. It is agnostic to the operating system. For example, when you’re synchronizing to Dropbox, they’re actually copying not at the block level, but at the file level, one file at a time.

42
Q

Describe what is happening in this FS consistency check:

A

A is the good case where every block is either in use or free.

But B is actually a bad scenario because you can see for example, block number 2 is neither in use nor free. This is bad because it means block number 2 is not accounted for. This can happen when we delete a file containing block number 2, but your machine crashes before you actually put that into free blocks. The way most file systems will fix this problem is by inserting block 2 into the free blocks.

Part C, is another bad scenario because block 4 appears twice in the free blocks. The way to fix this is to decrement and remove one of the block entries for four in the free space region.

In the last scenario on the bottom right, part D, we actually have a block number 5 that is in use twice. This means that two i-nodes mysteriously point to the same block.

43
Q

What is virtualization?

A

the ability of a computer to run multiple operating systems on the same physical machine

44
Q

Why do Type 0 Hypervisors offer good performance capability?

A

Since the type 0 hypervisor itself runs on raw hardware, it provides good performance with low overhead, thereby supporting nested VMs on top of a guest operating system on a VM.

45
Q

What are the benefits of virtualization?

A
  1. run different OSes on a single machine without rebooting or dealing with different partitions
  2. VMs isolated from other VMs (allows for sandbox testing - experimental OSes or those with security vulnerabilities
  3. Data center management in could-computing era:
    - -> freeze, suspend running VM (snapshots! can move or copy somewhere else and resume)
    - -> periodic backups for restoring to consistent state (some VMMs allow multiple snapshots per VM)
    - -> load balancing (migrate VMs are heavily loaded to less loaded machines)
    - -> templating: create an OS + application VM, clone multiple copies easily
46
Q

Compare Type 1 and Type 2 hypervisors.

A

Type 1 and 2 hypervisors run on commodity hardware, unlike Type 0 hypervisors which are implemented in hardware. The Type 1 hypervisor runs in kernel mode; it treats the guest OS like a process and handles the system calls issued by the guest OS. The Type 2 hypervisor, however, runs in user mode because it runs on top of an underlying host OS. Its purpose is to run another OS on top of the existing commodity general-purpose.

47
Q

What kind of instructions use the trap-and-emulate?

A

Privileged instructions - Trap-and-emulate will result in the degradation of performance. Hence, you never want to do this for all instructions. The only type of instructions that should go through trap-and-emulate are privileged instructions like those that deal with input and output. The reason is that if you trap and emulate every instruction, then the guest operating system slows down considerably.

Trap-and-Emulate relies on guest OS throwing errors, context switching from guest OS to the VMM and from user mode to kernel mode. It slows down the guest OS considerably and therefore has a larger performance degradation than Binary Translation.

48
Q

Describe what is happening in trap-and-emulate:

A
  1. guest OS runs in user mode and VMM (hypervisor) runs in kernel mode
  2. issues arise when guest OS attempts to run a privileged instruction; this will result in an error because the trapping will happen between user process and guest OS
  3. in the trap-and-emulate solution, whenever the guest OS tries to run a privileged instruction, the error is thrown within the OS and caught by the VMM
  4. then, the VMM emulates the instruction that was attempted on behalf of the guest OS
  5. the result of running this action will also update the VCPU

**only for privileged instructions

49
Q

How is binary translation different than trap-and-emulate? What advantages does it have?

A

In binary translation, instead of doing trap and emulate for every instruction that runs in the guest operating system, such instructions are translated on the fly to equivalent instructions in the MMU (memory management unit).
So rather than doing trap-and-emulate, you’ll simply replace the original assembly code that you’re supposed to run with the equivalent implementation in the VMM.

One of the advantages of doing this, is that you can use caching because we are essentially replacing some set of instructions with another set of instructions. Suppose you have performed code replacement for previous instructions, then you can cache the translations for these instructions. This way later on when you execute the same instructions again, you do not have to re-translate them, because they are already found in the translation cache, hence improving performance.

50
Q

Is it possible to have more VCPUs than physical CPUs?

A

Yes. VMMs can run many guest OSes and schedule many VCPUs, and when the number of VCPUs is larger than physical CPUs, VMMs use scheduling algorithms to assign physical CPU to VCPUs and saves VCPU states.

51
Q

Does the guest OS always allocate memory in contiguous chunks?

A

No. Without optimizations, guest OS physical memory maps onto host virtual memory, then onto host physical memory, and it can completely go out of sequence. In fact, some of guest physical memory could even be swapped out.

52
Q

Does the VMM allocate static or dynamic memory to virtual machines?

A

From the VMM point of view, the guest OS is a process, therefore the VMM allocates host virtual address to guest OS dynamically. So the host virtual address grows dynamically as the guest OS’s memory utilization grows.

53
Q

What happens when there is not enough host physical memory (in the context of virtualization)?

A

When there is not enough host physical memory, the guest physical memory is swapped out onto the swap file.

54
Q

Describe the optimization of Shadow Page Table.

A

The optimization of Shadow Page Tables relies on VMMs intercepting the writes to the guest OS page table and applying the write to the shadow page table, which maps from guest virtual address directly onto host physical address. The mechanism is similar to Trap-and-Emulate and effectively eliminates guest physical address and host virtual address.