CSE 3430 – C4-C6

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

22 Terms

1
New cards

Address conflict problem

  • Compilers number every program’s address starting at 0

  • If several processes are in memory at once, they would all use the same addresses for different things

  • OS fixes this by relocating each process’s address to where the process actually sits in physical memory


2
New cards

The 4 approaches to address relocation (address conflict problem)

  1. Time-Sharing

  2. Base + Bounds

  3. Segmentation

  4. Paging


3
New cards

Time sharing of memory + its downsides + its solution

  • Only one process is in RAM at a time. Every context switch, the whole process is saved to disk and the next one is loaded

  • Downside: terrible performance due to slow disk

  • Solution: space sharing (memory is divided among processes at the same time)


4
New cards

MMU (memory management unit)

Hardware that translates every virtual address a user process uses into a physical address

The 4 approaches depend on MMU

5
New cards

Base + bounds & its downsides

  • Base = where the process starts; bounds = its size

  • On every access, MMU checks where Address < bounds

    • If yes: adds base to address to get physical address; otherwise, trap and kill

  • Needs hardware (MMU registers)

  • Protects processes from eachother

  • Downsides: Whole address space must be contiguous and loaded


<ul><li><p><strong>Base</strong> = where the process starts; <strong>bounds</strong> = its size</p></li><li><p>On every access, MMU checks where Address &lt; bounds</p><ul><li><p>If yes: adds base to address to get physical address; otherwise, trap and kill</p></li></ul></li><li><p>Needs hardware (MMU registers)</p></li><li><p>Protects processes from eachother</p></li></ul><ul><li><p>Downsides: Whole address space must be <strong>contiguous </strong>and <strong>loaded</strong></p></li></ul><p></p>
6
New cards

Segmentation + its downsides

  • Address space split into code, heap and stack segments

  • Each segment has its own base, bounds and protection (kept in a segment table)

  • Needs hardware (segment table)

  • Protects processes from each other

  • Downsides: Only each segment must be contiguous, not the whole space. All segments must be loaded


<ul><li><p>Address space split into code, heap and stack segments</p></li><li><p>Each segment has its own base, bounds and protection (kept in a segment table)</p></li><li><p>Needs hardware (segment table)</p></li><li><p>Protects processes from each other</p></li><li><p>Downsides: Only <strong>each segment</strong> must be contiguous, not the whole space. All segments must be <strong>loaded</strong></p></li></ul><p></p>
7
New cards

Segmented address translation

  • Top bits of an address choose a segment; remaining bits give the offset

  • Process: MMU looks up segment’s base and checks the offset against the segment’s bounds.

    • Offset < bounds → physical = base + offset

    • Otherwise → error

    • Example: 0x265c = segment 2, offset 0x65c → 0x3000 + 0x65c = 0x365c


<ul><li><p>Top bits of an address choose a segment; remaining bits give the offset</p></li><li><p>Process: MMU looks up segment’s base and checks the offset against the segment’s bounds.</p><ul><li><p>Offset &lt; bounds → physical = base + offset</p></li><li><p>Otherwise → error</p></li><li><p>Example: 0x265c = segment 2, offset 0x65c → 0x3000 + 0x65c = 0x365c</p></li></ul></li></ul><p></p>
8
New cards

External vs. internal fragmentation

  • External: free memory is in small scattered holes that are too small to use; affects base + bounds and segmentation

  • Internal: unused space inside an allocated chunk


<ul><li><p><strong>External:</strong> free memory is in small scattered holes that are too small to use; affects base + bounds and segmentation</p></li><li><p><strong>Internal:</strong> unused space inside an allocated chunk</p></li></ul><p></p>
9
New cards

Paging

  • Memory split into fixed-size pages (physical pages are called frames)

  • Page table maps each virtual page number to a physical page number

  • Needs hardware (MMU + page table)

  • Protects processes from each other

  • Not contiguous; pages can go anywhere

  • Not fully loaded; some pages can stay on disk

  • No external fragmentation


<ul><li><p>Memory split into fixed-size <strong>pages</strong> (physical pages are called <strong>frames</strong>)</p></li><li><p>Page table maps each virtual page number to a physical page number</p></li><li><p>Needs hardware (MMU + page table)</p></li><li><p>Protects processes from each other</p></li><li><p><strong>Not</strong> contiguous; pages can go anywhere</p></li><li><p><strong>Not</strong> fully loaded; some pages can stay on disk</p></li><li><p>No external fragmentation</p></li></ul><p></p>
10
New cards

Paging address format

  • Address bits = VPN bits + offset bits

  • Page size = 2^(offset bits)

  • Number of pages = 2^(VPN bits)

  • 1 KB = 2^10, 2 KB = 2^11, 4 KB = 2^12

  • Example: 32-bit address with 4 KB pages → 12 offset bits, 20 VPN bits, 2^20 pages


<ul><li><p>Address bits = VPN bits + offset bits</p></li><li><p>Page size = 2^(offset bits)</p></li><li><p>Number of pages = 2^(VPN bits)</p></li><li><p>1 KB = 2^10, 2 KB = 2^11, 4 KB = 2^12</p></li><li><p>Example: 32-bit address with 4 KB pages → 12 offset bits, 20 VPN bits, 2^20 pages</p></li></ul><p></p>
11
New cards

Thread & Its Attributes

  • A sequence of execution inside a process

  • Has its own thread ID, PC, registers and stack pointer

  • Shares the process's heap with other threads, so shared data must be on the heap

  • On a multicore CPU, threads can run at the same time on different cores


12
New cards

Critical Section

  • Code that accesses shared data

  • Bank example: read balance → change it → write it back

  • If interrupted partway through, another thread can corrupt the data (for example, 950 instead of 1030)


13
New cards

Mutual Exclusion & Drawbacks Without It

  • At most one thread in a critical section at a time

  • Without it, the output is indeterminate: the same input can give different results


14
New cards

Binary Semaphore

  • A variable with a value of 0 or 1 and two atomic operations:

    • semWaitB (P): if the value is 0, block; if it's 1, set it to 0 and continue

    • semSignalB (V): unblock a waiting thread if there is one; otherwise set the value to 1


15
New cards

Semaphore as a lock


  • Initialize the semaphore to 1

  • semWaitB = acquire the lock (before the critical section)

  • semSignalB = release the lock (after the critical section)

  • Critical sections run as whole blocks: only 1,2,3 → 4,5,6 or 4,5,6 → 1,2,3 can happen, so the result is always correct


16
New cards

File / file system


  • File = an array of bytes that persists after power-off

  • File system = the collection of files, and also the part of the OS that manages them

  • Files are organized in a directory tree; a directory is a special file


17
New cards

Inode

  • A file's metadata record containing its size and location of its data on disk

  • Inode number = the file's index in that array = the file's unique ID


18
New cards

Three types of file names


  • Inode number

  • Path

  • File descriptor


19
New cards

Path traversal


  • A directory's data is a list of name → inode number entries

  • Lookup starts at the root directory (usually inode 2) and walks down one level at a time

  • Each level takes 2 reads: the inode, then its data

  • /etc/bashrc = 6 reads


20
New cards

Allocation methods & their purpose

File data is stored in fixed-sized blocks. There are 4 different allocation methods for storing data, each of which have their own benefits and drawbacks.

  1. Contiguous

  2. Extents

  3. Linked

  4. FAT


21
New cards

Contiguous vs. extent allocation and their pros & cons

  • Contiguous: one unbroken run of blocks

    • Fast and simple, little metadata

    • Terrible external fragmentation, and hard to grow

  • Extents: a few contiguous runs (2–6) per file

    • Less fragmentation, still fast

    • Can only grow until it runs out of extents


22
New cards

Linked vs. FAT allocation and their pros and cons

  • Linked: each block points to the next

    • No external fragmentation, grows easily

    • Very slow random access; one pointer wasted per block

  • FAT: the same chains, but all the pointers live in one table

    • Fast random access when the table is cached in memory

    • Two disk reads per data read if it isn't cached