Didn't provide much of an abstraction
추상화가 구현을 안했어서 그냥 메모리공간에 하나의 프로세스를 위한 공간이었다. 일단 다 실행시키고 다음 프로세스한테 넘기는 식이었다. 여러 프로세스가 대기해도 메모리공간 전체를 하나의 프로세스를 위해서만 썼기에 효율성이 굉장히 떨어졌다.
Multiprogramming
메모리공간을 쪼개서 각 프로세스에게 할당해준다. CPU 활용도가 높아짐.
Time sharing
메모리를 할당해주고 다 쓰면 switch 해준다.
Protection issue
다른 프로세스 공간에 침범하지 않게 검사하는 장치가 필요하다.
주소공간을 추상화로 활용한다. 프로세스에 필요한 모든 정보가 메모리에 저장되는데 실제 메모리공간위치에 그 값이 있는 것은 아니다.
Running program thinks it is loaded into memory at a particular address (0) and has a potentially very large address space (32 - bits or 64 - bits)
가상적으로 굉장히 무한한 공간을 가진다고 가정. 실제로 그렇진 않음.
Transperency
Effciency
메모리를 찾아가는 데 시간이 조금 걸리고 메모리의 위치를 저장할 새로운 자료구조가 필요
Protection
OS 가 할당된 공간 외를 벗어나지 않도록 잘 관리해준다.
Forgetting to allocate memory
char *src = "hello";
char *dst; // unallocated
strcpy(dst, src); // segfault and die
char *src = "hello";
char *dst = (char *)malloc(strlen(src) + 1); // 널문자 공간까지 생각.
strcpy(dst, src);
Not allocating enough memory
char *src = "hello";
char *dst = (char *)malloc(strlen(src)); // too small
strcpy(dst, src); // 널공간까지 추가로 넣어줘야함
Forgetting to initialize allocated memory
Forgetting to free memory
Freeing memory before you are done with it
Freeing memory repeatedly
Calling free() incorrectly
Address translation
Changing the virtual address provided by the instruction to a physical address where the desired information is actually located
Example
void func() {
int x = 3000;
x = x + 3;
...
}
128: movl 0x0(%ebx), %eax
132: addl $0x03, %eax
135: movl %eax, 0x0(%eax)
Fetch the instruction at address 128
Execute this instruction (load from address 15KB)
Fetch the instruction at address 132
Execute this instruction (no memory reference)
Fetch the instruction at address 135
Execute this instruction (store to address 15KB)
bounds
bounds
or negative, the CPU will raise an exceptionHardware Requirements | Notes |
---|---|
Privileged mode | Needed to prevent user-mode processes from executing privileged operations |
base/bounds registers | Need pair of registers per CPU to support address translation and bounds checks |
Ability to translate virtual addresses and check if within bounds | Circuitry to do translations and check limits (in this case, quite simple) |
Privileged instruction(s) to update base/ bounds | OS must be able to set these values before letting a user program run |
Privileged instruction(s) to register exception handlers | OS must be able to tell hardware what codeto run if exception occurs |
Ability to raise exceptions | When processes try to access privileged instructions or out-of-bounds memory |
OS Requirements | Notes |
---|---|
Memory management | Need to allocate memory for new provesses; Reclaim memory from terminated processes; Generally manage via free list |
base / bounds management | Must set base/bounds properly upon context switch or moving a provess's address space |
Exception handling | Code to run when exceptions arise; likely action is to terminate offending process |
*) Variable -sized address spaces and Larger address spaces than the size of physical memory are more difficult to handle