Solved

getblk for buffer cache.

Posted on 2004-09-13
1
3,316 Views
Last Modified: 2013-12-26
hello everyone,

      here is a part of the algorithm for getblk() function used for
acquiring buffers from a buffer cache pool in a sysVr2 kernel as defined
in M J Bacuhe Design of Unix OS (p 44):

algo getblk
input: file sys no, block no
output: locked buffer that can now be used for block
{
      while(block not found){
           if(block in hash queue){
                 if(buffer busy){
                       sleep(event: buffer becomes free)
                       continue;
                  }
                   mark buffer busy;
                   remove buffer from list;
                   return buffer;
            }
            .
            .
            .
            (other part not of concern)
}
            if the buffer is marked busy, the process is put to sleep, there by scheduling another process to run(which may again request for the same block). so we can have a number of proceses contending for the same buffer, on a disk interrupt, all these sleeping processes wd be woken up by the interrupt handler routine but only one process successfully acquires the buffer and others go to sleep again. this scheme doesnt gaurantee that a process will not be starved waiting for a buffer. so the question is, is it possible to modify the above part of the getblk() function so that there is no starvation? what i could think was that getblk() should constantly poll for availiability of the buffer till it eventually recieves it due to a disk interrupt.

        while(block in hash queue){
              if(buffer busy)
                     continue;
         .
         .

 obviously this is not a good solution, i wanted to know if its possible  to code getblk() in a way so that there is no starvation.

thanks a lot.
van_dy
0
Comment
Question by:van_dy
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 50 total points
ID: 12042545
Hi van_dy,

>  is it possible to modify the above part of the getblk() function so that there is no starvation?
Yes, look into Lamport's bakery algorithm
http://www.cs.wvu.edu/~jdm/classes/cs356/notes/mutex/Bakery.html

Sunnycoder
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now