Chapter 3 Buffer Cache TOPICS UNIX system Architecture Buffer Cache

Slides:



Advertisements
Similar presentations
More on File Management
Advertisements

Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
The Linux Kernel: Memory Management
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Management.
Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Introduction to Kernel
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
1 I/O Management in Representative Operating Systems.
Chapter 3 Buffer Cache TOPICS UNIX system Architecture Buffer Cache
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
CSC 322 Operating Systems Concepts Lecture - 25: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Chapter 4. INTERNAL REPRESENTATION OF FILES
10/23/ File System Architecture. 10/23/ / bin unixdev etc user jim mike x y z tty00 tty01 File System architecture.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
LINUX System : Lecture 7 Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
Chapter 4. INTERNAL REPRESENTATION OF FILES
Digital UNIX Internals II4 - 1Buffer Caches Chapter Four.
1 Chapter 4. INTERNAL REPRESENTATION OF FILES THE DESIGN OF THE UNIX OPERATING SYSTEM Maurice J. bach Prentice Hall.
Linux File system Implementations
Foundation of Unix Operating Systems
11.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 11.5 Free-Space Management Bit vector (n blocks) … 012n-1 bit[i] =  1  block[i]
DFS DBufferCache DBuffer VirtualDisk startRequest(dbuf, r/w) ioComplete() blockID = getBlockID() buf[] = getBuffer() read(), write() startFetch(), startPush()
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
4P13 Week 9 Talking Points
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 7 – Buffer Management.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Real Numbers Device driver process within the operating system that interacts with I/O controller logical record 1 logical record 2 logical record 3.
General overview of the Unix System Kernel Sub In-charge: Mr. V. V. Bhujade Dept. of CSE DMIETR, Wardha.
CSCE451/851 Introduction to Operating Systems
Input/Output (I/O) Important OS function – control I/O
Introduction to Kernel
Data Structures Using C, 2e
EmuOS Phase 3 Design Brendon Drew Will Mosley Anna Clayton
Chapter 11: File System Implementation
Chapter 9: Virtual Memory
Structure of Processes
The Buffer Cache.
Protection of System Resources
Lecture Topics: 11/1 Processes Process Management
Modeling Page Replacement Algorithms
Buffer Cache.
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Structure of Processes
Chapter 3: Windows7 Part 2.
Circular Buffers, Linked Lists
File Systems Directories Revisited Shared Files
Chapter 9: Virtual-Memory Management
Chapter 3: Windows7 Part 2.
CSC 660: Advanced Operating Systems
Modeling Page Replacement Algorithms
Lecture Topics: 11/1 General Operating System Concepts Processes
Chapter 5: I/O Systems.
LINUX System : Lecture 7 Lecture notes acknowledgement : The design of UNIX Operating System.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
UNIX File Systems (Chap 4. in the book “the design of the UNIX OS”)
Week 9 March 4, 2004 Adrienne Noble.
Lecture 9: Caching and Demand-Paged Virtual Memory
Internal Representation of Files
Structure of Processes
Chapter 12: File-System Implementation CSS503 Systems Programming
Mr. M. D. Jamadar Assistant Professor
CSE 542: Operating Systems
LINUX System : Lecture 6 Bong-Soo Sohn
The File Manager Implementation issues
Presentation transcript:

Chapter 3 Buffer Cache TOPICS UNIX system Architecture Buffer Cache Buffer Pool Structure Retrieval of Buffe Release Buffer Reading and Writing Disk Blocks Reference: The Design of the UNIX Operating System by Maurice J. Bach

UNIX Kernel Architecture libraries User level Kernel level User programs hardware Hardware level trap Sytem call interface File subsytem Buffer cache Chracter block Device drivers Hardware control Inter-process communication scheduler Memory management Process control sybsystem

Buffer Cache When a process wants to access data from a file, the kernel brings the data into main memory, alters it and then request to save in the file system Example: copy cp one.c two.c To increase the response time and throughput, the kernel minimizes the frequency of disk access by keeping a pool of internal data buffer called buffer cache.

Buffer Cache Buffer cache contains the data in recently used disk blocks When reading data from disk, the kernel attempts to read from buffer cache. If data is already in the buffer cache, the kernel does not need to read from disk If data is not in the buffer cache, the kernel reads the data from disk and cache it

Buffer Headers A buffer consists of two parts a memory array buffer header disk block : buffer = 1 : 1 Figure 3.1 Buffer Header device num block num status ptr to next buf on hash queue ptr to previous buf on hash queue ptr to next buf on free list ptr to previous buf on free list ptr to data area

Buffer Headers device num block num status logical file system number block num block number of the data on disk status The buffer is currently locked. The buffer contains valid data. delayed-write The kernel is currently reading or writing the contents of the disk. A process is currently waiting for the buffer to become free. kernel identifies the buffer content by examing device num and block num.

Buffer Headers struct buffer_head{ /*First cache line: */ struct buffer_head *b_next; /*Hash queue list*/ unsigned long b_blocknr; /*block number*/ unsigned long b_size; /*block size*/ kdev_t b_dev; /*device(B_FREE = free)*/ kdev_t b_rdev; /*Read device*/ unsigned long b_rsector; /*Real Buffer location on disk*/ struct buffer_head *b_this_page; /*circular list of buffers in one page*/ unsigned long b_state; /*buffer state bitmap(see above)*/ struct buffer_head *b_next_free; unsigned int b_count; /*users using this block*/ char *b_data; /*pointer to data block(1024 bytes)*/ unsigned int b_list; /*List that this buffer appears*/ unsigned long b_flushtime; /*Time when this(dirty) buffer should be written*/ struct wait_queue *b_wait; struct buffer_head **b_pprev; /*doubly linked list of hash-queue*/ struct buffer_head *b_prev_free; /* double linked list of buffers*/ struct buffer_head *b_reqnext; /*request queue*/ /*I/O completion*/ void (*b_end_io)(struct buffer_head *bh, int uptodate); void *b_dev_id; };

Buffer Headers /* buffer head state bits*/ #define BH_Uptodate 0 /*1 if the buffer contains valid data*/ #define BH_Dirty 1 /*1 if the buffer is dirty*/ #define BH_Lock 2 /*1 if the buffer is locked*/ #define BH_Req 3 /*0 if the buffer has been invalidated*/ #define BH_Protected 6 /*1 if the buffer is protected*/

Structures of the buffer pool Buffer pool according to LRU The kernel maintains a free list of buffer doubly linked list take a buffer from the head of the free list. When returning a buffer, attaches the buffer to the tail. free list head buf 1 buf 2 buf n Forward ptrs Back ptrs Figure 3.2 Free list of Buffers

Structures of the buffer pool When the kernel accesses a disk block separate queue (doublely linked circular list) hashed as a function of the device and block num Every disk block exists on one and only on hash queue and only once on the queue 4 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers Figure 3.3 Buffers on the Hash Queues

Scenarios for retrieval of a buffer Determine the logical device num and block num The algorithms for reading and writing disk blocks use the algorithm getblk The kernel finds the block on its hash queue The buffer is free. The buffer is currently busy. The kernel cannot find the block on the hash queue The kernel allocates a buffer from the free list. In attempting to allocate a buffer from the free list, finds a buffer on the free list that has been marked “delayed write”. The free list of buffers is empty.

Retrieval of a Buffer:1st Scenario (a) The kernel finds the block on the hash queue and its buffer is free 4 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers freelist header Search for block 4

Retrieval of a Buffer:1st Scenario (b) 4 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 freelist header Remove block 4 from free list

Retrieval of a Buffer: 2nd Scenario (a) The kernel cannot find the block on the hash queue, so it allocates a buffer from free list 4 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers freelist header Search for block 18: Not in cache

Retrieval of a Buffer: 2nd Scenario (b) Hash queue headers 18 4 5 17 10 50 98 99 35 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 freelist header Remove 1st block from free list: Assign to 18

Retrieval of a Buffer: 3rd Scenario (a) The kernel cannot find the block on the hash queue, and finds delayed write buffers on hash queue 4 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers freelist header delay delay Search for block 18, Delayed write blocks on free list

Retrieval of a Buffer: 3rd Scenario (b) 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers freelist header 18 writing (b) Writing Blocks 3, 5, Reassign 4 to 18 Figure 3.8

Retrieval of a Buffer: 4th Scenario The kernel cannot find the buffer on the hash queue, and the free list is empty 28 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers freelist header 4 64 5 97 17 10 50 98 99 35 3 Search for block 18, free list empty

Retrieval of a Buffer: 5th Scenario Kernel finds the buffer on hash queue, but it is currently busy 4 5 17 10 50 98 99 35 3 28 64 97 blkno0 mod 4 blkno1 mod 4 blkno2 mod 4 blkno3 mod 4 Hash queue headers freelist header busy Search for block 99, block busy

Algorithm: GetBlock GetBlock (file_system_no,block_no) while (buffer not found) if (buffer in hash queue) if (buffer busy) sleep (event buffer becomes free) continue mark buffer busy remove buffer from free list return buffer else if (there is no buffer on free list) sleep (event any buffer becomes free) if (buffer marked as delayed write) asyschronous white buffer to disk remove buffer from hash queue put buffer onto hash queue

Algorithm: ReleaseBlock ReleaseBlock (locked buffer) wakeup all process event, waiting for any buffer to become free wakeup all process event, waiting for this buffer to become free raise processor execution level to block interrupt if (buffer content valid and buffer not old) enqueue buffer at the end of free list else enqueue buffer at the beginning of free list lower processor execution level to allow interrupt unlock (buffer)

Reading and Writing disk blocks To read block ahead The kernel checks if the block is in the cache or not. If the block in not in the cache, it invokes the disk driver to read the block. The the process goes to sleep awaiting the event that the I/O is complete. The disk controller interrupts the processor when the I/O is complete The disk interrupt handler awakens the sleeping processes The content of disk blocks are now in the buffer When the process no longer need the buffer, it releases it so that other processes can access it

Reading and Writing disk blocks To write a disk block The kernel informs the disk driver that it has a buffer whose contents should be output. The disk driver schedules the block for I/O. If the write is synchronous, the calling process goes the sleep awaiting I/O completion and releases the buffer when awakens. If the write is asynchronous, the kernel starts the disk write. The kernel release the buffer when the I/O completes.