Link to home
Start Free TrialLog in
Avatar of van_dy
van_dy

asked on

getblk for buffer cache.

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
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial