The algorithm for reading and writing disk blocks use the algorithm
getblk to allocate buffers from the pool.
In the algorithm
getblk, if the kernel removes a buffer from the free list, it must raise the processor priority level to block out interrupts before checking the free list. Why ?
Code:
algorithm getblk
input: file system number
block number
output: locker buffer that can now be used for block
{
while (buffer not found)
{
if (block 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 are no buffers on free list)
...
...
...
}
}
}
Where can i find the C implementation of the above algorithm for buffer allocation in the linux source code ?