Transcript 설명: 설명: 설명
UNIX 운영체제의 설계 Chapter 3. Buffer Cache 2009. 08. 08 진현목 경희대학교 Contents Ⅰ 정의 및 버퍼 헤더 Ⅱ 버퍼풀의 구조 Ⅲ 버퍼를 가져오는 시나리오 Ⅳ 디스크 블럭의 I/O V 버퍼 캐쉬의 장∙단점 2 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache Ⅰ 정의 및 버퍼 헤더 Ⅱ 버퍼풀의 구조 Ⅲ 버퍼를 가져오는 시나리오 Ⅳ 디스크 블럭의 I/O V 버퍼 캐쉬의 장∙단점 3 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache Buffer Cache의 정의 디스크 블록 정보를 메모리 공간에 저장해두어 작업시 응답 시간 을 줄이게 해줌 ■ User Programs User Level Libraries trap Kernel Level System Call Interface Process Inter-process communication Control Scheduler File Subsystem 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.1 버퍼 헤더 (Buffer Header) ■ 버퍼 : 실제 데이터 영역 + 버퍼 헤더로 구성 ■ 장치 번호와 블록 번호로 고유한 버퍼 식별 장치 번호 블록 번호 데이터 영역의 포인터 상태 해쉬큐의 앞 버퍼의 포인터 해쉬큐의 다음 버퍼의 포인터 프리 리스트의 앞 버퍼의 포인터 프리 리스트의 다음 버퍼의 포인터 그림 3. 1 버퍼헤더 5 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache Ⅰ 정의 및 버퍼 헤더 Ⅱ 버퍼풀의 구조 Ⅲ 버퍼를 가져오는 시나리오 Ⅳ 디스크 블럭의 I/O V 버퍼 캐쉬의 장∙단점 6 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3.2 버퍼풀의 구조 ■ 버퍼의 Free List 커널은 LRU 알고리즘에 의해 버퍼들을 연결한 프리 리스트를 보관 프리 리스트 앞부분에서 버퍼를 취하고 리스트에서 제거 후 사용한 버 퍼는 끝에 삽입 프리 리스트 헤드 앞쪽 포인터 버퍼 1 버퍼 2 뒤쪽 포인터 전 후 프리 리스트 헤드 buf n 앞쪽 포인터 버퍼 2 buf n 뒤쪽 포인터 그림 3. 2 버퍼의 프리 리스트 7 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3.2 버퍼풀의 구조 ■ 해쉬큐의 버퍼 버퍼의 장치번호와 블록번호를 hashing 하여 별도의 queue로 구성 해쉬큐 헤더 blkno 0 mod 4 28 4 64 blkno 1 mod 4 17 5 97 blkno 2 mod 4 98 50 10 blkno 3 mod 4 3 35 99 프리 리스트 헤더 그림 3. 3 해쉬큐의 버퍼 8 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache Ⅰ 정의 및 버퍼 헤더 Ⅱ 버퍼풀의 구조 Ⅲ 버퍼를 가져오는 시나리오 Ⅳ 디스크 블럭의 I/O V 버퍼 캐쉬의 장∙단점 9 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3.3 버퍼를 가져오는 시나리오 ■ 버퍼 할당 알고리즘 getblk 알고리즘의 전형적 시나리오 • 시나리오 1 - 해쉬큐에서 그 블록을 발견하였으며 그 버퍼가 자유일 경우 • 시나리오 2 - 해쉬큐에서 그 블록을 찾지 못하여 프리 리스트로부터 버퍼를 할당 • 시나리오 3 - 시나리오 2에서 프리 리스트상의 버퍼가 지연 쓰기인 경우 • 시나리오 4 - 해쉬큐에서 그 블록을 발견하지 못하고 프리 리스트도 비어 있는 경우 • 시나리오 5 - 해쉬큐에서 그 블록을 발견하였으나 그 버퍼가 현재 사용중인 경우 10 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 시나리오 1 ■ 해쉬큐에서 그 블록을 발견하였으며 그 버퍼가 자유일 경우 해쉬큐 헤더 blkno 0 mod 4 blkno 1 mod 4 blkno 2 mod 4 blkno 3 mod 4 해쉬큐 헤더 28 4 64 17 5 97 98 50 10 3 35 99 프리 리스트 헤더 blkno 0 mod 4 blkno 1 mod 4 blkno 2 mod 4 blkno 3 mod 4 28 4 64 17 5 97 98 50 10 3 35 99 프리 리스트 헤더 3 -> 5 -> 4 -> 28 -> 97 -> 10 (a) 첫 해쉬큐의 블럭 4를 탐색 3 -> 5 -> 28 -> 97 -> 10 (b) 프리 리스트에서 블럭 4를 제거 그림 3. 5 해쉬큐의 버퍼를 찾는 시나리오 1 11 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 시나리오 2 ■ 해쉬큐에서 그 블록을 찾지 못하여 프리 리스트로부터 버퍼를 할당 해쉬큐 헤더 blkno 0 mod 4 blkno 1 mod 4 blkno 2 mod 4 blkno 3 mod 4 해쉬큐 헤더 28 4 64 17 5 97 98 50 10 3 35 99 프리 리스트 헤더 blkno 0 mod 4 blkno 1 mod 4 blkno 2 mod 4 blkno 3 mod 4 28 4 64 17 5 97 98 50 10 35 99 18 프리 리스트 헤더 3 -> 5 -> 4 -> 28 -> 97 -> 10 (a) 캐쉬에 없는 블록 18을 탐색 5 -> 4 -> 28 -> 97 -> 10 (b) 프리 리스트에서 첫 블록 제거, 18로 할당 그림 3. 7 버퍼를 할당하는 두 번째 시나리오 12 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 시나리오 3 ■ 시나리오 2에서 프리 리스트상의 버퍼가 지연 쓰기인 경우 해쉬큐 헤더 blkno 0 mod 4 blkno 1 mod 4 해쉬큐 헤더 28 4 64 17 5 97 blkno 0 mod 4 28 blkno 1 mod 4 17 Delay blkno 2 mod 4 blkno 3 mod 4 프리 리스트 헤더 64 5 97 Writing 98 50 10 3 35 99 Delay blkno 2 mod 4 blkno 3 mod 4 98 50 10 3 35 99 18 Writing 프리 리스트 헤더 3 -> 5 -> 4 -> 28 -> 97 -> 10 28 -> 97 -> 10 (a) 프리 리스트에 연기된 블럭 18을 탐색 (b) 블럭 3, 5를 쓰고 4를 18로 할당 그림 3. 7 버퍼를 할당하는 세 번째 시나리오 13 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 시나리오 4 ■ 해쉬큐에서 그 블록을 발견하지 못하고 프리 리스트도 비어 있는 경우 프로세스 A 해쉬큐 헤더 blkno 0 mod 4 blkno 1 mod 4 blkno 2 mod 4 프로세스 B 해쉬큐에서 블록 b를 찾을 수 없음 28 4 64 프리 리스트에 블록이 없음 Sleep 17 5 97 98 50 10 해쉬큐에서 블록 b를 찾을 수 없음 프리 리스트에 블록이 없음 Sleep blkno 3 mod 4 3 35 99 누군가가 이 버퍼를 자유화함 프리 리스트에서 버퍼를 가져옴 프리 리스트 헤더 비어있는 프리 리스트에서 블럭 18을 탐색 그림 3. 9 버퍼를 할당하는 네 번째 시나리오 시간 블록 b에 할당 그림 3. 10 프리 블록에 대한 경쟁 14 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 시나리오 5 ■ 해쉬큐에서 그 블록을 발견하였으나 그 버퍼가 현재 사용중인 경우 해쉬큐 헤더 blkno 0 mod 4 blkno 1 mod 4 blkno 2 mod 4 blkno 3 mod 4 28 4 64 17 5 97 98 50 10 3 35 99 Busy 프리 리스트 헤더 Busy 블록인 블록 99를 탐색 그림 3. 5 해쉬큐의 버퍼를 찾는 다섯 번째 시나리오 15 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 시나리오 5 ■ 해쉬큐에서 그 블록을 발견하였으나 그 버퍼가 현재 사용중인 경우 프로세스 A 블록 b에 버퍼를 할당 버퍼를 Lock I/O를 초기화 I/O가 끝날때까지 Sleep 프로세스 B 해쉬큐에서 블록 b를 찾음 버퍼가 Lock 되어 있음, Sleep 프로세스 C 프리 버퍼가 생길때까지 기다리면서 Sleep (시나리오 4) I/O가 끝남, 깨움 brelse () : 다른 것을 깨움 전에 블럭 b에 할당된 버퍼를 얻음 블럭 b’에 재할당 시간 버퍼는 block b를 가지지 않는다. 다시 탐색한다. 그림 3. 12 Locked 버퍼의 경쟁 16 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 버퍼 할당 알고리즘의 조건 ■ 안전성 프로세스들이 무한 sleep 에 빠지지 않아야 함 디스크 고장으로 CPU를 인터럽트 하지 못해 커널의 버퍼 반환 불가능 을 고려해 하드웨어 고장을 검사하고 디스크 오류를 커널에 알려야 함 ■ Starvation의 고려 버퍼가 자유화 되기를 기다리며 다음 프로세스들이 sleep 할 경우 기 다리는 프로세스들이 starvation 될 수 있음 17 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 버퍼 할당 알고리즘 ■ getblk 알고리즘 입력 파일시스템번호, 블록번호 출력 블록에 사용할 수 있는 로크된 버퍼 18 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 버퍼 해방 알고리즘 ■ brelse 알고리즘 입력 : 로크된 버퍼 출력 : 없음 19 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache Ⅰ 정의 및 버퍼 헤더 Ⅱ 버퍼풀의 구조 Ⅲ 버퍼를 가져오는 시나리오 Ⅳ 디스크 블럭의 I/O V 버퍼 캐쉬의 장∙단점 20 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3.4 디스크 블록의 I/O ■ Read 한 개의 블록만을 읽을 경우 두 개의 블록을 순차적으로 읽을 경우 • 효율적 access를 위해 첫 번째 블록은 즉시 읽기, 두 번째 블록은 비동기 읽 기 실행 21 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 동기적 Write • I/O 종료를 기다림 비동기적 Write • 디스크에 쓰기 시작하지만 I/O 종료를 기다리지 않음 지연쓰기 • 불필요한 I/O 방지 위해 최대한 디스크에 쓰기 지연 41 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. CPU Hardware 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. CPU Hardware 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. CPU Hardware 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. 다른 프로세스가 버퍼를 사용할 File Subsystem 경우 write 하지 않음 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회 절약 프로세스가 버퍼를 사용할 File Subsystem 경우 write 하지 않음 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. 다른 프로세스가 버퍼를 사용할 File Subsystem 경우 write 하지 않음 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. 다른 프로세스가 버퍼를 사용할 File Subsystem 경우 write 하지 않음 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. 다른 프로세스가 버퍼를 사용할 File Subsystem 경우 write 하지 않음 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 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache Ⅰ 정의 및 버퍼 헤더 Ⅱ 버퍼풀의 구조 Ⅲ 버퍼를 가져오는 시나리오 Ⅳ 디스크 블럭의 I/O V 버퍼 캐쉬의 장∙단점 59 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3.5 버퍼 캐쉬의 장점 ■ 간단한 시스템 설계 버퍼를 사용함으로써 커널이 I/O에 대한 이유를 일일히 알 필요가 없 어지기 때문에 일관된 디스크 접근 가능 ■ 높은 이식성 커널이 내부적으로 데이터를 정렬하기 때문에 개발자들이 일일히 데 이터 정렬을 신경 쓸 필요가 없음 ■ 낮은 disk traffic 캐쉬의 데이터 블록만 있으면 디스크 I/O가 필요 없으므로 불필요한 탐색을 줄일 수 있음 ■ 데이터의 무결성 유지 캐쉬에서 공통된 단 하나만의 버퍼를 유지하므로 데이터 뒤섞임 방지 60 UNIX 운영체제의 설계 – Chapter 3. Buffer Cache 3.5 버퍼 캐쉬의 단점 ■ 시스템 성능 저하 우려 너무 많은 메모리를 버퍼에 할당하면 paging이 잦아지게 됨 ■ 두 번의 데이터 복사 프로세스가 데이터를 write할 때는 커널에 데이터를 쓰고 디스크로 옮 기고 read할 때는 디스크에서 커널로 옮기게 되는 2번의 복사 작업이 대용량 데이터 사용시 시스템 성능을 저하시킴 61 감사합니다