index

The Abstraction: Address Spaces

Early Systems

Multiprogramming and Time Sharing

Multiprogramming: machines expensive so people sharing i.e. multiple processes Timesharing: now using multiple users/processes at the same time

so now you have to context switch and stuff, where do you store saved context?

  • option 1 on the disk.

ERROR

i/o to is disk slow as fuck, like seriously slow

  • option 2 gotta keep the saved context in memory then

how do you do this?

ERROR

people want protection of their context from other processes too, can’t have your pokemon psychic adventures gameplay being overwritten by someone who forgot to free() their variables right

The Address Space

first create an abstraction what do you need in the memory assigned to a process?

  • the code
  • the stack: keep track of functions
  • the heap: user managed memory
  • etc (small stuff related to the code)

how do you organise this? Next, we have the two regions of the address space that may grow (and shrink) while the program runs. Those are the heap (at the top) and the stack (at the bottom). We place them like this because each wishes to be able to grow, and by putting them at opposite ends of the address space, we can allow such growth: they just have to grow in opposite directions.

this is just a convention tho

Goals

and thus we come to the job of the OS, virtualize the memory to provide the user/process this abstraction. what are the objectives of such a virtual memory system?

  1. transparency (invisible): process should not know it’s memory is virtualised
  2. efficiency: virtualization should not make the running program significantly slower
  3. protection: protect processes from one another

TIP

strive for isolation. the linux kernel is monolithic. microkernels are being designed

Every Address you See is Virtual

any address you can see as a programmer of a user-level program is a virtual address check out

#include <stdio.h>
#include <stdlib.h>
int main(void) {
  printf("location of code: %p\n", main);
  printf("location of heap: %p\n", malloc(10e4));
  int x = 3;
  printf("location of stack: %p\n", &x);
  return x;
}
 ./va
location of code: 0x60cdcad5e159
location of heap: 0x60cdee9896b0
location of stack: 0x7ffcde430584

the output follows perfectly the layout of the address space