C+I Flashcards
What is a file?
A file is a named collection of related information that is
recorded on secondary storage.
Attributes of a file (metadata)
Name of file identifier (chosen by system) location on storage device Size of file Protection mode of file (permissions) Create, access, modify times
Four file operations
CRUD Create Read Update Delete
Which of the for file operations isn’t technically required? Why?
Update
While inefficient, one could create a new, updated file for each edit and delete the old file
Directory
Storage of files (folder)
file organisation
File mounting
File system on a storage device may be mounted at a point in the existing file system
2 distinctive features of Linux file system
∙ an everything is a file approach;
∙ a tree-like file structure;
Everything is a file
All these things are classed as files ∙ regular files: sequences of bytes; ∙ directories: name/inode association lists; ∙ special files: peripheral devices; ∙ pipes: buffers between processes; ∙ links: locations of other files; ∙ symbolic links: names of other files.
Tree like file structure
Diagram with the BLK and 12 /256 stuff
Magnetic Disks - Organisation
Disk has a number of spring platters, over which hover some heads attached to a movable arm.
Platter divided into circular tracks, which are divided into sectors.
Tracks at one arm position make up a cylinder
Magnetic Disks - Operation
A magnetic disk is read/written by moving the arm to the required cylinder and using a head to sense/change the magnetism of a sector.
Solid-State Disks - Organisation
A solid-state disk has a controller, some buffer memory, and some flash memory.
Typically like 256Kb buffer memory, 128Mb flash memory with 4Kb pages and 256Kb block size, and ARM controller
Solid-State Disks - Reading
Copy a flash memory page to the buffer
Read data from page in buffer
Solid-State Disks - Writing
Copy a memory block into the buffer
Erase the block in the flash memory
Modify the block in the buffer
Write the block from the buffer to the flash memory.
Wear levelling (increase SSD lifetime)
Dynamic - writes new data to the least-recently-used block, cold data is not moved
Static - additionally periodically moves existing data to the least-recently used block, cold data is moved
3 categories of I/O devices
∙ human interface devices - e.g. screens or keyboards;
∙ storage devices - e.g. disks or tapes;
∙ transmission devices - e.g. network cards or modems.
Busses
An I/O device may be connected via a port (rare) or a bus (common).
e.g. Graphics, Bridge, Disk and Network controllers attached to the PCI bus
Controller registers of I/O devices
∙ the data-in register — data coming from device;
∙ the data-out register — data going to device;
∙ the status register — bits indicating status of device;
∙ the control register — bits giving commands to device.
Instructions used to access controller register
Standard memory instructions (common), or special instruction (rare)
2 approaches to I/O control
1) polling
2) interrupts
I/O control - polling
The processor checks the device to see if it is ready
“How you doing? How you doing? How you doing?”
WORSE
I/O control - interrupts
The device signals the processor when it is ready
BETTER
When is Direct Memory Access used?
When devices need to deal with large volumes of data
4 separate I/O system calls
1 character I/O
2 block I/O
3 memory-mapped I/O
4 network I/O
Character I/O system call
Enable an application to get/put a single character from/to a device.
Block I/O system call
Enable an application to read/write many characters, and perhaps to seek on a device
Memory-Mapped I/O system call
Enable an application to
map a device into memory
Network I/O system call
Enable an application to
read/write many characters to/from a network device socket
A computer system organised into processes may achieve what 2 things?
∙ modularity — easier to build and maintain
∙ speedup — easier to run on multiple machines
Lifecycle of a process
born -> ready running ->exit
What does the process controll block contain?
∙ the process number (identity); ∙ the process state (registers); ∙ the process address space ( memory); ∙ the process I/O (open files and network connections); ∙ ... D
Context switching
A context switch involves saving the machine state in one process control block and loading the machine state from another.
Process Address Spaces have: (4 things)
∙ a stack section for temporary data;
∙ a heap section for dynamically-allocated data;
∙ a data section for global data;
∙ a text section for program code
What are the 4 Unix system calls to spawn a process?
∙ fork: copies a process address space;
∙ exec: overwrites a process address space with a program;
∙ wait: waits for another process to exit;
∙ exit: terminates a process.
Inter-process communication may be either:
1) shared memory;
2) message passing.
Inter-process communication - shared memory
Processes write data to/read data from from an agreed area of memory.
Inter-process communication - message passing
Processes send messages to/receive messages from an agreed mailbox
3 memory management tasks
1) relocation;
2) protection;
3) sharing.
Memory management - relocation
Relocating the memory of each process
Memory management - protection
Protecting the memory of each process
Memory management - sharing
(Controlled) sharing of the memory of each process
6 memory management techniques
1) fixed partitioning;
2) dynamic partitioning;
3) simple segmentation;
4) virtual memory segmentation;
5) simple paging;
6) virtual memory paging.
Memory management - Fixed Partitioning
Loads entire process memory maps into same-sized partitions
Memory management - Dynamic Partitioning
Loads entire process
memory maps into different-sized partitions. (e.g. big, medium, and small partitions)
Memory management - Simple Segmentation
Loads all process memory map segments into different-sized partitions.
– Also helps with memory protection
Memory management - Virtual memory segmentation
Loads some process memory map segments into different-sized partitions.
(Some stay in virtual memory)
Memory management - Simple paging
Divides process memory maps into same-sized pages and loads them all into same sized frames.
Memory management - Virtual memory paging
Divides process memory maps into same size pages and loads some of them into same sized frame. (Some stay in virtual memory)
Ensures memory sharing BY …
3 main components of a computer
1) the central processing unit (CPU)
2) the memory
3) the input/output devices
General-purpose registers
CPU contains small number of registers (r0-r15), most of which are general purpose (used for whatever is required)
Special-purpose registers
Of r0-r15, r13,r14, and r15 are special purpose. They perform specific roles such as program counter (r15) and stack pointer (r13)
Arithmetic logic unit (ALU)
Performs operations between two input registers, putting the result in an output register. e.g. mov r3, #7 @ set r3 to 7 mov r9, #6 @ set r9 to 6 mul r8, r3, r9 @ set r8 to r3 * r9
Bits, Bytes, and Words
∙ a binary digit (bit) is 0 or 1;
∙ a binary term (byte) is 8 bits;
∙ a word may be 2, 4, or 8 bytes.
What does the memory store
Programs and data
Load instruction
Transfers a word from memory to a register
e.g. ldr r1, [r8]
Store instruction
Transfers a word from a register to memory
e.g. str r3, [r6]
Commonly used bases
Decimal - base 10
Binary - base 2
Hexadecimal - base 16
Octal - base 8
Control unit
Fetches instructions from memory, as determined by the program counter register
The stack
Push instructions to add a value to top, pop to take off top value. LIFO/FILO ) first in last out) (opposite of queue).
I/O devices are connected by busses that have 3 difference lines. What are they?
∙ control lines that carry commands; (control bus)
∙ address lines that carry addresses; (address bus)
∙ data lines that carry data. (data bus)
Metaphor for why cache memory is needed
To cook, you require ingredients. But if you cook a meal it would be inefficient to fetch each required ingredient from a supermarket every time it is needed.
The solution is to use a fridge to store commonly used ingredients for easy access.
Computation is possible by fetching all instructions and data from the memory when required, but using a smaller, closer cache memory ans a bus connecting it to the CPU is far more efficient.
Temporal locality
Programs exhibit temporal locality (locality in time) — if an item in memory is referenced, then it is likely to be referenced again soon.
Hence it can be stored in cache.
Spacial locality
Programs exhibit spatial locality (locality in space) — if an item in memory is referenced, then it is likely that those nearby will be referenced soon.
Hence, nearby items are stored in cache.
Cache hit or miss
∙ a cache hit — read data from cache;
∙ a cache miss — read data from memory into cache first.
Three common cache designs
1) direct-mapped;
2) fully-associative;
3) set-associative
Direct-mapped cache
In a direct-mapped cache, a memory address is mapped to exactly one cache address.
-> Can waste space/ could already be something mapped to that spot
Fully-Associative Cache
In a fully-associative cache, a memory address is mapped to the least-recently-used cache address
-> More efficient but slower - have to search cache
Set-Associative Cache
In a set-associative cache, a memory address is mapped to exactly one cache set, and to the least-recently-used place in that set.
-> Most efficient. All modern computers use this
Relationship Between Caches
A fully-associative cache with 𝑆 slots is an 𝑆-way associative cache — there is 1 set of size 𝑠.
A direct-mapped cache with 𝑆 slots is a 1-way set-associative cache — there are 𝑆 sets of size 1.
DON’T REALLY GET THIS
Dealing with write hits (2 options)
∙ write back — write into cache only;
∙ write through — write into both cache and memory.
Dealing with write misses (2 options)
∙ write around — write into memory only;
∙ write allocate — write into memory and read into cache.
Virtual memory
Memory stored externally, such as disk. Extends the idea of a cache memory to disk.
Pages
Virtual memory (disk) is divided into pages, and addresses are seen as (virtual-page-number, offset) pairs. VIRTUAL MEMORY frames
Frames
Physical memory (RAM) is divided into frames, and addresses
are seen as (physical-frame-number, offset) pairs.
PHYSICAL MEMORY pages