컴퓨터 시스템/OS

OS review / Youngjin Kwon

Campkim 2021. 10. 1. 12:47

강의듣다가 기록

 

Top school은 OS가 전필임 한국도 변화가 필요함.

 

OS에서 하는일 예시

mmap (1mb) 예시

mmap 선언시 가상메모리에 할당만되고 실제 메모리에 할당되지 않는다.

VM에 먼저 할당이 되고, 요청시 page fault가 나면서 할당이됨

 

memset 으로 1로 해당 영역 초기화할때 비로소 할당이된다.

memset으로 2로 다시 초기화했을 때 더 빨리 할당이 됨 ( page fault가 없어서 ) 

(memset으로 2번째 실행시에는 cache hit 도 발생)

 

동일한 예시 mmap (1gb)  - map size is way beyond cpu cache size!  (1mb일때는 바로 cach에 다 올라갈 수 있었음)

 

page와 cache를 이해하고 pagefault와 cache effiective하게 설계하기 위해 OS가 필요하다.

 

 

OS에는 소프트웨어 학습의 방법론이 있음

OS가 있기 전에는 hardware control을 위해 직접 하나하나 조작해야 했음

OS는 programming 환경(API)을 제공함.

 

 

OS 디자인 목적 이해하기위해

Key roles of OS 알기

 

abstractions

define apis for applications to use 

OS의 시작은 추상화를 만드는 것으로 시작해서 추상화를 만드는 것으로 끝남

 

Protection & Isolation

 

Sharing resources

multiplex hardware resource

 

 

What is abstraction? 

추상화 - 모호함에서 불필요함을 잘라낸다. --> 복잡한 개념을 이것은 ~~~다. 라고 정의하는 것.

the process or outcome of making something easier to understancd by ignoring some of details that may be unimoprtant

 

how to make it easy to use hardware?

os designers build each abstraction of hardware resources and bind it to process

CPU - virtualizing cpu

memory - virtual address space

storage -> file ( 복잡한 memory 접근을 위해 file개념 도입과  접근 interface를 간단히함)

-->쓰레드는 OS 의 산물 **

 

os 디자이너의 첫번쨰 생각

1.아무도 하드웨어를 핸들링하면서 프로그램을 작성하고 싶어하지 않는다.

2. to utilize hardware resources, os has to run multiple applications(management unit of execution)

3. protect applications from each other (protection unit of execution)

3가지 요건 충족을 위 해 프로세스를 만듬

process는 single load machine(컴퓨터)를 abstract 한 것이다. 

 

VM

abstraction of address space

paging

segmentation

segmented paging 

 

cpu <->mmu(hardware) <-> memory

mmu 사용하는 이유? hard ware가 훨씬 빠르고 메모리 절약이 됨을 께달음

 

physical address 얻는 과정

현재는 페이지 테이블이 효과적이다.

본질은 가상주소와 물리주소를 맵핑하는 것이다. -> 인공지능이 하는걸 연구하고 있음

 

*TLB 목적 메모리에 있는 page table 캐시하기 위함. (반복접근 cost를 줄인다.)

pagetable은 dram에 저장된다.

pagetable을 기록하고 업데이트하는건 운영체체의 역할

pagetable을 보고 virtual address를 translation하는 것은 하드웨어이다. (아키텍쳐)

 

when to allocate physical memory? 

demand paging -> 메모리 공간 효율성을 위해 ( application들이 alloc해놓고 바로바로안쓰기 떄문에)

* application first accesses unallocated physical memory

(page fault handler / physical memory manager)

 

memory allocation

malloc에 할당된 메모리가 초기화 되지 않는 이유?  os에 메모리를 바로 반납하지 않는다. (효율성을 위해)

mmap은 page를 새로 받아옴 (사용시 pagefault일으킴)

 

OS는 외우는 것이아니라 design을 이해하는 것이다. 

page fault handling

two types of memory 가 있음 anonymous memory(주인 없는 메모리 stack, heap 이해 잘 못함 키워드로 찾아보기)  // file blacked memory (data, code)

 

변외

**three easy pieces 책 좋음

** c에서 변수는 virtual address를 표현함

** 요즘 language (python, java .. )는 변수는 값의 개념임. 

--> variable이 가리키는 것은 language 철학마다 다르다.

 

abstraction of storage ->file

file : a logical unit of starage

identifier : pathname(path/filename) -> file을 identify

location of data is identified by (file id, offset)

OS subsystem maps the file to physical storage -> file system.

 

inode

 (metadata of a file 중)

direct blocks -> physical blocks

single indirect

double indirect 

triple indirect

 

file system은 crash consistency도 만족해야함 ***

Pesist 만족해야함

fsync -> inode와 data 동기화 (dram, disk)

 

consistency :

atomicity(data가 모두 update 되거나, 아에안되거나 둘중하나로) -> promgrammer의 몫

durability : 하드웨어의 몫

 

crash consistency example

 

roll back logging

1. create(/a/log) log file 만든다.

2. write(/a/log, "foo") 'foo' backup

3. write(/a/file, "bar") original file update 'bar' 

4. unlink(/a/log) log file을 지운다.

 

roll back logging

create(/a/log)

write(/a/log, "foo")

fsync(/a/log)

fsync (/a/) - 디렉토리 싱크

write(/a/file, "bar")

fsync(/a/file)

unlink(/a/log)

-> must understand, atomicity, ordering, and durability (including directory)