SlideShare a Scribd company logo
Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Prof. A. V. Brahmane
Assistant Professor
E-mail : brahmaneanilkumarcomp@sanjivani.org.in
Contact No: 91301 91301 Ext :145, 9922827812
Subject- Operating System and Administration (CO2013)
Unit II- Buffer Cache
Content
• Buffer cache
• Buffer Headers
• Structre of the Buffer Pool
• Scenaios for retrival of a buffer
• Reading and Writing Disk blocks
• Advntages and disadvantages of buffer cache
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
The Buffer Cache
• The kernel could read and write directly to and from the disk for all the file system accesses, but
system response time and throughput will be poor because of the slow disk transfer rate.
• The kernel therefore attempts to minimize the frequency of disk access by keeping a pool of data
buffers, called the buffer cache, which contains data in recently used disk blocks.
• Architecturally, it is positioned between file subsystem and device drivers.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Buffer Headers
• During system initialization, the kernel allocates space for a number of buffers,
configurable according to memory size and performance constraints.
• Two parts of the buffer:
1.a memory array that contains data from the disk.
2.buffer header that identifies the buffer.
• Data in a buffer corresponds to data in a logical disk block on a file system. A disk
block can never map into more than one buffer at a time.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Buffer Header
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• The device number fields specifies the logical file system (not physical device) and block
number block number of the data on disk. These two numbers uniquely identify the buffer. The
status field summarizes the current status of the buffer. The ptr to data area is a pointer to the
data area, whose size must be at least as big as the size of a disk block.
• The status of a buffer is a combination of the following conditions:
• Buffer is locked / busy
• Buffer contains valid data
• Kernel must write the buffer contents to disk before reassigning the buffer; called as "delayed-
write"
• Kernel is currently reading or writing the contexts of the buffer to disk
• A process is currently waiting for the buffer to become free.
• The two set of pointers in the header are used for traversal of the buffer queues (doubly linked
circular lists).
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Structure of the Buffer Pool
• The kernel follows the least recently unused (LRU) algorithm for the buffer pool.
• The kernel maintains a free list of buffers that preserves the least recently used order.
• Dummy buffer header marks the beginning and end of the list.
• All the buffers are put on the free list when the system is booted.
• When the kernel wants any buffer, it takes it from the head of the free list.
• But it can also take a specific buffer from the list.
• The used buffers, when become free, are attached to the end of the list, hence the buffers closer
and closer to the head of the list are the most recently used ones.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Free list of buffers
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• When the kernel accesses a disk block, it searches for the buffer with the
appropriate device-block number combination.
• Rather than search the entire buffer pool, it organizes the buffers into separate
queues, hashed as a function of the device and block number.
• The hash queues are also doubly linked circular lists.
• A hashing function which uniformly distributes the buffers across the lists is used.
• But it also has to be simple so that the performance does not suffer.
Buffers on the Hash Queues
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Buffers on the Hash Queues
• The hash function shown in the figure only depends on the block number; real
hash functions depend on device number as well.
• Every disk block in the buffer pool exists on one and only one hash queue and
only once on that queue.
• However, presence of a buffer on a hash queue does not mean that it is busy, it
could well be on the free list as well if its status is free.
• Therefore, if the kernel wants a particular buffer, it will search it on the queue.
But if it wants any buffer, it removes a buffer from the free list. A buffer is always
on a hash queue, but it may or may not be on the free list
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Scenarios for Retrieval of a Buffer
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• The algorithms for reading and writing disk blocks use the algorithm getblk to allocate buffers
from the pool. There are 5 typical scenarios the kernel may follow in getblk to allocate a buffer for
a disk block.
• 1.Block is found on its hash queue and its buffer is free.
• 2.Block could not be found on the hash queue, so a buffer from the free list is allocated.
• 3.Block could not be found on the hash queue, and when allocating a buffer from free list, a
buffer marked "delayed write" is allocated. Then the kernel must write the "delayed write" buffer
to disk and allocate another buffer.
• 4.Block could not be found on the hash queue and the free list of buffers is empty.
• 5.Block was found on the hash queue, but its buffer is currently busy.
Algorithm for Buffer allocation
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Algorithm for releasing a buffer
• When using the buffer, the kernel always marks the buffer as busy so that no
other process can access it.
• When the kernel finishes using the buffer, it releases the buffer according to the
algorithm brelse
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Buffer releasing.....
• Buffer contents are old only if it is marked as "delayed write", in that case and in the case where
the data is not valid (for example, due to I/O corruption), the buffer is put in the beginning of the
free list as its data is not valid or old.
• Otherwise the data is valid as the buffer is put at the end to follow the LRU strategy.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Scenario 1
• The states of hash queues for different scenarios are shown in following figures :
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Scenario 2
• Here the buffer is not on the hash queue, so a buffer from free list is removed and then its device
and block numbers are changed.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Scenario 3
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• Cannot find block on the hash queue => allocate a buffer from free list but buffer
on the free list marked “delayed write” => flush “delayed write” buffer and
allocate another buffer.
Scenario 4
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Cannot find block on the hash queue and free list of buffer also empty.
Scenario 5
• Block in the hash queue, but buffer is busy.
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Reading and Writing Disk Blocks
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Reading and writing disk blocks....
•
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Writing a disk block
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Advantages of the buffer cache
• Uniform disk access => system design simpler
• Copying data from user buffers to system buffers => eliminates the need for
special alignment of user buffers.
• Use of the buffer cache can reduce the amount of disk traffic.
• Single image of of disk blocks contained in the cache => helps insure file system
integrity
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
Disadvantages of the buffer cache
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
• Delayed write => vulnerable to crashes that leave disk data in
incorrect state
• An extra data copy when reading and writing to and from user
processes => slow down when transmitting large data
•
• Thank you …
DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon

More Related Content

Similar to Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)

Progress Openedge performance management
Progress Openedge performance managementProgress Openedge performance management
Progress Openedge performance management
Yassine MOALLA
 
Progress OE performance management
Progress OE performance managementProgress OE performance management
Progress OE performance management
Yassine MOALLA
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
BLACKSPAROW
 
M2 212-unix fs-rl_2.1.2
M2 212-unix fs-rl_2.1.2M2 212-unix fs-rl_2.1.2
M2 212-unix fs-rl_2.1.2
MrudulaJoshi10
 
ch2.pptx
ch2.pptxch2.pptx
ch2.pptx
Halogens
 
kerch04.ppt
kerch04.pptkerch04.ppt
kerch04.ppt
KalimuthuVelappan
 
SFBigAnalytics_20190724: Monitor kafka like a Pro
SFBigAnalytics_20190724: Monitor kafka like a ProSFBigAnalytics_20190724: Monitor kafka like a Pro
SFBigAnalytics_20190724: Monitor kafka like a Pro
Chester Chen
 
bufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentationbufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentation
JohnLagman3
 
Java NIO Buffer basics
Java NIO Buffer basicsJava NIO Buffer basics
Java NIO Buffer basics
zarigatongy
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
قصي نسور
 
Kernel Memory Allocation, Review of Relocation & Program Forms
Kernel Memory Allocation, Review of Relocation & Program FormsKernel Memory Allocation, Review of Relocation & Program Forms
Kernel Memory Allocation, Review of Relocation & Program Forms
Meghaj Mallick
 
BSP.pptx
BSP.pptxBSP.pptx
BSP.pptx
taruian
 
Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)
AnilkumarBrahmane2
 
Conditional branches
Conditional branchesConditional branches
Conditional branches
Dilip Mathuria
 
515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx
ssuser03ec3c
 
Cache simulator
Cache simulatorCache simulator
Cache simulator
Suraj Saini
 
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Hsien-Hsin Sean Lee, Ph.D.
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
Dr. Loganathan R
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
ssusere16bd9
 
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.pptUnit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
AnilkumarBrahmane2
 

Similar to Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache) (20)

Progress Openedge performance management
Progress Openedge performance managementProgress Openedge performance management
Progress Openedge performance management
 
Progress OE performance management
Progress OE performance managementProgress OE performance management
Progress OE performance management
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
M2 212-unix fs-rl_2.1.2
M2 212-unix fs-rl_2.1.2M2 212-unix fs-rl_2.1.2
M2 212-unix fs-rl_2.1.2
 
ch2.pptx
ch2.pptxch2.pptx
ch2.pptx
 
kerch04.ppt
kerch04.pptkerch04.ppt
kerch04.ppt
 
SFBigAnalytics_20190724: Monitor kafka like a Pro
SFBigAnalytics_20190724: Monitor kafka like a ProSFBigAnalytics_20190724: Monitor kafka like a Pro
SFBigAnalytics_20190724: Monitor kafka like a Pro
 
bufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentationbufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentation
 
Java NIO Buffer basics
Java NIO Buffer basicsJava NIO Buffer basics
Java NIO Buffer basics
 
Buffer overflow
Buffer overflowBuffer overflow
Buffer overflow
 
Kernel Memory Allocation, Review of Relocation & Program Forms
Kernel Memory Allocation, Review of Relocation & Program FormsKernel Memory Allocation, Review of Relocation & Program Forms
Kernel Memory Allocation, Review of Relocation & Program Forms
 
BSP.pptx
BSP.pptxBSP.pptx
BSP.pptx
 
Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)Unit 4 File Management System.ppt (File Services)
Unit 4 File Management System.ppt (File Services)
 
Conditional branches
Conditional branchesConditional branches
Conditional branches
 
515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx515689311-Postgresql-DBA-Architecture.pptx
515689311-Postgresql-DBA-Architecture.pptx
 
Cache simulator
Cache simulatorCache simulator
Cache simulator
 
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Cache Memory.pptx
Cache Memory.pptxCache Memory.pptx
Cache Memory.pptx
 
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.pptUnit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
Unit 3.1 The Structure of Process, Process Control, Process Scheduling.ppt
 

Recently uploaded

Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 

Recently uploaded (20)

Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 

Unit 2.2. Buffer Cache.pptx (Introduction to Buffer Chache)

  • 1. Sanjivani Rural Education Society’s Sanjivani College of Engineering, Kopargaon-423 603 (An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune) NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified Department of Computer Engineering (NBA Accredited) Prof. A. V. Brahmane Assistant Professor E-mail : brahmaneanilkumarcomp@sanjivani.org.in Contact No: 91301 91301 Ext :145, 9922827812 Subject- Operating System and Administration (CO2013) Unit II- Buffer Cache
  • 2. Content • Buffer cache • Buffer Headers • Structre of the Buffer Pool • Scenaios for retrival of a buffer • Reading and Writing Disk blocks • Advntages and disadvantages of buffer cache DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 3. The Buffer Cache • The kernel could read and write directly to and from the disk for all the file system accesses, but system response time and throughput will be poor because of the slow disk transfer rate. • The kernel therefore attempts to minimize the frequency of disk access by keeping a pool of data buffers, called the buffer cache, which contains data in recently used disk blocks. • Architecturally, it is positioned between file subsystem and device drivers. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 4. Buffer Headers • During system initialization, the kernel allocates space for a number of buffers, configurable according to memory size and performance constraints. • Two parts of the buffer: 1.a memory array that contains data from the disk. 2.buffer header that identifies the buffer. • Data in a buffer corresponds to data in a logical disk block on a file system. A disk block can never map into more than one buffer at a time. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 5. Buffer Header DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 6. • The device number fields specifies the logical file system (not physical device) and block number block number of the data on disk. These two numbers uniquely identify the buffer. The status field summarizes the current status of the buffer. The ptr to data area is a pointer to the data area, whose size must be at least as big as the size of a disk block. • The status of a buffer is a combination of the following conditions: • Buffer is locked / busy • Buffer contains valid data • Kernel must write the buffer contents to disk before reassigning the buffer; called as "delayed- write" • Kernel is currently reading or writing the contexts of the buffer to disk • A process is currently waiting for the buffer to become free. • The two set of pointers in the header are used for traversal of the buffer queues (doubly linked circular lists). DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 7. Structure of the Buffer Pool • The kernel follows the least recently unused (LRU) algorithm for the buffer pool. • The kernel maintains a free list of buffers that preserves the least recently used order. • Dummy buffer header marks the beginning and end of the list. • All the buffers are put on the free list when the system is booted. • When the kernel wants any buffer, it takes it from the head of the free list. • But it can also take a specific buffer from the list. • The used buffers, when become free, are attached to the end of the list, hence the buffers closer and closer to the head of the list are the most recently used ones. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 8. Free list of buffers DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 9. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon • When the kernel accesses a disk block, it searches for the buffer with the appropriate device-block number combination. • Rather than search the entire buffer pool, it organizes the buffers into separate queues, hashed as a function of the device and block number. • The hash queues are also doubly linked circular lists. • A hashing function which uniformly distributes the buffers across the lists is used. • But it also has to be simple so that the performance does not suffer.
  • 10. Buffers on the Hash Queues DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 11. Buffers on the Hash Queues • The hash function shown in the figure only depends on the block number; real hash functions depend on device number as well. • Every disk block in the buffer pool exists on one and only one hash queue and only once on that queue. • However, presence of a buffer on a hash queue does not mean that it is busy, it could well be on the free list as well if its status is free. • Therefore, if the kernel wants a particular buffer, it will search it on the queue. But if it wants any buffer, it removes a buffer from the free list. A buffer is always on a hash queue, but it may or may not be on the free list DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 12. Scenarios for Retrieval of a Buffer DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon • The algorithms for reading and writing disk blocks use the algorithm getblk to allocate buffers from the pool. There are 5 typical scenarios the kernel may follow in getblk to allocate a buffer for a disk block. • 1.Block is found on its hash queue and its buffer is free. • 2.Block could not be found on the hash queue, so a buffer from the free list is allocated. • 3.Block could not be found on the hash queue, and when allocating a buffer from free list, a buffer marked "delayed write" is allocated. Then the kernel must write the "delayed write" buffer to disk and allocate another buffer. • 4.Block could not be found on the hash queue and the free list of buffers is empty. • 5.Block was found on the hash queue, but its buffer is currently busy.
  • 13. Algorithm for Buffer allocation DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 14. Algorithm for releasing a buffer • When using the buffer, the kernel always marks the buffer as busy so that no other process can access it. • When the kernel finishes using the buffer, it releases the buffer according to the algorithm brelse DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 15. Buffer releasing..... • Buffer contents are old only if it is marked as "delayed write", in that case and in the case where the data is not valid (for example, due to I/O corruption), the buffer is put in the beginning of the free list as its data is not valid or old. • Otherwise the data is valid as the buffer is put at the end to follow the LRU strategy. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 16. Scenario 1 • The states of hash queues for different scenarios are shown in following figures : DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 17. Scenario 2 • Here the buffer is not on the hash queue, so a buffer from free list is removed and then its device and block numbers are changed. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 18. Scenario 3 DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon • Cannot find block on the hash queue => allocate a buffer from free list but buffer on the free list marked “delayed write” => flush “delayed write” buffer and allocate another buffer.
  • 19. Scenario 4 DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon Cannot find block on the hash queue and free list of buffer also empty.
  • 20. Scenario 5 • Block in the hash queue, but buffer is busy. DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 21. Reading and Writing Disk Blocks DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 22. Reading and writing disk blocks.... • DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 23. Writing a disk block DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 24. Advantages of the buffer cache • Uniform disk access => system design simpler • Copying data from user buffers to system buffers => eliminates the need for special alignment of user buffers. • Use of the buffer cache can reduce the amount of disk traffic. • Single image of of disk blocks contained in the cache => helps insure file system integrity DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
  • 25. Disadvantages of the buffer cache DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon • Delayed write => vulnerable to crashes that leave disk data in incorrect state • An extra data copy when reading and writing to and from user processes => slow down when transmitting large data •
  • 26. • Thank you … DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon