Week 6 (Lect 14-16) Flashcards

(36 cards)

1
Q

How does the program use Code, Stack, Heap? (what are their functions?)

A

Code: instructions that live in memory

Stack: to keep track of where it is in the function call. used for local variables.

Heap: Dynamically allocated, user managed memory

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

2 types of allocated memory?

A
  1. Stack: managed implicitly (automatic memory)
  2. Heap: managed explicitly by the user
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a stack save in a function?

A
  1. return address
  2. save main’s pointer
  3. arguments and local variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

3 goals of a virtual memory system?

A
  1. Transparency (code that is invisible to the running program)
  2. Efficiency (in terms of time and space)
  3. Protection (protect processes from one another)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the malloc() call?

A

Pass a size asking for room in the heap.

Ex: malloc(10 * sizeof())

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

Some sources of segmentation fault?

A
  1. not allocating enough memory
  2. forgetting to initialize allocated memory
  3. forgetting to free memory
  4. double freeing
  5. freeing memory before you’re done
  6. invalid frees
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are stack canaries?

A

software defense that attempts to stop buffer overflow attacks / stack smashing.

It is a value (buffer) placed between local variables and return addresses. If an attacker attempts to overflow the buffer the overflow will also modify the canary

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

What is stack smashing?

A

An attack where an attacker attempts to write beyond the bounds of a local variable to modify the return address

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

Pros of a stack being a bump allocator?

A

Allocations/deallocations are really fast because we only move the stack pointer.

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

Cons of a stack being a bump allocator?

A

Allocations / deallocations only in the reverse order of which they are allocated

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

3 Ways to load virtual address into physical address?

A
  1. Direct Mapping
  2. Dynamic Relocation (whole memory)
  3. Segmentation (segments the memory)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is direct mapping?

A

Give all the physical memory to the process.

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

Pros of direct mapping?

A

simple to implement, process knows where every byte of memory is

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

Cons of direct mapping?

A

Where does the OS go and what if you want to run more than one process

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

What is dynamic relocation?

A

divides the memory into slots, each process gets a slot.

translates virtual -> physical address by:

physical = virtual + base

Implemented by a base and bounds registers with the help of the MMU (memory management unit)

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

What is the base and bounds register?

A

Base (OFFSET) register: stores the starting address in physical memory (the offset from virtual –> physical)

Bounds (SIZE): defines the size/limit of the programs memory

17
Q

What is internal fragmentation?

A

The space inside an allocated memory block is not all used. Happens a lot with dynamic relocation.

18
Q

What are some Hardware Requirements for Dynamic Relocation?

A
  1. Privlege mode to update base/bounds
  2. Implement base/bound registers
  3. Translate virtual address
  4. Raise exceptions
19
Q

What is Segmentation?

A

Splitting up the address space and storing each segment separately

20
Q

What are the 3 main segments?

A
  1. Heap
  2. Stack
  3. Code
21
Q

Pros of Segmentation?

A

Better utilization of physical memory, can place independently.

22
Q

Cons of segmentation?

A
  • External Fragmentation
  • segments can be different sizes so the OS has to worry about finding space
23
Q

What is external fragmentation?

A

Physical memory has become full o flittle holes of free space between segments.

24
Q

What is the explicit approach to knowing the offset and specific segment an address is refering to?

A

USE VIRTUAL ADDRESS:

  • top 2 bits to determine the type of segment
  • the remaining bits determine the offset
25
Some issues of using the top 2 bits for code, stack, and heap, and how to solve it?
2 bits with 3 segments → one segment of the address space goes unused. - Each segment would be limited to a maximum size.
26
Implicit approach to knowing the offset and segment an address is referring to?
Hardware notices how the address was formed.
27
How is the offset from virtual --> physical found?
Offset = virtual address - base of the segment
28
What is an additional support for segmenting "Stacks?"
Hardware needs to know if a segment is growing backwards to calculate offset properly
29
What is an additional support for code sharing?
Protection bits to indicate whether it can read or write a segment
30
Coarse grained vs fine grained segmentation?
Coarse: few but segments Fine-grained: large number of smaller segments
31
What is paging?
Divide physical and virtual memory into fixed-size chunks called pages / page frames
32
How do we know what page we're on?
Look at the 2 highest order bits (left-most of) of the virtual address.
33
How does the OS keep track of used pages / where each page is placed?
Through a free list of all free pages and a page table.
34
What is the physical page number (PPN) ?
Also known as the “physical frame number” The ACTUAL page number in the physical memory. The mapping from VPN → PPN is decided by a page table.
35
How does the OS help in translating from virtual -> physical address?
- Handles allocation and management - decides WHERE to place process - SAVE and LOAD values on context switches - exception handlers - clean process
36
How is fairness scheduled in lottery scheduling?
Fairness = time Job A finished / time Job B finishes The shorter the job the greater the unfairness.