UNIX Chapter 3 Buffer Cache 2009 08 UNIX
UNIX 운영체제의 설계 Chapter 3. Buffer Cache 2009. 08 진현목 경희대학교
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache의 정의 디스크 블록 정보를 메모리 공간에 저장해두어 작업시 응답 시간 을 줄이게 해줌 ■ User Programs User Level trap Kernel Level Libraries System Call Interface File Subsystem Process Inter-process communication Control Scheduler Buffer cache Character Block Device drivers Hardware Level Subsystem Memory management hardware control hardware 그림 2. 1 Block Diagram of the System Kernel 4
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read Process (Block A) User Level Kernel Level System Call Interface File Subsystem Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 22
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) User Level Kernel Level System Call Interface File Subsystem Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 23
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) User Level Kernel Level System Call Interface File Subsystem 2. 버퍼에 있는지 확인 Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 24
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) User Level Kernel Level System Call Interface File Subsystem 2. 버퍼에 있는지 확인 Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) 3. 버퍼에 있으면 불러옴 Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 25
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) User Level Kernel Level System Call Interface File Subsystem 2. 버퍼에 없을 경우 Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 26
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) User Level Kernel Level System Call Interface File Subsystem 2. 버퍼에 없을 경우 3. Disk Driver 불러옴 Buffer Cache Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 27
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) User Level Kernel Level System Call Interface File Subsystem 2. 버퍼에 없을 경우 3. Disk Driver 불러옴 Buffer Cache 4. Read 스케줄링 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 28
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) 5. Process Sleep User Level Kernel Level System Call Interface File Subsystem 2. 버퍼에 없을 경우 3. Disk Driver 불러옴 Buffer Cache 4. Read 스케줄링 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 29
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) 5. Process Sleep User Level Kernel Level System Call Interface 6. 버퍼에 올림 File Subsystem 2. 버퍼에 없을 경우 3. Disk Driver 불러옴 Buffer Cache 4. Read 스케줄링 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 30
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) 5. Process Sleep User Level Kernel Level System Call Interface 6. 버퍼에 올림 File Subsystem 2. 버퍼에 없을 경우 3. Disk Driver 불러옴 Buffer Cache 4. Read 스케줄링 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 7. CPU 인터럽트 Hardware Level 31
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - Read 1. Block A Read 요청 Process (Block A) 8. Process를 깨움 User Level Kernel Level System Call Interface 6. 버퍼에 올림 File Subsystem 2. 버퍼에 없을 경우 3. Disk Driver 불러옴 Buffer Cache 4. Read 스케줄링 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 7. CPU 인터럽트 Hardware Level 32
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 성능 향상을 위해 Block A는 동기적, Process Block B는 비동기적으로 읽음 (Block A +Block B) User Level Kernel Level System Call Interface File Subsystem Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 33
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 Process (Block A +Block B) User Level Kernel Level System Call Interface File Subsystem Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 34
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 Process (Block A +Block B) User Level Kernel Level System Call Interface File Subsystem 2. 블록 A, 동기적 Read 지시 블록 B, 비동기적 Read 지시 Process Control Subsystem Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 35
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 Process (Block A +Block B) User Level Kernel Level System Call Interface File Subsystem Buffer Cache 2. 블록 A, 동기적 Read 지시 블록 B, 비동기적 Read 지시 3. 블록 A에 대한 I/O 스케줄링 블록 B에 대한 I/O 완료 여부 무시 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 36
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 Process (Block A +Block B) 4. Block A에 대한 I/O 종료 기다리며 Sleep Kernel Level System Call Interface File Subsystem Buffer Cache User Level 2. 블록 A, 동기적 Read 지시 블록 B, 비동기적 Read 지시 3. 블록 A에 대한 I/O 스케줄링 블록 B에 대한 I/O 완료 여부 무시 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 37
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 5. 블록 A를 버 퍼에 올림 사용 후 File Subsystem 프로세스 깨움 Buffer Cache Process (Block A +Block B) 4. Block A에 대한 I/O 종료 기다리며 Sleep User Level Kernel Level System Call Interface 2. 블록 A, 동기적 Read 지시 블록 B, 비동기적 Read 지시 3. 블록 A에 대한 I/O 스케줄링 블록 B에 대한 I/O 완료 여부 무시 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 38
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 5. 블록 A를 버 퍼에 올림 사용 후 File Subsystem 프로세스 깨움 Buffer Cache Process (Block A +Block B) 4. Block A에 대한 I/O 종료 기다리며 Sleep User Level Kernel Level System Call Interface 2. 블록 A, 동기적 Read 지시 블록 B, 비동기적 Read 지시 3. 블록 A에 대한 I/O 스케줄링 블록 B에 대한 I/O 완료 여부 무시 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 6. Block B의 I/O 끝나면 CPU Hardware 인터럽트 Level 39
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 순차적 Read 1. 블록 A, B Read 요청 5. 블록 A를 버 퍼에 올림 사용 후 File Subsystem 프로세스 깨움 Buffer Cache Process (Block A +Block B) System Call Interface 7. 인터럽트 핸들러는 Block B에 대한 비동기 읽기 인지 후 버퍼 방출 (lock 해제) User Level Kernel Level 2. 블록 A, 동기적 Read 지시 블록 B, 비동기적 Read 지시 3. 블록 A에 대한 I/O 스케줄링 블록 B에 대한 I/O 완료 여부 무시 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 6. Block B의 I/O 끝나면 CPU Hardware 인터럽트 Level 40
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 42
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache 2. 블록 입출력 스케줄 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 43
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 3. I/O 끝나기를 기다리며 Sleep Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache 2. 블록 입출력 스케줄 Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 44
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 3. I/O 끝나기를 기다리며 Sleep Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache 2. 블록 입출력 스케줄 Process Control Subsystem Device Driver (Disk Driver) 4. 쓰기 수 행 (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 45
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 3. I/O 끝나기를 기다리며 Sleep Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache 2. 블록 입출력 스케줄 Process Control Subsystem Device Driver (Disk Driver) 4. 쓰기 수 행 (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 5. Hardware CPU Level 인터럽트 46
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 6. I/O 끝난 후 깨움 Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache 2. 블록 입출력 스케줄 Process Control Subsystem Device Driver (Disk Driver) 4. 쓰기 수 행 (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 5. Hardware CPU Level 인터럽트 47
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 6. I/O 끝난 후 깨움 Process User Level Kernel Level System Call Interface 7. 버퍼반 환 File Subsystem 1. Disk Driver에게 알림 Buffer Cache 2. 블록 입출력 스케줄 Process Control Subsystem Device Driver (Disk Driver) 4. 쓰기 수 행 (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) 5. Hardware CPU Level 인터럽트 48
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 비동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 49
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 비동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 Process User Level Kernel Level System Call Interface File Subsystem 1. Disk Driver에게 알림 Buffer Cache Process Control Subsystem Device Driver (Disk Driver) 2. 쓰기 수 행 (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 50
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O – 비동기적 Write 사용된 버퍼 반환을 위해 디스크에 써야 할 경우 Process User Level Kernel Level System Call Interface 3. 버퍼반 환 File Subsystem 1. Disk Driver에게 알림 Buffer Cache Process Control Subsystem Device Driver (Disk Driver) 2. 쓰기 수 행 (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 51
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 Process User Level Kernel Level System Call Interface File Subsystem 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Process Control Subsystem Device Driver (Disk Driver) (Disk Controller) (Disk) Hardware Control Hardware (Interrupt Handler) (CPU) Hardware Level 52
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 Process User Level Kernel Level System Call Interface File Subsystem 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) 2. 다른 프로세스에서 사용하길 기대하며 최대한 쓰기 지연 I/O 스케줄 하지 않음 Hardware Control Hardware Process Control Subsystem (Interrupt Handler) (CPU) Hardware Level 53
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 3. 다른 프로세 스가 버퍼를 사용할 경우 write 하지 않 File Subsystem 음 Process User Level Kernel Level System Call Interface 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) 2. 다른 프로세스에서 사용하길 기대하며 최대한 쓰기 지연 I/O 스케줄 하지 않음 Hardware Control Hardware Process Control Subsystem (Interrupt Handler) (CPU) Hardware Level 54
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 Disk Access 3. 다른 프로세 1회 절약 스가 버퍼를 사용할 경우 write 하지 않 File Subsystem 음 Process User Level Kernel Level System Call Interface 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Device Driver (Disk Driver) (Disk Controller) (Disk) 2. 다른 프로세스에서 사용하길 기대하며 최대한 쓰기 지연 I/O 스케줄 하지 않음 Hardware Control Hardware Process Control Subsystem (Interrupt Handler) (CPU) Hardware Level 55
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 3. 다른 프로세 스가 버퍼를 사용할 경우 write 하지 않 File Subsystem 음 Process User Level Kernel Level System Call Interface 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Device Driver (Disk Driver) 4. 없을 경우 쓰기 수행 (Disk Controller) (Disk) 2. 다른 프로세스에서 사용하길 기대하며 최대한 쓰기 지연 I/O 스케줄 하지 않음 Hardware Control Hardware Process Control Subsystem (Interrupt Handler) (CPU) Hardware Level 56
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 3. 다른 프로세 스가 버퍼를 사용할 경우 write 하지 않 File Subsystem 음 Process User Level Kernel Level System Call Interface 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Device Driver (Disk Driver) 4. 없을 경우 쓰기 수행 (Disk Controller) (Disk) 2. 다른 프로세스에서 사용하길 기대하며 최대한 쓰기 지연 I/O 스케줄 하지 않음 Hardware Control Hardware Process Control Subsystem (Interrupt Handler) (CPU) 5. 버퍼 반환 을 위해 CPU Hardware 인터럽트 Level 57
UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3. 4 디스크 블록의 I/O - 지연쓰기 불필요한 I/O를 피하기 위해 사용 3. 다른 프로세 스가 버퍼를 사용할 경우 write 하지 않 File Subsystem 음 Process System Call Interface 6. 버퍼는 Old 였기 때문에 프리 리스트 상의 맨 앞에 위치하게 된다 (LRU 알고리즘) 1. Buffer에 Old 라고 표기 후 Disk Driver에게 알림 Buffer Cache Device Driver (Disk Driver) 4. 없을 경우 쓰기 수행 (Disk Controller) (Disk) 2. 다른 프로세스에서 사용하길 기대하며 최대한 쓰기 지연 I/O 스케줄 하지 않음 Hardware Control Hardware User Level Kernel Level Process Control Subsystem (Interrupt Handler) (CPU) 5. 버퍼 반환 을 위해 CPU Hardware 인터럽트 Level 58
- Slides: 62